Add initial sandbox management implementation
Signed-off-by: Random-Liu <lantaol@google.com>
This commit is contained in:
11
pkg/os/os.go
11
pkg/os/os.go
@@ -17,7 +17,12 @@ limitations under the License.
|
||||
package os
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
"github.com/tonistiigi/fifo"
|
||||
)
|
||||
|
||||
// OS collects system level operations that need to be mocked out
|
||||
@@ -25,6 +30,7 @@ import (
|
||||
type OS interface {
|
||||
MkdirAll(path string, perm os.FileMode) error
|
||||
RemoveAll(path string) error
|
||||
OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error)
|
||||
}
|
||||
|
||||
// RealOS is used to dispatch the real system level operations.
|
||||
@@ -39,3 +45,8 @@ func (RealOS) MkdirAll(path string, perm os.FileMode) error {
|
||||
func (RealOS) RemoveAll(path string) error {
|
||||
return os.RemoveAll(path)
|
||||
}
|
||||
|
||||
// OpenFifo will call fifo.OpenFifo to open a fifo.
|
||||
func (RealOS) OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) {
|
||||
return fifo.OpenFifo(ctx, fn, flag, perm)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,11 @@ limitations under the License.
|
||||
package testing
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
|
||||
osInterface "github.com/kubernetes-incubator/cri-containerd/pkg/os"
|
||||
)
|
||||
|
||||
@@ -28,6 +31,7 @@ import (
|
||||
type FakeOS struct {
|
||||
MkdirAllFn func(string, os.FileMode) error
|
||||
RemoveAllFn func(string) error
|
||||
OpenFifoFn func(context.Context, string, int, os.FileMode) (io.ReadWriteCloser, error)
|
||||
}
|
||||
|
||||
var _ osInterface.OS = &FakeOS{}
|
||||
@@ -52,3 +56,11 @@ func (f *FakeOS) RemoveAll(path string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// OpenFifo is a fake call that invokes OpenFifoFn or just returns nil.
|
||||
func (f *FakeOS) OpenFifo(ctx context.Context, fn string, flag int, perm os.FileMode) (io.ReadWriteCloser, error) {
|
||||
if f.OpenFifoFn != nil {
|
||||
return f.OpenFifoFn(ctx, fn, flag, perm)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user