From 2c1809475cf1863c4a2945fa8d3809bf5c14af9f Mon Sep 17 00:00:00 2001 From: Kevin Klues Date: Fri, 7 Aug 2020 14:29:54 +0000 Subject: [PATCH] Add more tests for new semantics with device list from volume mounts Signed-off-by: Kevin Klues --- pkg/container_test.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/pkg/container_test.go b/pkg/container_test.go index e531454b..e5f0302e 100644 --- a/pkg/container_test.go +++ b/pkg/container_test.go @@ -587,6 +587,42 @@ func TestDeviceListSourcePriority(t *testing.T) { acceptMounts: true, expectedDevices: &[]string{"GPU0,GPU1"}[0], }, + { + description: "Mount devices, unprivileged, accept unprivileged, no accept mounts", + mountDevices: []Mount{ + { + Source: "/dev/null", + Destination: filepath.Join(deviceListAsVolumeMountsRoot, "GPU0"), + }, + { + Source: "/dev/null", + Destination: filepath.Join(deviceListAsVolumeMountsRoot, "GPU1"), + }, + }, + envvarDevices: "GPU2,GPU3", + privileged: false, + acceptUnprivileged: true, + acceptMounts: false, + expectedDevices: &[]string{"GPU2,GPU3"}[0], + }, + { + description: "Mount devices, unprivileged, no accept unprivileged, no accept mounts", + mountDevices: []Mount{ + { + Source: "/dev/null", + Destination: filepath.Join(deviceListAsVolumeMountsRoot, "GPU0"), + }, + { + Source: "/dev/null", + Destination: filepath.Join(deviceListAsVolumeMountsRoot, "GPU1"), + }, + }, + envvarDevices: "GPU2,GPU3", + privileged: false, + acceptUnprivileged: false, + acceptMounts: false, + expectedPanic: true, + }, } for _, tc := range tests { t.Run(tc.description, func(t *testing.T) {