From a7adb5cd3f10cbfff07c31a9bd24ef4e2c71caf0 Mon Sep 17 00:00:00 2001 From: Yecheng Fu Date: Tue, 29 May 2018 15:36:54 +0800 Subject: [PATCH] Clean up fake mounters. --- exec_mount_test.go | 73 +++------------------------------------------- fake.go | 9 +++++- 2 files changed, 12 insertions(+), 70 deletions(-) diff --git a/exec_mount_test.go b/exec_mount_test.go index 9619356f..d6ccd844 100644 --- a/exec_mount_test.go +++ b/exec_mount_test.go @@ -19,9 +19,7 @@ limitations under the License. package mount import ( - "errors" "fmt" - "os" "reflect" "strings" "testing" @@ -47,7 +45,7 @@ func TestMount(t *testing.T) { return nil, nil }) - wrappedMounter := &fakeMounter{t} + wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t} mounter := NewExecMounter(exec, wrappedMounter) mounter.Mount(sourcePath, destinationPath, fsType, mountOptions) @@ -75,7 +73,7 @@ func TestBindMount(t *testing.T) { return nil, nil }) - wrappedMounter := &fakeMounter{t} + wrappedMounter := &fakeMounter{FakeMounter: &FakeMounter{}, t: t} mounter := NewExecMounter(exec, wrappedMounter) bindOptions := append(mountOptions, "bind") mounter.Mount(sourcePath, destinationPath, fsType, bindOptions) @@ -94,7 +92,7 @@ func TestUnmount(t *testing.T) { return nil, nil }) - wrappedMounter := &fakeMounter{t} + wrappedMounter := &fakeMounter{&FakeMounter{}, t} mounter := NewExecMounter(exec, wrappedMounter) mounter.Unmount(destinationPath) @@ -102,6 +100,7 @@ func TestUnmount(t *testing.T) { /* Fake wrapped mounter */ type fakeMounter struct { + *FakeMounter t *testing.T } @@ -116,67 +115,3 @@ func (fm *fakeMounter) Unmount(target string) error { fm.t.Errorf("Unexpected wrapped mount call") return fmt.Errorf("Unexpected wrapped mount call") } - -func (fm *fakeMounter) List() ([]MountPoint, error) { - return nil, nil -} -func (fm *fakeMounter) IsMountPointMatch(mp MountPoint, dir string) bool { - return false -} -func (fm *fakeMounter) IsNotMountPoint(file string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) IsLikelyNotMountPoint(file string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) DeviceOpened(pathname string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) PathIsDevice(pathname string) (bool, error) { - return false, nil -} -func (fm *fakeMounter) GetDeviceNameFromMount(mountPath, pluginDir string) (string, error) { - return "", nil -} -func (fm *fakeMounter) MakeRShared(path string) error { - return nil -} -func (fm *fakeMounter) MakeFile(pathname string) error { - return nil -} -func (fm *fakeMounter) MakeDir(pathname string) error { - return nil -} -func (fm *fakeMounter) ExistsPath(pathname string) (bool, error) { - return false, errors.New("not implemented") -} -func (fm *fakeMounter) GetFileType(pathname string) (FileType, error) { - return FileTypeFile, nil -} -func (fm *fakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) { - return subPath.Path, nil, nil -} - -func (fm *fakeMounter) CleanSubPaths(podDir string, volumeName string) error { - return nil -} - -func (fm *fakeMounter) SafeMakeDir(pathname string, base string, perm os.FileMode) error { - return nil -} - -func (fm *fakeMounter) GetMountRefs(pathname string) ([]string, error) { - return nil, errors.New("not implemented") -} - -func (fm *fakeMounter) GetFSGroup(pathname string) (int64, error) { - return -1, errors.New("not implemented") -} - -func (fm *fakeMounter) GetSELinuxSupport(pathname string) (bool, error) { - return false, errors.New("not implemented") -} - -func (fm *fakeMounter) GetMode(pathname string) (os.FileMode, error) { - return 0, errors.New("not implemented") -} diff --git a/fake.go b/fake.go index 10832fd3..55c99c9f 100644 --- a/fake.go +++ b/fake.go @@ -29,6 +29,7 @@ import ( type FakeMounter struct { MountPoints []MountPoint Log []FakeAction + Filesystem map[string]FileType // Some tests run things in parallel, make sure the mounter does not produce // any golang's DATA RACE warnings. mutex sync.Mutex @@ -190,6 +191,9 @@ func (f *FakeMounter) MakeRShared(path string) error { } func (f *FakeMounter) GetFileType(pathname string) (FileType, error) { + if t, ok := f.Filesystem[pathname]; ok { + return t, nil + } return FileType("fake"), nil } @@ -202,7 +206,10 @@ func (f *FakeMounter) MakeFile(pathname string) error { } func (f *FakeMounter) ExistsPath(pathname string) (bool, error) { - return false, errors.New("not implemented") + if _, ok := f.Filesystem[pathname]; ok { + return true, nil + } + return false, nil } func (f *FakeMounter) PrepareSafeSubpath(subPath Subpath) (newHostPath string, cleanupAction func(), err error) {