From 53d73e56e026552b38f34191ac8472f539274c11 Mon Sep 17 00:00:00 2001 From: "James O. D. Hunt" Date: Mon, 23 Apr 2018 14:29:13 +0100 Subject: [PATCH] virtcontainers: Fix TestIsHostDevice test as non-root Don't Attempt to create file below `/dev` when running as non-`root`. Move the logic into a new `TestIsHostDeviceCreateFile` test and skip unless `root.` Fixes #242. Signed-off-by: James O. D. Hunt --- virtcontainers/mount_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/virtcontainers/mount_test.go b/virtcontainers/mount_test.go index 25f00dbc28..3c3b061eac 100644 --- a/virtcontainers/mount_test.go +++ b/virtcontainers/mount_test.go @@ -8,7 +8,6 @@ package virtcontainers import ( "bytes" "fmt" - "github.com/stretchr/testify/assert" "os" "os/exec" "path/filepath" @@ -16,6 +15,8 @@ import ( "strings" "syscall" "testing" + + "github.com/stretchr/testify/assert" ) func TestIsSystemMount(t *testing.T) { @@ -60,8 +61,14 @@ func TestIsHostDevice(t *testing.T) { t.Fatalf("Expected result for path %s : %v, got %v", test.mnt, test.expected, result) } } +} +func TestIsHostDeviceCreateFile(t *testing.T) { + if os.Geteuid() != 0 { + t.Skip(testDisabledAsNonRoot) + } // Create regular file in /dev + path := "/dev/foobar" f, err := os.Create(path) if err != nil {