diff options
author | Fabricio Voznika <fvoznika@google.com> | 2019-11-25 11:41:39 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-11-25 11:43:05 -0800 |
commit | 97d2c9a94e802bcb450e50816a913dfc18afc0e3 (patch) | |
tree | a5f7b5d6fbe114ef7a9bc77af1f66742d140b702 /runsc/boot/fs_test.go | |
parent | a5f7b82036f4a062183f1fed9c27227636c8eed5 (diff) |
Use mount hints to determine FileAccessType
PiperOrigin-RevId: 282401165
Diffstat (limited to 'runsc/boot/fs_test.go')
-rw-r--r-- | runsc/boot/fs_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/runsc/boot/fs_test.go b/runsc/boot/fs_test.go index 49ab34b33..0396a4cfb 100644 --- a/runsc/boot/fs_test.go +++ b/runsc/boot/fs_test.go @@ -191,3 +191,61 @@ func TestPodMountHintsErrors(t *testing.T) { }) } } + +func TestGetMountAccessType(t *testing.T) { + const source = "foo" + for _, tst := range []struct { + name string + annotations map[string]string + want FileAccessType + }{ + { + name: "container=exclusive", + annotations: map[string]string{ + path.Join(MountPrefix, "mount1", "source"): source, + path.Join(MountPrefix, "mount1", "type"): "bind", + path.Join(MountPrefix, "mount1", "share"): "container", + }, + want: FileAccessExclusive, + }, + { + name: "pod=shared", + annotations: map[string]string{ + path.Join(MountPrefix, "mount1", "source"): source, + path.Join(MountPrefix, "mount1", "type"): "bind", + path.Join(MountPrefix, "mount1", "share"): "pod", + }, + want: FileAccessShared, + }, + { + name: "shared=shared", + annotations: map[string]string{ + path.Join(MountPrefix, "mount1", "source"): source, + path.Join(MountPrefix, "mount1", "type"): "bind", + path.Join(MountPrefix, "mount1", "share"): "shared", + }, + want: FileAccessShared, + }, + { + name: "default=shared", + annotations: map[string]string{ + path.Join(MountPrefix, "mount1", "source"): source + "mismatch", + path.Join(MountPrefix, "mount1", "type"): "bind", + path.Join(MountPrefix, "mount1", "share"): "container", + }, + want: FileAccessShared, + }, + } { + t.Run(tst.name, func(t *testing.T) { + spec := &specs.Spec{Annotations: tst.annotations} + podHints, err := newPodMountHints(spec) + if err != nil { + t.Fatalf("newPodMountHints failed: %v", err) + } + mounter := containerMounter{hints: podHints} + if got := mounter.getMountAccessType(specs.Mount{Source: source}); got != tst.want { + t.Errorf("getMountAccessType(), want: %v, got: %v", tst.want, got) + } + }) + } +} |