Browse code

daemon/oci_linux_test: Skip privileged tests when non-root

These tests fail when run by a non-root user

=== RUN TestTmpfsDevShmNoDupMount
oci_linux_test.go:29: assertion failed: error is not nil: mkdir /var/lib/docker: permission denied
--- FAIL: TestTmpfsDevShmNoDupMount (0.00s)
=== RUN TestIpcPrivateVsReadonly
oci_linux_test.go:29: assertion failed: error is not nil: mkdir /var/lib/docker: permission denied
--- FAIL: TestIpcPrivateVsReadonly (0.00s)
=== RUN TestSysctlOverride
oci_linux_test.go:29: assertion failed: error is not nil: mkdir /var/lib/docker: permission denied
--- FAIL: TestSysctlOverride (0.00s)
=== RUN TestSysctlOverrideHost
oci_linux_test.go:29: assertion failed: error is not nil: mkdir /var/lib/docker: permission denied
--- FAIL: TestSysctlOverrideHost (0.00s)

Signed-off-by: Arnaud Rebillout <elboulangero@gmail.com>

Arnaud Rebillout authored on 2020/11/26 18:18:50
Showing 1 changed files
... ...
@@ -15,6 +15,7 @@ import (
15 15
 	"github.com/docker/libnetwork"
16 16
 	"gotest.tools/v3/assert"
17 17
 	is "gotest.tools/v3/assert/cmp"
18
+	"gotest.tools/v3/skip"
18 19
 )
19 20
 
20 21
 func setupFakeDaemon(t *testing.T, c *container.Container) *Daemon {
... ...
@@ -62,6 +63,7 @@ func cleanupFakeContainer(c *container.Container) {
62 62
 // in "Duplicate mount point" error from the engine.
63 63
 // https://github.com/moby/moby/issues/35455
64 64
 func TestTmpfsDevShmNoDupMount(t *testing.T) {
65
+	skip.If(t, os.Getuid() != 0, "skipping test that requires root")
65 66
 	c := &container.Container{
66 67
 		ShmPath: "foobar", // non-empty, for c.IpcMounts() to work
67 68
 		HostConfig: &containertypes.HostConfig{
... ...
@@ -84,6 +86,7 @@ func TestTmpfsDevShmNoDupMount(t *testing.T) {
84 84
 // the resulting /dev/shm mount is NOT made read-only.
85 85
 // https://github.com/moby/moby/issues/36503
86 86
 func TestIpcPrivateVsReadonly(t *testing.T) {
87
+	skip.If(t, os.Getuid() != 0, "skipping test that requires root")
87 88
 	c := &container.Container{
88 89
 		HostConfig: &containertypes.HostConfig{
89 90
 			IpcMode:        containertypes.IpcMode("private"),
... ...
@@ -108,6 +111,7 @@ func TestIpcPrivateVsReadonly(t *testing.T) {
108 108
 // TestSysctlOverride ensures that any implicit sysctls (such as
109 109
 // Config.Domainname) are overridden by an explicit sysctl in the HostConfig.
110 110
 func TestSysctlOverride(t *testing.T) {
111
+	skip.If(t, os.Getuid() != 0, "skipping test that requires root")
111 112
 	c := &container.Container{
112 113
 		Config: &containertypes.Config{
113 114
 			Hostname:   "foobar",
... ...
@@ -149,6 +153,7 @@ func TestSysctlOverride(t *testing.T) {
149 149
 // TestSysctlOverrideHost ensures that any implicit network sysctls are not set
150 150
 // with host networking
151 151
 func TestSysctlOverrideHost(t *testing.T) {
152
+	skip.If(t, os.Getuid() != 0, "skipping test that requires root")
152 153
 	c := &container.Container{
153 154
 		Config: &containertypes.Config{},
154 155
 		HostConfig: &containertypes.HostConfig{