Merge pull request #36913 from vdemeester/test-skip-non-root

Skip some tests requires root uid when run as user…
This commit is contained in:
Yong Tang 2018-04-23 11:42:42 -07:00 committed by GitHub
commit 5c233cf431
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 76 additions and 34 deletions

View File

@ -1,6 +1,7 @@
package dockerfile // import "github.com/docker/docker/builder/dockerfile" package dockerfile // import "github.com/docker/docker/builder/dockerfile"
import ( import (
"os"
"testing" "testing"
"github.com/docker/docker/builder/dockerfile/instructions" "github.com/docker/docker/builder/dockerfile/instructions"
@ -8,6 +9,7 @@ import (
"github.com/docker/docker/internal/testutil" "github.com/docker/docker/internal/testutil"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
"github.com/gotestyourself/gotestyourself/skip"
) )
type dispatchTestCase struct { type dispatchTestCase struct {
@ -94,6 +96,7 @@ func initDispatchTestCases() []dispatchTestCase {
} }
func TestDispatch(t *testing.T) { func TestDispatch(t *testing.T) {
skip.IfCondition(t, os.Getuid() != 0, "skipping test that requires root")
testCases := initDispatchTestCases() testCases := initDispatchTestCases()
for _, testCase := range testCases { for _, testCase := range testCases {

View File

@ -2,6 +2,7 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile"
import ( import (
"fmt" "fmt"
"os"
"runtime" "runtime"
"testing" "testing"
@ -14,6 +15,7 @@ import (
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
) )
func TestEmptyDockerfile(t *testing.T) { func TestEmptyDockerfile(t *testing.T) {
@ -59,6 +61,7 @@ func TestNonExistingDockerfile(t *testing.T) {
} }
func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) { func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) {
skip.IfCondition(t, os.Getuid() != 0, "skipping test that requires root")
tarStream, err := archive.Tar(contextDir, archive.Uncompressed) tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
assert.NilError(t, err) assert.NilError(t, err)

View File

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/builder" "github.com/docker/docker/builder"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@ -136,6 +137,7 @@ func TestRemoveDirectory(t *testing.T) {
} }
func makeTestArchiveContext(t *testing.T, dir string) builder.Source { func makeTestArchiveContext(t *testing.T, dir string) builder.Source {
skip.IfCondition(t, os.Getuid() != 0, "skipping test that requires root")
tarStream, err := archive.Tar(dir, archive.Uncompressed) tarStream, err := archive.Tar(dir, archive.Uncompressed)
if err != nil { if err != nil {
t.Fatalf("error: %s", err) t.Fatalf("error: %s", err)

View File

@ -12,6 +12,7 @@ import (
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/spf13/pflag" "github.com/spf13/pflag"
) )
@ -432,6 +433,7 @@ func TestReloadSetConfigFileNotExist(t *testing.T) {
// TestReloadDefaultConfigNotExist tests that if the default configuration file // TestReloadDefaultConfigNotExist tests that if the default configuration file
// doesn't exist the daemon still will be reloaded. // doesn't exist the daemon still will be reloaded.
func TestReloadDefaultConfigNotExist(t *testing.T) { func TestReloadDefaultConfigNotExist(t *testing.T) {
skip.IfCondition(t, os.Getuid() != 0, "skipping test that requires root")
reloaded := false reloaded := false
configFile := "/etc/docker/daemon.json" configFile := "/etc/docker/daemon.json"
flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags := pflag.NewFlagSet("test", pflag.ContinueOnError)

View File

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/skip"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -22,6 +23,7 @@ import (
// └── d3 # 0700 // └── d3 # 0700
// └── f1 # whiteout, 0644 // └── f1 # whiteout, 0644
func setupOverlayTestDir(t *testing.T, src string) { func setupOverlayTestDir(t *testing.T, src string) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
// Create opaque directory containing single file and permission 0700 // Create opaque directory containing single file and permission 0700
err := os.Mkdir(filepath.Join(src, "d1"), 0700) err := os.Mkdir(filepath.Join(src, "d1"), 0700)
assert.NilError(t, err) assert.NilError(t, err)

View File

@ -20,6 +20,7 @@ import (
"github.com/docker/docker/pkg/ioutils" "github.com/docker/docker/pkg/ioutils"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
) )
var tmp string var tmp string
@ -304,6 +305,7 @@ func TestUntarPathWithInvalidSrc(t *testing.T) {
} }
func TestUntarPath(t *testing.T) { func TestUntarPath(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpFolder, err := ioutil.TempDir("", "docker-archive-test") tmpFolder, err := ioutil.TempDir("", "docker-archive-test")
assert.NilError(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpFolder) defer os.RemoveAll(tmpFolder)
@ -434,6 +436,7 @@ func TestCopyWithTarInvalidSrc(t *testing.T) {
} }
func TestCopyWithTarInexistentDestWillCreateIt(t *testing.T) { func TestCopyWithTarInexistentDestWillCreateIt(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tempFolder, err := ioutil.TempDir("", "docker-archive-test") tempFolder, err := ioutil.TempDir("", "docker-archive-test")
if err != nil { if err != nil {
t.Fatal(nil) t.Fatal(nil)
@ -968,9 +971,8 @@ func TestUntarInvalidFilenames(t *testing.T) {
func TestUntarHardlinkToSymlink(t *testing.T) { func TestUntarHardlinkToSymlink(t *testing.T) {
// TODO Windows. There may be a way of running this, but turning off for now // TODO Windows. There may be a way of running this, but turning off for now
if runtime.GOOS == "windows" { skip.If(t, runtime.GOOS == "windows", "hardlinks on Windows")
t.Skip("hardlinks on Windows") skip.If(t, os.Getuid() != 0, "skipping test that requires root")
}
for i, headers := range [][]*tar.Header{ for i, headers := range [][]*tar.Header{
{ {
{ {
@ -1252,6 +1254,7 @@ func TestReplaceFileTarWrapper(t *testing.T) {
// TestPrefixHeaderReadable tests that files that could be created with the // TestPrefixHeaderReadable tests that files that could be created with the
// version of this package that was built with <=go17 are still readable. // version of this package that was built with <=go17 are still readable.
func TestPrefixHeaderReadable(t *testing.T) { func TestPrefixHeaderReadable(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
// https://gist.github.com/stevvooe/e2a790ad4e97425896206c0816e1a882#file-out-go // https://gist.github.com/stevvooe/e2a790ad4e97425896206c0816e1a882#file-out-go
var testFile = []byte("\x1f\x8b\x08\x08\x44\x21\x68\x59\x00\x03\x74\x2e\x74\x61\x72\x00\x4b\xcb\xcf\x67\xa0\x35\x30\x80\x00\x86\x06\x10\x47\x01\xc1\x37\x40\x00\x54\xb6\xb1\xa1\xa9\x99\x09\x48\x25\x1d\x40\x69\x71\x49\x62\x91\x02\xe5\x76\xa1\x79\x84\x21\x91\xd6\x80\x72\xaf\x8f\x82\x51\x30\x0a\x46\x36\x00\x00\xf0\x1c\x1e\x95\x00\x06\x00\x00") var testFile = []byte("\x1f\x8b\x08\x08\x44\x21\x68\x59\x00\x03\x74\x2e\x74\x61\x72\x00\x4b\xcb\xcf\x67\xa0\x35\x30\x80\x00\x86\x06\x10\x47\x01\xc1\x37\x40\x00\x54\xb6\xb1\xa1\xa9\x99\x09\x48\x25\x1d\x40\x69\x71\x49\x62\x91\x02\xe5\x76\xa1\x79\x84\x21\x91\xd6\x80\x72\xaf\x8f\x82\x51\x30\x0a\x46\x36\x00\x00\xf0\x1c\x1e\x95\x00\x06\x00\x00")
@ -1309,6 +1312,7 @@ func appendModifier(path string, header *tar.Header, content io.Reader) (*tar.He
} }
func readFileFromArchive(t *testing.T, archive io.ReadCloser, name string, expectedCount int, doc string) string { func readFileFromArchive(t *testing.T, archive io.ReadCloser, name string, expectedCount int, doc string) string {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
destDir, err := ioutil.TempDir("", "docker-test-destDir") destDir, err := ioutil.TempDir("", "docker-test-destDir")
assert.NilError(t, err) assert.NilError(t, err)
defer os.RemoveAll(destDir) defer os.RemoveAll(destDir)

View File

@ -15,6 +15,7 @@ import (
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
@ -183,6 +184,7 @@ func getInode(path string) (uint64, error) {
} }
func TestTarWithBlockCharFifo(t *testing.T) { func TestTarWithBlockCharFifo(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
origin, err := ioutil.TempDir("", "docker-test-tar-hardlink") origin, err := ioutil.TempDir("", "docker-test-tar-hardlink")
assert.NilError(t, err) assert.NilError(t, err)
@ -223,6 +225,7 @@ func TestTarWithBlockCharFifo(t *testing.T) {
// TestTarUntarWithXattr is Unix as Lsetxattr is not supported on Windows // TestTarUntarWithXattr is Unix as Lsetxattr is not supported on Windows
func TestTarUntarWithXattr(t *testing.T) { func TestTarUntarWithXattr(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
origin, err := ioutil.TempDir("", "docker-test-untar-origin") origin, err := ioutil.TempDir("", "docker-test-untar-origin")
assert.NilError(t, err) assert.NilError(t, err)
defer os.RemoveAll(origin) defer os.RemoveAll(origin)

View File

@ -12,6 +12,7 @@ import (
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/skip"
) )
func max(x, y int) int { func max(x, y int) int {
@ -480,6 +481,7 @@ func TestChangesSize(t *testing.T) {
} }
func checkChanges(expectedChanges, changes []Change, t *testing.T) { func checkChanges(expectedChanges, changes []Change, t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
sort.Sort(changesByPath(expectedChanges)) sort.Sort(changesByPath(expectedChanges))
sort.Sort(changesByPath(changes)) sort.Sort(changesByPath(changes))
for i := 0; i < max(len(changes), len(expectedChanges)); i++ { for i := 0; i < max(len(changes), len(expectedChanges)); i++ {

View File

@ -16,6 +16,7 @@ import (
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/reexec"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/skip"
) )
func init() { func init() {
@ -41,6 +42,7 @@ func CopyWithTar(src, dst string) error {
} }
func TestChrootTarUntar(t *testing.T) { func TestChrootTarUntar(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar") tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -72,6 +74,7 @@ func TestChrootTarUntar(t *testing.T) {
// gh#10426: Verify the fix for having a huge excludes list (like on `docker load` with large # of // gh#10426: Verify the fix for having a huge excludes list (like on `docker load` with large # of
// local images) // local images)
func TestChrootUntarWithHugeExcludesList(t *testing.T) { func TestChrootUntarWithHugeExcludesList(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarHugeExcludes") tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarHugeExcludes")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -170,10 +173,8 @@ func compareFiles(src string, dest string) error {
} }
func TestChrootTarUntarWithSymlink(t *testing.T) { func TestChrootTarUntarWithSymlink(t *testing.T) {
// TODO Windows: Figure out why this is failing skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
if runtime.GOOS == "windows" { skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Skip("Failing on Windows")
}
tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntarWithSymlink") tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntarWithSymlink")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -196,10 +197,8 @@ func TestChrootTarUntarWithSymlink(t *testing.T) {
} }
func TestChrootCopyWithTar(t *testing.T) { func TestChrootCopyWithTar(t *testing.T) {
// TODO Windows: Figure out why this is failing skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
if runtime.GOOS == "windows" { skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Skip("Failing on Windows")
}
tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyWithTar") tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyWithTar")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -246,6 +245,7 @@ func TestChrootCopyWithTar(t *testing.T) {
} }
func TestChrootCopyFileWithTar(t *testing.T) { func TestChrootCopyFileWithTar(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyFileWithTar") tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyFileWithTar")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -289,10 +289,8 @@ func TestChrootCopyFileWithTar(t *testing.T) {
} }
func TestChrootUntarPath(t *testing.T) { func TestChrootUntarPath(t *testing.T) {
// TODO Windows: Figure out why this is failing skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
if runtime.GOOS == "windows" { skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Skip("Failing on Windows")
}
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarPath") tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarPath")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -354,6 +352,7 @@ func (s *slowEmptyTarReader) Read(p []byte) (int, error) {
} }
func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) { func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarEmptyArchiveFromSlowReader") tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarEmptyArchiveFromSlowReader")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -370,6 +369,7 @@ func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
} }
func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) { func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyEmptyArchiveFromSlowReader") tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyEmptyArchiveFromSlowReader")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -386,6 +386,7 @@ func TestChrootApplyEmptyArchiveFromSlowReader(t *testing.T) {
} }
func TestChrootApplyDotDotFile(t *testing.T) { func TestChrootApplyDotDotFile(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyDotDotFile") tmpdir, err := ioutil.TempDir("", "docker-TestChrootApplyDotDotFile")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -284,7 +284,7 @@ func TestGetRootUIDGID(t *testing.T) {
uid, gid, err := GetRootUIDGID(uidMap, gidMap) uid, gid, err := GetRootUIDGID(uidMap, gidMap)
assert.Check(t, err) assert.Check(t, err)
assert.Check(t, is.Equal(os.Getegid(), uid)) assert.Check(t, is.Equal(os.Geteuid(), uid))
assert.Check(t, is.Equal(os.Getegid(), gid)) assert.Check(t, is.Equal(os.Getegid(), gid))
uidMapError := []IDMap{ uidMapError := []IDMap{
@ -393,5 +393,5 @@ func TestMkdirIsNotDir(t *testing.T) {
} }
func RequiresRoot(t *testing.T) { func RequiresRoot(t *testing.T) {
skip.IfCondition(t, os.Getuid() != 0, "skipping test that requires root") skip.If(t, os.Getuid() != 0, "skipping test that requires root")
} }

View File

@ -9,6 +9,7 @@ import (
"time" "time"
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/gotestyourself/gotestyourself/skip"
) )
func TestEnsureRemoveAllNotExist(t *testing.T) { func TestEnsureRemoveAllNotExist(t *testing.T) {
@ -40,9 +41,8 @@ func TestEnsureRemoveAllWithFile(t *testing.T) {
} }
func TestEnsureRemoveAllWithMount(t *testing.T) { func TestEnsureRemoveAllWithMount(t *testing.T) {
if runtime.GOOS == "windows" { skip.If(t, runtime.GOOS == "windows", "mount not supported on Windows")
t.Skip("mount not supported on Windows") skip.If(t, os.Getuid() != 0, "skipping test that requires root")
}
dir1, err := ioutil.TempDir("", "test-ensure-removeall-with-dir1") dir1, err := ioutil.TempDir("", "test-ensure-removeall-with-dir1")
if err != nil { if err != nil {

View File

@ -11,11 +11,13 @@ import (
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/system" "github.com/docker/docker/pkg/system"
"github.com/docker/docker/plugin/v2" "github.com/docker/docker/plugin/v2"
"github.com/gotestyourself/gotestyourself/skip"
specs "github.com/opencontainers/runtime-spec/specs-go" specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
func TestManagerWithPluginMounts(t *testing.T) { func TestManagerWithPluginMounts(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
root, err := ioutil.TempDir("", "test-store-with-plugin-mounts") root, err := ioutil.TempDir("", "test-store-with-plugin-mounts")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"net/http/httputil" "net/http/httputil"
"net/url" "net/url"
"os"
"strings" "strings"
"testing" "testing"
@ -13,6 +14,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/skip"
) )
var ( var (
@ -53,6 +55,7 @@ func spawnTestRegistrySession(t *testing.T) *Session {
} }
func TestPingRegistryEndpoint(t *testing.T) { func TestPingRegistryEndpoint(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
testPing := func(index *registrytypes.IndexInfo, expectedStandalone bool, assertMessage string) { testPing := func(index *registrytypes.IndexInfo, expectedStandalone bool, assertMessage string) {
ep, err := NewV1Endpoint(index, "", nil) ep, err := NewV1Endpoint(index, "", nil)
if err != nil { if err != nil {
@ -72,6 +75,7 @@ func TestPingRegistryEndpoint(t *testing.T) {
} }
func TestEndpoint(t *testing.T) { func TestEndpoint(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
// Simple wrapper to fail test if err != nil // Simple wrapper to fail test if err != nil
expandEndpoint := func(index *registrytypes.IndexInfo) *V1Endpoint { expandEndpoint := func(index *registrytypes.IndexInfo) *V1Endpoint {
endpoint, err := NewV1Endpoint(index, "", nil) endpoint, err := NewV1Endpoint(index, "", nil)
@ -661,6 +665,7 @@ func TestNewIndexInfo(t *testing.T) {
} }
func TestMirrorEndpointLookup(t *testing.T) { func TestMirrorEndpointLookup(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
containsMirror := func(endpoints []APIEndpoint) bool { containsMirror := func(endpoints []APIEndpoint) bool {
for _, pe := range endpoints { for _, pe := range endpoints {
if pe.URL.Host == "my.mirror" { if pe.URL.Host == "my.mirror" {

View File

@ -1,8 +1,14 @@
package registry // import "github.com/docker/docker/registry" package registry // import "github.com/docker/docker/registry"
import "testing" import (
"os"
"testing"
"github.com/gotestyourself/gotestyourself/skip"
)
func TestLookupV1Endpoints(t *testing.T) { func TestLookupV1Endpoints(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
s, err := NewService(ServiceOptions{}) s, err := NewService(ServiceOptions{})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/idtools"
"github.com/docker/docker/pkg/mount" "github.com/docker/docker/pkg/mount"
"github.com/gotestyourself/gotestyourself/skip"
) )
func TestGetAddress(t *testing.T) { func TestGetAddress(t *testing.T) {
@ -30,11 +31,8 @@ func TestGetAddress(t *testing.T) {
} }
func TestRemove(t *testing.T) { func TestRemove(t *testing.T) {
// TODO Windows: Investigate why this test fails on Windows under CI skip.If(t, runtime.GOOS == "windows", "FIXME: investigate why this test fails on CI")
// but passes locally. skip.If(t, os.Getuid() != 0, "skipping test that requires root")
if runtime.GOOS == "windows" {
t.Skip("Test failing on Windows CI")
}
rootDir, err := ioutil.TempDir("", "local-volume-test") rootDir, err := ioutil.TempDir("", "local-volume-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -77,6 +75,7 @@ func TestRemove(t *testing.T) {
} }
func TestInitializeWithVolumes(t *testing.T) { func TestInitializeWithVolumes(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
rootDir, err := ioutil.TempDir("", "local-volume-test") rootDir, err := ioutil.TempDir("", "local-volume-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -109,6 +108,7 @@ func TestInitializeWithVolumes(t *testing.T) {
} }
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
rootDir, err := ioutil.TempDir("", "local-volume-test") rootDir, err := ioutil.TempDir("", "local-volume-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -181,13 +181,8 @@ func TestValidateName(t *testing.T) {
} }
func TestCreateWithOpts(t *testing.T) { func TestCreateWithOpts(t *testing.T) {
if runtime.GOOS == "windows" { skip.If(t, runtime.GOOS == "windows")
t.Skip() skip.If(t, os.Getuid() != 0, "skipping test that requires root")
}
if os.Getuid() != 0 {
t.Skip("root required")
}
rootDir, err := ioutil.TempDir("", "local-volume-test") rootDir, err := ioutil.TempDir("", "local-volume-test")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -284,7 +279,8 @@ func TestCreateWithOpts(t *testing.T) {
} }
} }
func TestRealodNoOpts(t *testing.T) { func TestRelaodNoOpts(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
rootDir, err := ioutil.TempDir("", "volume-test-reload-no-opts") rootDir, err := ioutil.TempDir("", "volume-test-reload-no-opts")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)

View File

@ -15,9 +15,11 @@ import (
"github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp"
"github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
) )
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
s, cleanup := setupTest(t) s, cleanup := setupTest(t)
@ -47,6 +49,7 @@ func TestCreate(t *testing.T) {
} }
func TestRemove(t *testing.T) { func TestRemove(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
s, cleanup := setupTest(t) s, cleanup := setupTest(t)
@ -125,6 +128,7 @@ func TestList(t *testing.T) {
} }
func TestFilterByDriver(t *testing.T) { func TestFilterByDriver(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
s, cleanup := setupTest(t) s, cleanup := setupTest(t)
defer cleanup() defer cleanup()
@ -152,6 +156,7 @@ func TestFilterByDriver(t *testing.T) {
} }
func TestFilterByUsed(t *testing.T) { func TestFilterByUsed(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
s, cleanup := setupTest(t) s, cleanup := setupTest(t)
defer cleanup() defer cleanup()
@ -189,6 +194,7 @@ func TestFilterByUsed(t *testing.T) {
} }
func TestDerefMultipleOfSameRef(t *testing.T) { func TestDerefMultipleOfSameRef(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
s, cleanup := setupTest(t) s, cleanup := setupTest(t)
defer cleanup() defer cleanup()
@ -210,6 +216,7 @@ func TestDerefMultipleOfSameRef(t *testing.T) {
} }
func TestCreateKeepOptsLabelsWhenExistsRemotely(t *testing.T) { func TestCreateKeepOptsLabelsWhenExistsRemotely(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
s, cleanup := setupTest(t) s, cleanup := setupTest(t)
defer cleanup() defer cleanup()
@ -238,6 +245,7 @@ func TestCreateKeepOptsLabelsWhenExistsRemotely(t *testing.T) {
} }
func TestDefererencePluginOnCreateError(t *testing.T) { func TestDefererencePluginOnCreateError(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
var ( var (
@ -284,6 +292,7 @@ func TestDefererencePluginOnCreateError(t *testing.T) {
} }
func TestRefDerefRemove(t *testing.T) { func TestRefDerefRemove(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
driverName := "test-ref-deref-remove" driverName := "test-ref-deref-remove"
@ -304,6 +313,7 @@ func TestRefDerefRemove(t *testing.T) {
} }
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
driverName := "test-get" driverName := "test-get"
@ -330,6 +340,7 @@ func TestGet(t *testing.T) {
} }
func TestGetWithRef(t *testing.T) { func TestGetWithRef(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
t.Parallel() t.Parallel()
driverName := "test-get-with-ref" driverName := "test-get-with-ref"