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>
This commit is contained in:
Kir Kolyshkin 2018-05-22 13:12:29 -07:00
parent 9bd5d9912f
commit 16670ed484
3 changed files with 12 additions and 0 deletions

View File

@ -229,6 +229,10 @@ func checkMounted(t *testing.T, p string, expect bool) {
}
func TestRootMountCleanup(t *testing.T) {
if os.Getuid() != 0 {
t.Skip("root required")
}
t.Parallel()
testRoot, err := ioutil.TempDir("", t.Name())

View File

@ -153,6 +153,10 @@ func TestValidContainerNames(t *testing.T) {
}
func TestContainerInitDNS(t *testing.T) {
if os.Getuid() != 0 {
t.Skip("root required") // for chown
}
tmp, err := ioutil.TempDir("", "docker-container-test-")
if err != nil {
t.Fatal(err)

View File

@ -1,6 +1,7 @@
package daemon // import "github.com/docker/docker/daemon"
import (
"os"
"reflect"
"sort"
"testing"
@ -499,6 +500,9 @@ func TestDaemonDiscoveryReloadOnlyClusterAdvertise(t *testing.T) {
}
func TestDaemonReloadNetworkDiagnosticPort(t *testing.T) {
if os.Getuid() != 0 {
t.Skip("root required")
}
daemon := &Daemon{
imageService: images.NewImageService(images.ImageServiceConfig{}),
}