Browse code

daemon unit tests: skip some if non-root

This prevents the following test case failures "go test" is run
as non-root in the daemon/ directory:

> --- FAIL: TestContainerInitDNS (0.02s)
> daemon_test.go:209: chown /tmp/docker-container-test-054812199/volumes: operation not permitted
>
> --- FAIL: TestDaemonReloadNetworkDiagnosticPort (0.00s)
> reload_test.go:525: mkdir /var/lib/docker/network/files/: permission denied
> --- FAIL: TestRootMountCleanup (0.00s)
> daemon_linux_test.go:240: assertion failed: error is not nil: operation not permitted

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2018/05/23 05:12:29
Showing 3 changed files
... ...
@@ -229,6 +229,10 @@ func checkMounted(t *testing.T, p string, expect bool) {
229 229
 }
230 230
 
231 231
 func TestRootMountCleanup(t *testing.T) {
232
+	if os.Getuid() != 0 {
233
+		t.Skip("root required")
234
+	}
235
+
232 236
 	t.Parallel()
233 237
 
234 238
 	testRoot, err := ioutil.TempDir("", t.Name())
... ...
@@ -153,6 +153,10 @@ func TestValidContainerNames(t *testing.T) {
153 153
 }
154 154
 
155 155
 func TestContainerInitDNS(t *testing.T) {
156
+	if os.Getuid() != 0 {
157
+		t.Skip("root required") // for chown
158
+	}
159
+
156 160
 	tmp, err := ioutil.TempDir("", "docker-container-test-")
157 161
 	if err != nil {
158 162
 		t.Fatal(err)
... ...
@@ -1,6 +1,7 @@
1 1
 package daemon // import "github.com/docker/docker/daemon"
2 2
 
3 3
 import (
4
+	"os"
4 5
 	"reflect"
5 6
 	"sort"
6 7
 	"testing"
... ...
@@ -499,6 +500,9 @@ func TestDaemonDiscoveryReloadOnlyClusterAdvertise(t *testing.T) {
499 499
 }
500 500
 
501 501
 func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) {
502
+	if os.Getuid() != 0 {
503
+		t.Skip("root required")
504
+	}
502 505
 	daemon := &Daemon{
503 506
 		imageService: images.NewImageService(images.ImageServiceConfig{}),
504 507
 	}