Skip some tests requires root uid when run as user

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2018-04-20 11:59:08 +02:00
parent 5d8b88b114
commit a7999aaa53
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3
16 changed files with 75 additions and 33 deletions

View file

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

View file

@ -2,6 +2,7 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile"
import (
"fmt"
"os"
"runtime"
"testing"
@ -14,6 +15,7 @@ import (
"github.com/docker/go-connections/nat"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
)
func TestEmptyDockerfile(t *testing.T) {
@ -59,6 +61,7 @@ func TestNonExistingDockerfile(t *testing.T) {
}
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)
assert.NilError(t, err)

View file

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/builder"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/reexec"
"github.com/gotestyourself/gotestyourself/skip"
"github.com/pkg/errors"
)
@ -136,6 +137,7 @@ func TestRemoveDirectory(t *testing.T) {
}
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)
if err != nil {
t.Fatalf("error: %s", err)

View file

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

View file

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/skip"
"golang.org/x/sys/unix"
)
@ -22,6 +23,7 @@ import (
// └── d3 # 0700
// └── f1 # whiteout, 0644
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
err := os.Mkdir(filepath.Join(src, "d1"), 0700)
assert.NilError(t, err)

View file

@ -20,6 +20,7 @@ import (
"github.com/docker/docker/pkg/ioutils"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/skip"
)
var tmp string
@ -304,6 +305,7 @@ func TestUntarPathWithInvalidSrc(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")
assert.NilError(t, err)
defer os.RemoveAll(tmpFolder)
@ -434,6 +436,7 @@ func TestCopyWithTarInvalidSrc(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")
if err != nil {
t.Fatal(nil)
@ -968,9 +971,8 @@ func TestUntarInvalidFilenames(t *testing.T) {
func TestUntarHardlinkToSymlink(t *testing.T) {
// TODO Windows. There may be a way of running this, but turning off for now
if runtime.GOOS == "windows" {
t.Skip("hardlinks on Windows")
}
skip.If(t, runtime.GOOS == "windows", "hardlinks on Windows")
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
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
// version of this package that was built with <=go17 are still readable.
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
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 {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
destDir, err := ioutil.TempDir("", "docker-test-destDir")
assert.NilError(t, err)
defer os.RemoveAll(destDir)

View file

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

View file

@ -12,6 +12,7 @@ import (
"github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/skip"
)
func max(x, y int) int {
@ -480,6 +481,7 @@ func TestChangesSize(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(changes))
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/reexec"
"github.com/docker/docker/pkg/system"
"github.com/gotestyourself/gotestyourself/skip"
)
func init() {
@ -41,6 +42,7 @@ func CopyWithTar(src, dst string) error {
}
func TestChrootTarUntar(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntar")
if err != nil {
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
// local images)
func TestChrootUntarWithHugeExcludesList(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarHugeExcludes")
if err != nil {
t.Fatal(err)
@ -170,10 +173,8 @@ func compareFiles(src string, dest string) error {
}
func TestChrootTarUntarWithSymlink(t *testing.T) {
// TODO Windows: Figure out why this is failing
if runtime.GOOS == "windows" {
t.Skip("Failing on Windows")
}
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootTarUntarWithSymlink")
if err != nil {
t.Fatal(err)
@ -196,10 +197,8 @@ func TestChrootTarUntarWithSymlink(t *testing.T) {
}
func TestChrootCopyWithTar(t *testing.T) {
// TODO Windows: Figure out why this is failing
if runtime.GOOS == "windows" {
t.Skip("Failing on Windows")
}
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootCopyWithTar")
if err != nil {
t.Fatal(err)
@ -246,6 +245,7 @@ func TestChrootCopyWithTar(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")
if err != nil {
t.Fatal(err)
@ -289,10 +289,8 @@ func TestChrootCopyFileWithTar(t *testing.T) {
}
func TestChrootUntarPath(t *testing.T) {
// TODO Windows: Figure out why this is failing
if runtime.GOOS == "windows" {
t.Skip("Failing on Windows")
}
skip.If(t, runtime.GOOS == "windows", "FIXME: figure out why this is failing")
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarPath")
if err != nil {
t.Fatal(err)
@ -354,6 +352,7 @@ func (s *slowEmptyTarReader) Read(p []byte) (int, error) {
}
func TestChrootUntarEmptyArchiveFromSlowReader(t *testing.T) {
skip.If(t, os.Getuid() != 0, "skipping test that requires root")
tmpdir, err := ioutil.TempDir("", "docker-TestChrootUntarEmptyArchiveFromSlowReader")
if err != nil {
t.Fatal(err)
@ -370,6 +369,7 @@ func TestChrootUntarEmptyArchiveFromSlowReader(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")
if err != nil {
t.Fatal(err)
@ -386,6 +386,7 @@ func TestChrootApplyEmptyArchiveFromSlowReader(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")
if err != nil {
t.Fatal(err)

View file

@ -393,5 +393,5 @@ func TestMkdirIsNotDir(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"
"github.com/docker/docker/pkg/mount"
"github.com/gotestyourself/gotestyourself/skip"
)
func TestEnsureRemoveAllNotExist(t *testing.T) {
@ -40,9 +41,8 @@ func TestEnsureRemoveAllWithFile(t *testing.T) {
}
func TestEnsureRemoveAllWithMount(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("mount not supported on Windows")
}
skip.If(t, runtime.GOOS == "windows", "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")
if err != nil {

View file

@ -11,11 +11,13 @@ import (
"github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/system"
"github.com/docker/docker/plugin/v2"
"github.com/gotestyourself/gotestyourself/skip"
specs "github.com/opencontainers/runtime-spec/specs-go"
"github.com/pkg/errors"
)
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")
if err != nil {
t.Fatal(err)

View file

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

View file

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

View file

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

View file

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