Add some units tests around lifecycle annotation.

PiperOrigin-RevId: 572986759
This commit is contained in:
Ayush Ranjan
2023-10-12 13:01:07 -07:00
committed by gVisor bot
parent e9cef920a4
commit 807e59f15c
3 changed files with 31 additions and 4 deletions
+11 -4
View File
@@ -29,10 +29,11 @@ func TestPodMountHintsHappy(t *testing.T) {
MountPrefix + "mount1.type": "tmpfs",
MountPrefix + "mount1.share": "pod",
MountPrefix + "mount2.source": "bar",
MountPrefix + "mount2.type": "bind",
MountPrefix + "mount2.share": "container",
MountPrefix + "mount2.options": "rw,private",
MountPrefix + "mount2.source": "bar",
MountPrefix + "mount2.type": "bind",
MountPrefix + "mount2.share": "container",
MountPrefix + "mount2.options": "rw,private",
MountPrefix + "mount2.lifecycle": "pod",
},
}
podHints, err := NewPodMountHints(spec)
@@ -57,6 +58,9 @@ func TestPodMountHintsHappy(t *testing.T) {
if want := []string(nil); !reflect.DeepEqual(want, mount1.Mount.Options) {
t.Errorf("mount1 type, want: %q, got: %q", want, mount1.Mount.Options)
}
if want := sharedLife; want != mount1.Lifecycle {
t.Errorf("mount1 lifecycle, want: %q, got: %q", want, mount1.Lifecycle)
}
mount2 := podHints.Mounts["mount2"]
if want := "mount2"; want != mount2.Name {
@@ -74,6 +78,9 @@ func TestPodMountHintsHappy(t *testing.T) {
if want := []string{"rw", "private"}; !reflect.DeepEqual(want, mount2.Mount.Options) {
t.Errorf("mount2 type, want: %q, got: %q", want, mount2.Mount.Options)
}
if want := podLife; want != mount2.Lifecycle {
t.Errorf("mount2 lifecycle, want: %q, got: %q", want, mount2.Lifecycle)
}
}
func TestPodMountHintsErrors(t *testing.T) {
+19
View File
@@ -46,6 +46,16 @@ func TestGetMountAccessType(t *testing.T) {
},
want: config.FileAccessShared,
},
{
name: "pod+podLife=shared",
annotations: map[string]string{
MountPrefix + "mount1.source": source,
MountPrefix + "mount1.type": "bind",
MountPrefix + "mount1.share": "pod",
MountPrefix + "mount1.lifecycle": "pod",
},
want: config.FileAccessShared,
},
{
name: "shared=shared",
annotations: map[string]string{
@@ -64,6 +74,15 @@ func TestGetMountAccessType(t *testing.T) {
},
want: config.FileAccessShared,
},
{
name: "tmpfs+pod=exclusive",
annotations: map[string]string{
MountPrefix + "mount1.source": source,
MountPrefix + "mount1.type": "tmpfs",
MountPrefix + "mount1.share": "pod",
},
want: config.FileAccessExclusive,
},
} {
t.Run(tst.name, func(t *testing.T) {
spec := &specs.Spec{Annotations: tst.annotations}
+1
View File
@@ -129,6 +129,7 @@ func createSharedMount(mount specs.Mount, name string, pod ...*specs.Spec) {
spec.Annotations[boot.MountPrefix+name+".source"] = mount.Source
spec.Annotations[boot.MountPrefix+name+".type"] = mount.Type
spec.Annotations[boot.MountPrefix+name+".share"] = "pod"
spec.Annotations[boot.MountPrefix+name+".lifecycle"] = "pod"
if len(mount.Options) > 0 {
spec.Annotations[boot.MountPrefix+name+".options"] = strings.Join(mount.Options, ",")
}