Move mount/fake.go to mount/fake_mount.go

This patch moves fake.go to mount_fake.go, and follows to principle of
always returning a discrete type rather than an Interface. All callers
of "FakeMounter" are changed to instead use "NewFakeMounter()". The
FakeMounter "Log" struct member is changed to not be exported, and
instead only access through a new "GetLog()" method.
This commit is contained in:
Travis Rhoden
2019-08-26 22:52:08 -06:00
parent 47dc1d6af1
commit 1fd8921546
37 changed files with 161 additions and 185 deletions

View File

@@ -31,8 +31,8 @@ import (
)
func fakeContainerMgrMountInt() mount.Interface {
return &mount.FakeMounter{
MountPoints: []mount.MountPoint{
return mount.NewFakeMounter(
[]mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
@@ -53,8 +53,7 @@ func fakeContainerMgrMountInt() mount.Interface {
Type: "cgroup",
Opts: []string{"rw", "relatime", "memory"},
},
},
}
})
}
func TestCgroupMountValidationSuccess(t *testing.T) {
@@ -64,8 +63,8 @@ func TestCgroupMountValidationSuccess(t *testing.T) {
}
func TestCgroupMountValidationMemoryMissing(t *testing.T) {
mountInt := &mount.FakeMounter{
MountPoints: []mount.MountPoint{
mountInt := mount.NewFakeMounter(
[]mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
@@ -81,15 +80,14 @@ func TestCgroupMountValidationMemoryMissing(t *testing.T) {
Type: "cgroup",
Opts: []string{"rw", "relatime", "cpuacct"},
},
},
}
})
_, err := validateSystemRequirements(mountInt)
assert.Error(t, err)
}
func TestCgroupMountValidationMultipleSubsystem(t *testing.T) {
mountInt := &mount.FakeMounter{
MountPoints: []mount.MountPoint{
mountInt := mount.NewFakeMounter(
[]mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
@@ -105,8 +103,7 @@ func TestCgroupMountValidationMultipleSubsystem(t *testing.T) {
Type: "cgroup",
Opts: []string{"rw", "relatime", "cpuacct"},
},
},
}
})
_, err := validateSystemRequirements(mountInt)
assert.Nil(t, err)
}
@@ -118,8 +115,8 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) {
defer os.RemoveAll(tempDir)
req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_period_us"), []byte("0"), os.ModePerm))
req.NoError(ioutil.WriteFile(path.Join(tempDir, "cpu.cfs_quota_us"), []byte("0"), os.ModePerm))
mountInt := &mount.FakeMounter{
MountPoints: []mount.MountPoint{
mountInt := mount.NewFakeMounter(
[]mount.MountPoint{
{
Device: "cgroup",
Type: "cgroup",
@@ -136,8 +133,7 @@ func TestSoftRequirementsValidationSuccess(t *testing.T) {
Type: "cgroup",
Opts: []string{"rw", "relatime", "cpuacct", "memory"},
},
},
}
})
f, err := validateSystemRequirements(mountInt)
assert.NoError(t, err)
assert.True(t, f.cpuHardcapping, "cpu hardcapping is expected to be enabled")