From 50c96789e7fdc1cbcb9514c19a22cb0c1db06741 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 7 Mar 2015 12:33:26 -0800 Subject: [PATCH] Add an action log to FakeMounter. # *** ERROR: *** docs are out of sync between cli and markdown # run hack/run-gendocs.sh > docs/kubectl.md to regenerate # # Your commit will be aborted unless you regenerate docs. COMMIT_BLOCKED_ON_GENDOCS --- pkg/util/mount/fake.go | 21 ++++++++++++++++++++- pkg/util/mount/mount_linux_test.go | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pkg/util/mount/fake.go b/pkg/util/mount/fake.go index 271f7b49e81..9377c6c780f 100644 --- a/pkg/util/mount/fake.go +++ b/pkg/util/mount/fake.go @@ -16,16 +16,35 @@ limitations under the License. package mount -// FakeMounter implements mount.Interface. +// FakeMounter implements mount.Interface for tests. type FakeMounter struct { MountPoints []MountPoint + Log []FakeAction +} + +// Values for FakeAction.Action +const FakeActionMount = "mount" +const FakeActionUnmount = "unmount" + +// FakeAction objects are logged every time a fake mount or unmount is called. +type FakeAction struct { + Action string // "mount" or "unmount" + Target string // applies to both mount and unmount actions + Source string // applies only to "mount" actions + FSType string // applies only to "mount" actions +} + +func (f *FakeMounter) ResetLog() { + f.Log = []FakeAction{} } func (f *FakeMounter) Mount(source string, target string, fstype string, flags uintptr, data string) error { + f.Log = append(f.Log, FakeAction{Action: FakeActionMount, Target: target, Source: source, FSType: fstype}) return nil } func (f *FakeMounter) Unmount(target string, flags int) error { + f.Log = append(f.Log, FakeAction{Action: FakeActionUnmount, Target: target}) return nil } diff --git a/pkg/util/mount/mount_linux_test.go b/pkg/util/mount/mount_linux_test.go index 98a80945834..7cf067ca74d 100644 --- a/pkg/util/mount/mount_linux_test.go +++ b/pkg/util/mount/mount_linux_test.go @@ -94,7 +94,7 @@ func slicesEqual(a, b []string) bool { func TestGetMountRefs(t *testing.T) { fm := &FakeMounter{ - []MountPoint{ + MountPoints: []MountPoint{ {Device: "/dev/sdb", Path: "/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd"}, {Device: "/dev/sdb", Path: "/var/lib/kubelet/pods/some-pod/volumes/kubernetes.io~gce-pd/gce-pd-in-pod"}, {Device: "/dev/sdc", Path: "/var/lib/kubelet/plugins/kubernetes.io/gce-pd/mounts/gce-pd2"},