1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

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) { func TestRootMountCleanup(t *testing.T) {
if os.Getuid() != 0 {
t.Skip("root required")
}
t.Parallel() t.Parallel()
testRoot, err := ioutil.TempDir("", t.Name()) testRoot, err := ioutil.TempDir("", t.Name())

View file

@ -153,6 +153,10 @@ func TestValidContainerNames(t *testing.T) {
} }
func TestContainerInitDNS(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-") tmp, err := ioutil.TempDir("", "docker-container-test-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View file

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