diff --git a/components/engine/TESTING.md b/components/engine/TESTING.md index 20f7c9254e..1231e1c5f4 100644 --- a/components/engine/TESTING.md +++ b/components/engine/TESTING.md @@ -8,11 +8,11 @@ questions you may have as an aspiring Moby contributor. Moby has two test suites (and one legacy test suite): * Unit tests - use standard `go test` and - [testify](https://github.com/stretchr/testify) assertions. They are located in + [gotestyourself/assert](https://godoc.org/github.com/gotestyourself/gotestyourself/assert) assertions. They are located in the package they test. Unit tests should be fast and test only their own package. * API integration tests - use standard `go test` and - [testify](https://github.com/stretchr/testify) assertions. They are located in + [gotestyourself/assert](https://godoc.org/github.com/gotestyourself/gotestyourself/assert) assertions. They are located in `./integration/` directories, where `component` is: container, image, volume, etc. These tests perform HTTP requests to an API endpoint and check the HTTP response and daemon state after the call. diff --git a/components/engine/api/server/middleware/debug_test.go b/components/engine/api/server/middleware/debug_test.go index a467c4a442..cc227b3248 100644 --- a/components/engine/api/server/middleware/debug_test.go +++ b/components/engine/api/server/middleware/debug_test.go @@ -3,7 +3,8 @@ package middleware // import "github.com/docker/docker/api/server/middleware" import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestMaskSecretKeys(t *testing.T) { @@ -53,6 +54,6 @@ func TestMaskSecretKeys(t *testing.T) { for _, testcase := range tests { maskSecretKeys(testcase.input, testcase.path) - assert.Equal(t, testcase.expected, testcase.input) + assert.Check(t, is.DeepEqual(testcase.expected, testcase.input)) } } diff --git a/components/engine/api/server/middleware/version_test.go b/components/engine/api/server/middleware/version_test.go index 37d22b5c46..f426acf0a3 100644 --- a/components/engine/api/server/middleware/version_test.go +++ b/components/engine/api/server/middleware/version_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/docker/docker/api/server/httputils" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -17,7 +18,7 @@ func TestVersionMiddlewareVersion(t *testing.T) { expectedVersion := defaultVersion handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { v := httputils.VersionFromContext(ctx) - assert.Equal(t, expectedVersion, v) + assert.Check(t, is.Equal(expectedVersion, v)) return nil } @@ -56,9 +57,9 @@ func TestVersionMiddlewareVersion(t *testing.T) { err := h(ctx, resp, req, map[string]string{"version": test.reqVersion}) if test.errString != "" { - assert.EqualError(t, err, test.errString) + assert.Check(t, is.Error(err, test.errString)) } else { - assert.NoError(t, err) + assert.Check(t, err) } } } @@ -66,7 +67,7 @@ func TestVersionMiddlewareVersion(t *testing.T) { func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) { handler := func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { v := httputils.VersionFromContext(ctx) - assert.NotEmpty(t, v) + assert.Check(t, len(v) != 0) return nil } @@ -81,11 +82,11 @@ func TestVersionMiddlewareWithErrorsReturnsHeaders(t *testing.T) { vars := map[string]string{"version": "0.1"} err := h(ctx, resp, req, vars) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) hdr := resp.Result().Header - assert.Contains(t, hdr.Get("Server"), "Docker/"+defaultVersion) - assert.Contains(t, hdr.Get("Server"), runtime.GOOS) - assert.Equal(t, hdr.Get("API-Version"), defaultVersion) - assert.Equal(t, hdr.Get("OSType"), runtime.GOOS) + assert.Check(t, is.Contains(hdr.Get("Server"), "Docker/"+defaultVersion)) + assert.Check(t, is.Contains(hdr.Get("Server"), runtime.GOOS)) + assert.Check(t, is.Equal(hdr.Get("API-Version"), defaultVersion)) + assert.Check(t, is.Equal(hdr.Get("OSType"), runtime.GOOS)) } diff --git a/components/engine/api/types/filters/parse_test.go b/components/engine/api/types/filters/parse_test.go index b54ffa66ec..fbd9ae4fb1 100644 --- a/components/engine/api/types/filters/parse_test.go +++ b/components/engine/api/types/filters/parse_test.go @@ -4,8 +4,8 @@ import ( "errors" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestParseArgs(t *testing.T) { @@ -22,10 +22,10 @@ func TestParseArgs(t *testing.T) { for i := range flagArgs { args, err = ParseFlag(flagArgs[i], args) - require.NoError(t, err) + assert.NilError(t, err) } - assert.Len(t, args.Get("created"), 1) - assert.Len(t, args.Get("image.name"), 2) + assert.Check(t, is.Len(args.Get("created"), 1)) + assert.Check(t, is.Len(args.Get("image.name"), 2)) } func TestParseArgsEdgeCase(t *testing.T) { @@ -231,7 +231,7 @@ func TestArgsMatch(t *testing.T) { } for args, field := range matches { - assert.True(t, args.Match(field, source), + assert.Check(t, args.Match(field, source), "Expected field %s to match %s", field, source) } @@ -255,8 +255,7 @@ func TestArgsMatch(t *testing.T) { } for args, field := range differs { - assert.False(t, args.Match(field, source), - "Expected field %s to not match %s", field, source) + assert.Check(t, !args.Match(field, source), "Expected field %s to not match %s", field, source) } } diff --git a/components/engine/builder/dockerfile/buildargs_test.go b/components/engine/builder/dockerfile/buildargs_test.go index c46dd7d49e..ae00e3b650 100644 --- a/components/engine/builder/dockerfile/buildargs_test.go +++ b/components/engine/builder/dockerfile/buildargs_test.go @@ -2,9 +2,11 @@ package dockerfile // import "github.com/docker/docker/builder/dockerfile" import ( "bytes" + "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func strPtr(source string) *string { @@ -39,7 +41,7 @@ func TestGetAllAllowed(t *testing.T) { "ArgFromMeta": "frommeta1", "ArgFromMetaOverridden": "fromdockerfile3", } - assert.Equal(t, expected, all) + assert.Check(t, is.DeepEqual(expected, all)) } func TestGetAllMeta(t *testing.T) { @@ -61,7 +63,7 @@ func TestGetAllMeta(t *testing.T) { "ArgOverriddenByOptions": "fromopt2", "ArgNoDefaultInMetaFromOptions": "fromopt3", } - assert.Equal(t, expected, all) + assert.Check(t, is.DeepEqual(expected, all)) } func TestWarnOnUnusedBuildArgs(t *testing.T) { @@ -77,10 +79,10 @@ func TestWarnOnUnusedBuildArgs(t *testing.T) { buffer := new(bytes.Buffer) buildArgs.WarnOnUnusedBuildArgs(buffer) out := buffer.String() - assert.NotContains(t, out, "ThisArgIsUsed") - assert.NotContains(t, out, "HTTPS_PROXY") - assert.NotContains(t, out, "HTTP_PROXY") - assert.Contains(t, out, "ThisArgIsNotUsed") + assert.Assert(t, !strings.Contains(out, "ThisArgIsUsed"), out) + assert.Assert(t, !strings.Contains(out, "HTTPS_PROXY"), out) + assert.Assert(t, !strings.Contains(out, "HTTP_PROXY"), out) + assert.Check(t, is.Contains(out, "ThisArgIsNotUsed")) } func TestIsUnreferencedBuiltin(t *testing.T) { @@ -93,8 +95,8 @@ func TestIsUnreferencedBuiltin(t *testing.T) { buildArgs.AddArg("ThisArgIsUsed", nil) buildArgs.AddArg("HTTPS_PROXY", nil) - assert.True(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsUsed")) - assert.True(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsNotUsed")) - assert.True(t, buildArgs.IsReferencedOrNotBuiltin("HTTPS_PROXY")) - assert.False(t, buildArgs.IsReferencedOrNotBuiltin("HTTP_PROXY")) + assert.Check(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsUsed")) + assert.Check(t, buildArgs.IsReferencedOrNotBuiltin("ThisArgIsNotUsed")) + assert.Check(t, buildArgs.IsReferencedOrNotBuiltin("HTTPS_PROXY")) + assert.Check(t, !buildArgs.IsReferencedOrNotBuiltin("HTTP_PROXY")) } diff --git a/components/engine/builder/dockerfile/builder_test.go b/components/engine/builder/dockerfile/builder_test.go index a3a1f122f9..6c73b6cced 100644 --- a/components/engine/builder/dockerfile/builder_test.go +++ b/components/engine/builder/dockerfile/builder_test.go @@ -5,13 +5,14 @@ import ( "testing" "github.com/docker/docker/builder/dockerfile/parser" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestAddNodesForLabelOption(t *testing.T) { dockerfile := "FROM scratch" result, err := parser.Parse(strings.NewReader(dockerfile)) - assert.NoError(t, err) + assert.Check(t, err) labels := map[string]string{ "org.e": "cli-e", @@ -27,8 +28,8 @@ func TestAddNodesForLabelOption(t *testing.T) { "FROM scratch", `LABEL "org.a"='cli-a' "org.b"='cli-b' "org.c"='cli-c' "org.d"='cli-d' "org.e"='cli-e'`, } - assert.Len(t, nodes.Children, 2) + assert.Check(t, is.Len(nodes.Children, 2)) for i, v := range nodes.Children { - assert.Equal(t, expected[i], v.Original) + assert.Check(t, is.Equal(expected[i], v.Original)) } } diff --git a/components/engine/builder/dockerfile/copy_test.go b/components/engine/builder/dockerfile/copy_test.go index da8e0711ac..f2f895387c 100644 --- a/components/engine/builder/dockerfile/copy_test.go +++ b/components/engine/builder/dockerfile/copy_test.go @@ -5,8 +5,9 @@ import ( "testing" "github.com/docker/docker/pkg/containerfs" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/assert" ) func TestIsExistingDirectory(t *testing.T) { @@ -39,10 +40,10 @@ func TestIsExistingDirectory(t *testing.T) { for _, testcase := range testcases { result, err := isExistingDirectory(©Endpoint{driver: containerfs.NewLocalDriver(), path: testcase.path}) - if !assert.NoError(t, err) { + if !assert.Check(t, err) { continue } - assert.Equal(t, testcase.expected, result, testcase.doc) + assert.Check(t, is.Equal(testcase.expected, result), testcase.doc) } } @@ -142,6 +143,6 @@ func TestGetFilenameForDownload(t *testing.T) { resp.Header.Add("Content-Disposition", testcase.disposition) } filename := getFilenameForDownload(testcase.path, &resp) - assert.Equal(t, testcase.expected, filename) + assert.Check(t, is.Equal(testcase.expected, filename)) } } diff --git a/components/engine/builder/dockerfile/dispatchers_test.go b/components/engine/builder/dockerfile/dispatchers_test.go index 6d52e7e619..988580cb15 100644 --- a/components/engine/builder/dockerfile/dispatchers_test.go +++ b/components/engine/builder/dockerfile/dispatchers_test.go @@ -16,8 +16,8 @@ import ( "github.com/docker/docker/image" "github.com/docker/docker/pkg/system" "github.com/docker/go-connections/nat" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func newBuilderWithMockBackend() *Builder { @@ -49,13 +49,13 @@ func TestEnv2Variables(t *testing.T) { }, } err := dispatch(sb, envCommand) - require.NoError(t, err) + assert.NilError(t, err) expected := []string{ "var1=val1", "var2=val2", } - assert.Equal(t, expected, sb.state.runConfig.Env) + assert.Check(t, is.DeepEqual(expected, sb.state.runConfig.Env)) } func TestEnvValueWithExistingRunConfigEnv(t *testing.T) { @@ -68,12 +68,12 @@ func TestEnvValueWithExistingRunConfigEnv(t *testing.T) { }, } err := dispatch(sb, envCommand) - require.NoError(t, err) + assert.NilError(t, err) expected := []string{ "var1=val1", "var2=fromenv", } - assert.Equal(t, expected, sb.state.runConfig.Env) + assert.Check(t, is.DeepEqual(expected, sb.state.runConfig.Env)) } func TestMaintainer(t *testing.T) { @@ -82,8 +82,8 @@ func TestMaintainer(t *testing.T) { sb := newDispatchRequest(b, '\\', nil, newBuildArgs(make(map[string]*string)), newStagesBuildResults()) cmd := &instructions.MaintainerCommand{Maintainer: maintainerEntry} err := dispatch(sb, cmd) - require.NoError(t, err) - assert.Equal(t, maintainerEntry, sb.state.maintainer) + assert.NilError(t, err) + assert.Check(t, is.Equal(maintainerEntry, sb.state.maintainer)) } func TestLabel(t *testing.T) { @@ -98,10 +98,10 @@ func TestLabel(t *testing.T) { }, } err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) - require.Contains(t, sb.state.runConfig.Labels, labelName) - assert.Equal(t, sb.state.runConfig.Labels[labelName], labelValue) + assert.Assert(t, is.Contains(sb.state.runConfig.Labels, labelName)) + assert.Check(t, is.Equal(sb.state.runConfig.Labels[labelName], labelValue)) } func TestFromScratch(t *testing.T) { @@ -113,22 +113,22 @@ func TestFromScratch(t *testing.T) { err := initializeStage(sb, cmd) if runtime.GOOS == "windows" && !system.LCOWSupported() { - assert.EqualError(t, err, "Windows does not support FROM scratch") + assert.Check(t, is.Error(err, "Windows does not support FROM scratch")) return } - require.NoError(t, err) - assert.True(t, sb.state.hasFromImage()) - assert.Equal(t, "", sb.state.imageID) + assert.NilError(t, err) + assert.Check(t, sb.state.hasFromImage()) + assert.Check(t, is.Equal("", sb.state.imageID)) expected := "PATH=" + system.DefaultPathEnv(runtime.GOOS) - assert.Equal(t, []string{expected}, sb.state.runConfig.Env) + assert.Check(t, is.DeepEqual([]string{expected}, sb.state.runConfig.Env)) } func TestFromWithArg(t *testing.T) { tag, expected := ":sometag", "expectedthisid" getImage := func(name string) (builder.Image, builder.ROLayer, error) { - assert.Equal(t, "alpine"+tag, name) + assert.Check(t, is.Equal("alpine"+tag, name)) return &mockImage{id: "expectedthisid"}, nil, nil } b := newBuilderWithMockBackend() @@ -146,21 +146,21 @@ func TestFromWithArg(t *testing.T) { err := processMetaArg(metaArg, shell.NewLex('\\'), args) sb := newDispatchRequest(b, '\\', nil, args, newStagesBuildResults()) - require.NoError(t, err) + assert.NilError(t, err) err = initializeStage(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, expected, sb.state.imageID) - assert.Equal(t, expected, sb.state.baseImage.ImageID()) - assert.Len(t, sb.state.buildArgs.GetAllAllowed(), 0) - assert.Len(t, sb.state.buildArgs.GetAllMeta(), 1) + assert.Check(t, is.Equal(expected, sb.state.imageID)) + assert.Check(t, is.Equal(expected, sb.state.baseImage.ImageID())) + assert.Check(t, is.Len(sb.state.buildArgs.GetAllAllowed(), 0)) + assert.Check(t, is.Len(sb.state.buildArgs.GetAllMeta(), 1)) } func TestFromWithUndefinedArg(t *testing.T) { tag, expected := "sometag", "expectedthisid" getImage := func(name string) (builder.Image, builder.ROLayer, error) { - assert.Equal(t, "alpine", name) + assert.Check(t, is.Equal("alpine", name)) return &mockImage{id: "expectedthisid"}, nil, nil } b := newBuilderWithMockBackend() @@ -173,8 +173,8 @@ func TestFromWithUndefinedArg(t *testing.T) { BaseName: "alpine${THETAG}", } err := initializeStage(sb, cmd) - require.NoError(t, err) - assert.Equal(t, expected, sb.state.imageID) + assert.NilError(t, err) + assert.Check(t, is.Equal(expected, sb.state.imageID)) } func TestFromMultiStageWithNamedStage(t *testing.T) { @@ -185,13 +185,13 @@ func TestFromMultiStageWithNamedStage(t *testing.T) { firstSB := newDispatchRequest(b, '\\', nil, newBuildArgs(make(map[string]*string)), previousResults) secondSB := newDispatchRequest(b, '\\', nil, newBuildArgs(make(map[string]*string)), previousResults) err := initializeStage(firstSB, firstFrom) - require.NoError(t, err) - assert.True(t, firstSB.state.hasFromImage()) + assert.NilError(t, err) + assert.Check(t, firstSB.state.hasFromImage()) previousResults.indexed["base"] = firstSB.state.runConfig previousResults.flat = append(previousResults.flat, firstSB.state.runConfig) err = initializeStage(secondSB, secondFrom) - require.NoError(t, err) - assert.True(t, secondSB.state.hasFromImage()) + assert.NilError(t, err) + assert.Check(t, secondSB.state.hasFromImage()) } func TestOnbuild(t *testing.T) { @@ -201,8 +201,8 @@ func TestOnbuild(t *testing.T) { Expression: "ADD . /app/src", } err := dispatch(sb, cmd) - require.NoError(t, err) - assert.Equal(t, "ADD . /app/src", sb.state.runConfig.OnBuild[0]) + assert.NilError(t, err) + assert.Check(t, is.Equal("ADD . /app/src", sb.state.runConfig.OnBuild[0])) } func TestWorkdir(t *testing.T) { @@ -217,8 +217,8 @@ func TestWorkdir(t *testing.T) { } err := dispatch(sb, cmd) - require.NoError(t, err) - assert.Equal(t, workingDir, sb.state.runConfig.WorkingDir) + assert.NilError(t, err) + assert.Check(t, is.Equal(workingDir, sb.state.runConfig.WorkingDir)) } func TestCmd(t *testing.T) { @@ -233,7 +233,7 @@ func TestCmd(t *testing.T) { }, } err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) var expectedCommand strslice.StrSlice if runtime.GOOS == "windows" { @@ -242,8 +242,8 @@ func TestCmd(t *testing.T) { expectedCommand = strslice.StrSlice(append([]string{"/bin/sh"}, "-c", command)) } - assert.Equal(t, expectedCommand, sb.state.runConfig.Cmd) - assert.True(t, sb.state.cmdSet) + assert.Check(t, is.DeepEqual(expectedCommand, sb.state.runConfig.Cmd)) + assert.Check(t, sb.state.cmdSet) } func TestHealthcheckNone(t *testing.T) { @@ -255,10 +255,10 @@ func TestHealthcheckNone(t *testing.T) { }, } err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) - require.NotNil(t, sb.state.runConfig.Healthcheck) - assert.Equal(t, []string{"NONE"}, sb.state.runConfig.Healthcheck.Test) + assert.Assert(t, sb.state.runConfig.Healthcheck != nil) + assert.Check(t, is.DeepEqual([]string{"NONE"}, sb.state.runConfig.Healthcheck.Test)) } func TestHealthcheckCmd(t *testing.T) { @@ -272,10 +272,10 @@ func TestHealthcheckCmd(t *testing.T) { }, } err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) - require.NotNil(t, sb.state.runConfig.Healthcheck) - assert.Equal(t, expectedTest, sb.state.runConfig.Healthcheck.Test) + assert.Assert(t, sb.state.runConfig.Healthcheck != nil) + assert.Check(t, is.DeepEqual(expectedTest, sb.state.runConfig.Healthcheck.Test)) } func TestEntrypoint(t *testing.T) { @@ -290,8 +290,8 @@ func TestEntrypoint(t *testing.T) { }, } err := dispatch(sb, cmd) - require.NoError(t, err) - require.NotNil(t, sb.state.runConfig.Entrypoint) + assert.NilError(t, err) + assert.Assert(t, sb.state.runConfig.Entrypoint != nil) var expectedEntrypoint strslice.StrSlice if runtime.GOOS == "windows" { @@ -299,7 +299,7 @@ func TestEntrypoint(t *testing.T) { } else { expectedEntrypoint = strslice.StrSlice(append([]string{"/bin/sh"}, "-c", entrypointCmd)) } - assert.Equal(t, expectedEntrypoint, sb.state.runConfig.Entrypoint) + assert.Check(t, is.DeepEqual(expectedEntrypoint, sb.state.runConfig.Entrypoint)) } func TestExpose(t *testing.T) { @@ -311,14 +311,14 @@ func TestExpose(t *testing.T) { Ports: []string{exposedPort}, } err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) - require.NotNil(t, sb.state.runConfig.ExposedPorts) - require.Len(t, sb.state.runConfig.ExposedPorts, 1) + assert.Assert(t, sb.state.runConfig.ExposedPorts != nil) + assert.Assert(t, is.Len(sb.state.runConfig.ExposedPorts, 1)) portsMapping, err := nat.ParsePortSpec(exposedPort) - require.NoError(t, err) - assert.Contains(t, sb.state.runConfig.ExposedPorts, portsMapping[0].Port) + assert.NilError(t, err) + assert.Check(t, is.Contains(sb.state.runConfig.ExposedPorts, portsMapping[0].Port)) } func TestUser(t *testing.T) { @@ -329,8 +329,8 @@ func TestUser(t *testing.T) { User: "test", } err := dispatch(sb, cmd) - require.NoError(t, err) - assert.Equal(t, "test", sb.state.runConfig.User) + assert.NilError(t, err) + assert.Check(t, is.Equal("test", sb.state.runConfig.User)) } func TestVolume(t *testing.T) { @@ -343,10 +343,10 @@ func TestVolume(t *testing.T) { Volumes: []string{exposedVolume}, } err := dispatch(sb, cmd) - require.NoError(t, err) - require.NotNil(t, sb.state.runConfig.Volumes) - assert.Len(t, sb.state.runConfig.Volumes, 1) - assert.Contains(t, sb.state.runConfig.Volumes, exposedVolume) + assert.NilError(t, err) + assert.Assert(t, sb.state.runConfig.Volumes != nil) + assert.Check(t, is.Len(sb.state.runConfig.Volumes, 1)) + assert.Check(t, is.Contains(sb.state.runConfig.Volumes, exposedVolume)) } func TestStopSignal(t *testing.T) { @@ -362,8 +362,8 @@ func TestStopSignal(t *testing.T) { Signal: signal, } err := dispatch(sb, cmd) - require.NoError(t, err) - assert.Equal(t, signal, sb.state.runConfig.StopSignal) + assert.NilError(t, err) + assert.Check(t, is.Equal(signal, sb.state.runConfig.StopSignal)) } func TestArg(t *testing.T) { @@ -374,10 +374,10 @@ func TestArg(t *testing.T) { argVal := "bar" cmd := &instructions.ArgCommand{Key: argName, Value: &argVal} err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) expected := map[string]string{argName: argVal} - assert.Equal(t, expected, sb.state.buildArgs.GetAllAllowed()) + assert.Check(t, is.DeepEqual(expected, sb.state.buildArgs.GetAllAllowed())) } func TestShell(t *testing.T) { @@ -388,10 +388,10 @@ func TestShell(t *testing.T) { cmd := &instructions.ShellCommand{Shell: strslice.StrSlice{shellCmd}} err := dispatch(sb, cmd) - require.NoError(t, err) + assert.NilError(t, err) expectedShell := strslice.StrSlice([]string{shellCmd}) - assert.Equal(t, expectedShell, sb.state.runConfig.Shell) + assert.Check(t, is.DeepEqual(expectedShell, sb.state.runConfig.Shell)) } func TestPrependEnvOnCmd(t *testing.T) { @@ -403,7 +403,7 @@ func TestPrependEnvOnCmd(t *testing.T) { cmdWithEnv := prependEnvOnCmd(buildArgs, args, cmd) expected := strslice.StrSlice([]string{ "|3", "NO_PROXY=YA", "args=not", "sorted=nope", "foo", "bar"}) - assert.Equal(t, expected, cmdWithEnv) + assert.Check(t, is.DeepEqual(expected, cmdWithEnv)) } func TestRunWithBuildArgs(t *testing.T) { @@ -422,8 +422,8 @@ func TestRunWithBuildArgs(t *testing.T) { imageCache := &mockImageCache{ getCacheFunc: func(parentID string, cfg *container.Config) (string, error) { // Check the runConfig.Cmd sent to probeCache() - assert.Equal(t, cachedCmd, cfg.Cmd) - assert.Equal(t, strslice.StrSlice(nil), cfg.Entrypoint) + assert.Check(t, is.DeepEqual(cachedCmd, cfg.Cmd)) + assert.Check(t, is.DeepEqual(strslice.StrSlice(nil), cfg.Entrypoint)) return "", nil }, } @@ -441,21 +441,21 @@ func TestRunWithBuildArgs(t *testing.T) { } mockBackend.containerCreateFunc = func(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error) { // Check the runConfig.Cmd sent to create() - assert.Equal(t, cmdWithShell, config.Config.Cmd) - assert.Contains(t, config.Config.Env, "one=two") - assert.Equal(t, strslice.StrSlice{""}, config.Config.Entrypoint) + assert.Check(t, is.DeepEqual(cmdWithShell, config.Config.Cmd)) + assert.Check(t, is.Contains(config.Config.Env, "one=two")) + assert.Check(t, is.DeepEqual(strslice.StrSlice{""}, config.Config.Entrypoint)) return container.ContainerCreateCreatedBody{ID: "12345"}, nil } mockBackend.commitFunc = func(cfg backend.CommitConfig) (image.ID, error) { // Check the runConfig.Cmd sent to commit() - assert.Equal(t, origCmd, cfg.Config.Cmd) - assert.Equal(t, cachedCmd, cfg.ContainerConfig.Cmd) - assert.Equal(t, strslice.StrSlice(nil), cfg.Config.Entrypoint) + assert.Check(t, is.DeepEqual(origCmd, cfg.Config.Cmd)) + assert.Check(t, is.DeepEqual(cachedCmd, cfg.ContainerConfig.Cmd)) + assert.Check(t, is.DeepEqual(strslice.StrSlice(nil), cfg.Config.Entrypoint)) return "", nil } from := &instructions.Stage{BaseName: "abcdef"} err := initializeStage(sb, from) - require.NoError(t, err) + assert.NilError(t, err) sb.state.buildArgs.AddArg("one", strPtr("two")) run := &instructions.RunCommand{ ShellDependantCmdLine: instructions.ShellDependantCmdLine{ @@ -463,8 +463,8 @@ func TestRunWithBuildArgs(t *testing.T) { PrependShell: true, }, } - require.NoError(t, dispatch(sb, run)) + assert.NilError(t, dispatch(sb, run)) // Check that runConfig.Cmd has not been modified by run - assert.Equal(t, origCmd, sb.state.runConfig.Cmd) + assert.Check(t, is.DeepEqual(origCmd, sb.state.runConfig.Cmd)) } diff --git a/components/engine/builder/dockerfile/instructions/parse_test.go b/components/engine/builder/dockerfile/instructions/parse_test.go index ffd6d4f45c..b084ad11c7 100644 --- a/components/engine/builder/dockerfile/instructions/parse_test.go +++ b/components/engine/builder/dockerfile/instructions/parse_test.go @@ -7,8 +7,8 @@ import ( "github.com/docker/docker/builder/dockerfile/command" "github.com/docker/docker/builder/dockerfile/parser" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestCommandsExactlyOneArgument(t *testing.T) { @@ -21,9 +21,9 @@ func TestCommandsExactlyOneArgument(t *testing.T) { for _, command := range commands { ast, err := parser.Parse(strings.NewReader(command)) - require.NoError(t, err) + assert.NilError(t, err) _, err = ParseInstruction(ast.AST.Children[0]) - assert.EqualError(t, err, errExactlyOneArgument(command).Error()) + assert.Check(t, is.Error(err, errExactlyOneArgument(command).Error())) } } @@ -39,9 +39,9 @@ func TestCommandsAtLeastOneArgument(t *testing.T) { for _, command := range commands { ast, err := parser.Parse(strings.NewReader(command)) - require.NoError(t, err) + assert.NilError(t, err) _, err = ParseInstruction(ast.AST.Children[0]) - assert.EqualError(t, err, errAtLeastOneArgument(command).Error()) + assert.Check(t, is.Error(err, errAtLeastOneArgument(command).Error())) } } @@ -53,9 +53,9 @@ func TestCommandsNoDestinationArgument(t *testing.T) { for _, command := range commands { ast, err := parser.Parse(strings.NewReader(command + " arg1")) - require.NoError(t, err) + assert.NilError(t, err) _, err = ParseInstruction(ast.AST.Children[0]) - assert.EqualError(t, err, errNoDestinationArgument(command).Error()) + assert.Check(t, is.Error(err, errNoDestinationArgument(command).Error())) } } @@ -80,7 +80,7 @@ func TestCommandsTooManyArguments(t *testing.T) { }, } _, err := ParseInstruction(node) - assert.EqualError(t, err, errTooManyArguments(command).Error()) + assert.Check(t, is.Error(err, errTooManyArguments(command).Error())) } } @@ -102,7 +102,7 @@ func TestCommandsBlankNames(t *testing.T) { }, } _, err := ParseInstruction(node) - assert.EqualError(t, err, errBlankCommandNames(command).Error()) + assert.Check(t, is.Error(err, errBlankCommandNames(command).Error())) } } @@ -120,11 +120,11 @@ func TestHealthCheckCmd(t *testing.T) { }, } cmd, err := ParseInstruction(node) - assert.NoError(t, err) + assert.Check(t, err) hc, ok := cmd.(*HealthCheckCommand) - assert.True(t, ok) + assert.Check(t, ok) expected := []string{"CMD-SHELL", "hello world"} - assert.Equal(t, expected, hc.Health.Test) + assert.Check(t, is.DeepEqual(expected, hc.Health.Test)) } func TestParseOptInterval(t *testing.T) { @@ -138,7 +138,7 @@ func TestParseOptInterval(t *testing.T) { flInterval.Value = "1ms" _, err = parseOptInterval(flInterval) - require.NoError(t, err) + assert.NilError(t, err) } func TestErrorCases(t *testing.T) { diff --git a/components/engine/builder/dockerfile/internals_linux_test.go b/components/engine/builder/dockerfile/internals_linux_test.go index 08067f8573..c244ddfe3f 100644 --- a/components/engine/builder/dockerfile/internals_linux_test.go +++ b/components/engine/builder/dockerfile/internals_linux_test.go @@ -6,8 +6,8 @@ import ( "testing" "github.com/docker/docker/pkg/idtools" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestChownFlagParsing(t *testing.T) { @@ -99,8 +99,8 @@ othergrp:x:6666: } { t.Run(testcase.name, func(t *testing.T) { idPair, err := parseChownFlag(testcase.chownStr, contextDir, testcase.idMapping) - require.NoError(t, err, "Failed to parse chown flag: %q", testcase.chownStr) - assert.Equal(t, testcase.expected, idPair, "chown flag mapping failure") + assert.NilError(t, err, "Failed to parse chown flag: %q", testcase.chownStr) + assert.Check(t, is.DeepEqual(testcase.expected, idPair), "chown flag mapping failure") }) } @@ -132,7 +132,7 @@ othergrp:x:6666: } { t.Run(testcase.name, func(t *testing.T) { _, err := parseChownFlag(testcase.chownStr, contextDir, testcase.idMapping) - assert.EqualError(t, err, testcase.descr, "Expected error string doesn't match") + assert.Check(t, is.Error(err, testcase.descr), "Expected error string doesn't match") }) } } diff --git a/components/engine/builder/dockerfile/internals_test.go b/components/engine/builder/dockerfile/internals_test.go index 24103ecd8e..ae20026833 100644 --- a/components/engine/builder/dockerfile/internals_test.go +++ b/components/engine/builder/dockerfile/internals_test.go @@ -12,8 +12,8 @@ import ( "github.com/docker/docker/builder/remotecontext" "github.com/docker/docker/pkg/archive" "github.com/docker/go-connections/nat" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestEmptyDockerfile(t *testing.T) { @@ -60,7 +60,7 @@ func TestNonExistingDockerfile(t *testing.T) { func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, expectedError string) { tarStream, err := archive.Tar(contextDir, archive.Uncompressed) - require.NoError(t, err) + assert.NilError(t, err) defer func() { if err = tarStream.Close(); err != nil { @@ -77,7 +77,7 @@ func readAndCheckDockerfile(t *testing.T, testName, contextDir, dockerfilePath, Source: tarStream, } _, _, err = remotecontext.Detect(config) - assert.EqualError(t, err, expectedError) + assert.Check(t, is.Error(err, expectedError)) } func TestCopyRunConfig(t *testing.T) { @@ -124,9 +124,9 @@ func TestCopyRunConfig(t *testing.T) { Env: defaultEnv, } runConfigCopy := copyRunConfig(runConfig, testcase.modifiers...) - assert.Equal(t, testcase.expected, runConfigCopy, testcase.doc) + assert.Check(t, is.DeepEqual(testcase.expected, runConfigCopy), testcase.doc) // Assert the original was not modified - assert.NotEqual(t, runConfig, runConfigCopy, testcase.doc) + assert.Check(t, runConfig != runConfigCopy, testcase.doc) } } @@ -156,7 +156,7 @@ func fullMutableRunConfig() *container.Config { func TestDeepCopyRunConfig(t *testing.T) { runConfig := fullMutableRunConfig() copy := copyRunConfig(runConfig) - assert.Equal(t, fullMutableRunConfig(), copy) + assert.Check(t, is.DeepEqual(fullMutableRunConfig(), copy)) copy.Cmd[1] = "arg2" copy.Env[1] = "env2=new" @@ -166,5 +166,5 @@ func TestDeepCopyRunConfig(t *testing.T) { copy.OnBuild[0] = "start" copy.Labels["label3"] = "value3" copy.Shell[0] = "sh" - assert.Equal(t, fullMutableRunConfig(), runConfig) + assert.Check(t, is.DeepEqual(fullMutableRunConfig(), runConfig)) } diff --git a/components/engine/builder/dockerfile/internals_windows_test.go b/components/engine/builder/dockerfile/internals_windows_test.go index 08f394ac60..1fc55c0752 100644 --- a/components/engine/builder/dockerfile/internals_windows_test.go +++ b/components/engine/builder/dockerfile/internals_windows_test.go @@ -7,7 +7,8 @@ import ( "testing" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestNormalizeDest(t *testing.T) { @@ -42,10 +43,10 @@ func TestNormalizeDest(t *testing.T) { msg := fmt.Sprintf("Input: %s, %s", testcase.current, testcase.requested) actual, err := normalizeDest(testcase.current, testcase.requested, "windows") if testcase.etext == "" { - if !assert.NoError(t, err, msg) { + if !assert.Check(t, err, msg) { continue } - assert.Equal(t, testcase.expected, actual, msg) + assert.Check(t, is.Equal(testcase.expected, actual), msg) } else { testutil.ErrorContains(t, err, testcase.etext) } diff --git a/components/engine/builder/dockerfile/parser/line_parsers_test.go b/components/engine/builder/dockerfile/parser/line_parsers_test.go index 8ce6a7ad6f..50b8d03c23 100644 --- a/components/engine/builder/dockerfile/parser/line_parsers_test.go +++ b/components/engine/builder/dockerfile/parser/line_parsers_test.go @@ -3,25 +3,29 @@ package parser // import "github.com/docker/docker/builder/dockerfile/parser" import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/google/go-cmp/cmp" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestParseNameValOldFormat(t *testing.T) { directive := Directive{} node, err := parseNameVal("foo bar", "LABEL", &directive) - assert.NoError(t, err) + assert.Check(t, err) expected := &Node{ Value: "foo", Next: &Node{Value: "bar"}, } - assert.Equal(t, expected, node) + assert.DeepEqual(t, expected, node, cmpNodeOpt) } +var cmpNodeOpt = cmp.AllowUnexported(Node{}) + func TestParseNameValNewFormat(t *testing.T) { directive := Directive{} node, err := parseNameVal("foo=bar thing=star", "LABEL", &directive) - assert.NoError(t, err) + assert.Check(t, err) expected := &Node{ Value: "foo", @@ -35,7 +39,7 @@ func TestParseNameValNewFormat(t *testing.T) { }, }, } - assert.Equal(t, expected, node) + assert.DeepEqual(t, expected, node, cmpNodeOpt) } func TestNodeFromLabels(t *testing.T) { @@ -61,8 +65,7 @@ func TestNodeFromLabels(t *testing.T) { } node := NodeFromLabels(labels) - assert.Equal(t, expected, node) - + assert.DeepEqual(t, expected, node, cmpNodeOpt) } func TestParseNameValWithoutVal(t *testing.T) { @@ -70,5 +73,5 @@ func TestParseNameValWithoutVal(t *testing.T) { // In Config.Env, a variable without `=` is removed from the environment. (#31634) // However, in Dockerfile, we don't allow "unsetting" an environment variable. (#11922) _, err := parseNameVal("foo", "ENV", &directive) - assert.Error(t, err, "ENV must have two arguments") + assert.Check(t, is.ErrorContains(err, ""), "ENV must have two arguments") } diff --git a/components/engine/builder/dockerfile/parser/parser_test.go b/components/engine/builder/dockerfile/parser/parser_test.go index 807ac1b097..10bed1f756 100644 --- a/components/engine/builder/dockerfile/parser/parser_test.go +++ b/components/engine/builder/dockerfile/parser/parser_test.go @@ -11,8 +11,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) const testDir = "testfiles" @@ -21,11 +21,11 @@ const testFileLineInfo = "testfile-line/Dockerfile" func getDirs(t *testing.T, dir string) []string { f, err := os.Open(dir) - require.NoError(t, err) + assert.NilError(t, err) defer f.Close() dirs, err := f.Readdirnames(0) - require.NoError(t, err) + assert.NilError(t, err) return dirs } @@ -34,11 +34,11 @@ func TestParseErrorCases(t *testing.T) { dockerfile := filepath.Join(negativeTestDir, dir, "Dockerfile") df, err := os.Open(dockerfile) - require.NoError(t, err, dockerfile) + assert.NilError(t, err, dockerfile) defer df.Close() _, err = Parse(df) - assert.Error(t, err, dockerfile) + assert.Check(t, is.ErrorContains(err, ""), dockerfile) } } @@ -48,20 +48,20 @@ func TestParseCases(t *testing.T) { resultfile := filepath.Join(testDir, dir, "result") df, err := os.Open(dockerfile) - require.NoError(t, err, dockerfile) + assert.NilError(t, err, dockerfile) defer df.Close() result, err := Parse(df) - require.NoError(t, err, dockerfile) + assert.NilError(t, err, dockerfile) content, err := ioutil.ReadFile(resultfile) - require.NoError(t, err, resultfile) + assert.NilError(t, err, resultfile) if runtime.GOOS == "windows" { // CRLF --> CR to match Unix behavior content = bytes.Replace(content, []byte{'\x0d', '\x0a'}, []byte{'\x0a'}, -1) } - assert.Equal(t, result.AST.Dump()+"\n", string(content), "In "+dockerfile) + assert.Check(t, is.Equal(result.AST.Dump()+"\n", string(content)), "In "+dockerfile) } } @@ -103,22 +103,22 @@ func TestParseWords(t *testing.T) { for _, test := range tests { words := parseWords(test["input"][0], NewDefaultDirective()) - assert.Equal(t, test["expect"], words) + assert.Check(t, is.DeepEqual(test["expect"], words)) } } func TestParseIncludesLineNumbers(t *testing.T) { df, err := os.Open(testFileLineInfo) - require.NoError(t, err) + assert.NilError(t, err) defer df.Close() result, err := Parse(df) - require.NoError(t, err) + assert.NilError(t, err) ast := result.AST - assert.Equal(t, 5, ast.StartLine) - assert.Equal(t, 31, ast.endLine) - assert.Len(t, ast.Children, 3) + assert.Check(t, is.Equal(5, ast.StartLine)) + assert.Check(t, is.Equal(31, ast.endLine)) + assert.Check(t, is.Len(ast.Children, 3)) expected := [][]int{ {5, 5}, {11, 12}, @@ -126,7 +126,7 @@ func TestParseIncludesLineNumbers(t *testing.T) { } for i, child := range ast.Children { msg := fmt.Sprintf("Child %d", i) - assert.Equal(t, expected[i], []int{child.StartLine, child.endLine}, msg) + assert.Check(t, is.DeepEqual(expected[i], []int{child.StartLine, child.endLine}), msg) } } @@ -153,13 +153,13 @@ RUN indented \ `) result, err := Parse(dockerfile) - require.NoError(t, err) + assert.NilError(t, err) warnings := result.Warnings - assert.Len(t, warnings, 3) - assert.Contains(t, warnings[0], "Empty continuation line found in") - assert.Contains(t, warnings[0], "RUN something following more") - assert.Contains(t, warnings[1], "RUN another thing") - assert.Contains(t, warnings[2], "will become errors in a future release") + assert.Check(t, is.Len(warnings, 3)) + assert.Check(t, is.Contains(warnings[0], "Empty continuation line found in")) + assert.Check(t, is.Contains(warnings[0], "RUN something following more")) + assert.Check(t, is.Contains(warnings[1], "RUN another thing")) + assert.Check(t, is.Contains(warnings[2], "will become errors in a future release")) } func TestParseReturnsScannerErrors(t *testing.T) { @@ -170,5 +170,5 @@ func TestParseReturnsScannerErrors(t *testing.T) { LABEL test=%s `, label)) _, err := Parse(dockerfile) - assert.EqualError(t, err, "dockerfile line greater than max allowed size of 65535") + assert.Check(t, is.Error(err, "dockerfile line greater than max allowed size of 65535")) } diff --git a/components/engine/builder/dockerfile/shell/lex_test.go b/components/engine/builder/dockerfile/shell/lex_test.go index 6932a44e3d..7a726ad79b 100644 --- a/components/engine/builder/dockerfile/shell/lex_test.go +++ b/components/engine/builder/dockerfile/shell/lex_test.go @@ -7,7 +7,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestShellParser4EnvVars(t *testing.T) { @@ -15,7 +16,7 @@ func TestShellParser4EnvVars(t *testing.T) { lineCount := 0 file, err := os.Open(fn) - assert.NoError(t, err) + assert.Check(t, err) defer file.Close() shlex := NewLex('\\') @@ -37,7 +38,7 @@ func TestShellParser4EnvVars(t *testing.T) { } words := strings.Split(line, "|") - assert.Len(t, words, 3) + assert.Check(t, is.Len(words, 3)) platform := strings.TrimSpace(words[0]) source := strings.TrimSpace(words[1]) @@ -52,10 +53,10 @@ func TestShellParser4EnvVars(t *testing.T) { ((platform == "U" || platform == "A") && runtime.GOOS != "windows") { newWord, err := shlex.ProcessWord(source, envs) if expected == "error" { - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) } else { - assert.NoError(t, err) - assert.Equal(t, newWord, expected) + assert.Check(t, err) + assert.Check(t, is.Equal(newWord, expected)) } } } diff --git a/components/engine/builder/fscache/fscache_test.go b/components/engine/builder/fscache/fscache_test.go index 7afee49ed5..613070f7b6 100644 --- a/components/engine/builder/fscache/fscache_test.go +++ b/components/engine/builder/fscache/fscache_test.go @@ -7,14 +7,15 @@ import ( "testing" "time" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/moby/buildkit/session/filesync" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) func TestFSCache(t *testing.T) { tmpDir, err := ioutil.TempDir("", "fscache") - assert.Nil(t, err) + assert.Check(t, err) defer os.RemoveAll(tmpDir) backend := NewNaiveCacheBackend(filepath.Join(tmpDir, "backend")) @@ -26,84 +27,84 @@ func TestFSCache(t *testing.T) { } fscache, err := NewFSCache(opt) - assert.Nil(t, err) + assert.Check(t, err) defer fscache.Close() err = fscache.RegisterTransport("test", &testTransport{}) - assert.Nil(t, err) + assert.Check(t, err) src1, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo", "data", "bar"}) - assert.Nil(t, err) + assert.Check(t, err) dt, err := ioutil.ReadFile(filepath.Join(src1.Root().Path(), "foo")) - assert.Nil(t, err) - assert.Equal(t, string(dt), "data") + assert.Check(t, err) + assert.Check(t, is.Equal(string(dt), "data")) // same id doesn't recalculate anything src2, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo", "data2", "bar"}) - assert.Nil(t, err) - assert.Equal(t, src1.Root().Path(), src2.Root().Path()) + assert.Check(t, err) + assert.Check(t, is.Equal(src1.Root().Path(), src2.Root().Path())) dt, err = ioutil.ReadFile(filepath.Join(src1.Root().Path(), "foo")) - assert.Nil(t, err) - assert.Equal(t, string(dt), "data") - assert.Nil(t, src2.Close()) + assert.Check(t, err) + assert.Check(t, is.Equal(string(dt), "data")) + assert.Check(t, src2.Close()) src3, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo2", "data2", "bar"}) - assert.Nil(t, err) - assert.NotEqual(t, src1.Root().Path(), src3.Root().Path()) + assert.Check(t, err) + assert.Check(t, src1.Root().Path() != src3.Root().Path()) dt, err = ioutil.ReadFile(filepath.Join(src3.Root().Path(), "foo2")) - assert.Nil(t, err) - assert.Equal(t, string(dt), "data2") + assert.Check(t, err) + assert.Check(t, is.Equal(string(dt), "data2")) s, err := fscache.DiskUsage() - assert.Nil(t, err) - assert.Equal(t, s, int64(0)) + assert.Check(t, err) + assert.Check(t, is.Equal(s, int64(0))) - assert.Nil(t, src3.Close()) + assert.Check(t, src3.Close()) s, err = fscache.DiskUsage() - assert.Nil(t, err) - assert.Equal(t, s, int64(5)) + assert.Check(t, err) + assert.Check(t, is.Equal(s, int64(5))) // new upload with the same shared key shoutl overwrite src4, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo3", "data3", "bar"}) - assert.Nil(t, err) - assert.NotEqual(t, src1.Root().Path(), src3.Root().Path()) + assert.Check(t, err) + assert.Check(t, src1.Root().Path() != src3.Root().Path()) dt, err = ioutil.ReadFile(filepath.Join(src3.Root().Path(), "foo3")) - assert.Nil(t, err) - assert.Equal(t, string(dt), "data3") - assert.Equal(t, src4.Root().Path(), src3.Root().Path()) - assert.Nil(t, src4.Close()) + assert.Check(t, err) + assert.Check(t, is.Equal(string(dt), "data3")) + assert.Check(t, is.Equal(src4.Root().Path(), src3.Root().Path())) + assert.Check(t, src4.Close()) s, err = fscache.DiskUsage() - assert.Nil(t, err) - assert.Equal(t, s, int64(10)) + assert.Check(t, err) + assert.Check(t, is.Equal(s, int64(10))) // this one goes over the GC limit src5, err := fscache.SyncFrom(context.TODO(), &testIdentifier{"foo4", "datadata", "baz"}) - assert.Nil(t, err) - assert.Nil(t, src5.Close()) + assert.Check(t, err) + assert.Check(t, src5.Close()) // GC happens async time.Sleep(100 * time.Millisecond) // only last insertion after GC s, err = fscache.DiskUsage() - assert.Nil(t, err) - assert.Equal(t, s, int64(8)) + assert.Check(t, err) + assert.Check(t, is.Equal(s, int64(8))) // prune deletes everything released, err := fscache.Prune(context.TODO()) - assert.Nil(t, err) - assert.Equal(t, released, uint64(8)) + assert.Check(t, err) + assert.Check(t, is.Equal(released, uint64(8))) s, err = fscache.DiskUsage() - assert.Nil(t, err) - assert.Equal(t, s, int64(0)) + assert.Check(t, err) + assert.Check(t, is.Equal(s, int64(0))) } type testTransport struct { diff --git a/components/engine/builder/remotecontext/git/gitutils_test.go b/components/engine/builder/remotecontext/git/gitutils_test.go index 4f4d833508..a46675b22b 100644 --- a/components/engine/builder/remotecontext/git/gitutils_test.go +++ b/components/engine/builder/remotecontext/git/gitutils_test.go @@ -13,42 +13,39 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/google/go-cmp/cmp" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestParseRemoteURL(t *testing.T) { dir, err := parseRemoteURL("git://github.com/user/repo.git") - require.NoError(t, err) - assert.NotEmpty(t, dir) - assert.Equal(t, gitRepo{"git://github.com/user/repo.git", "master", ""}, dir) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt)) dir, err = parseRemoteURL("git://github.com/user/repo.git#mybranch:mydir/mysubdir/") - require.NoError(t, err) - assert.NotEmpty(t, dir) - assert.Equal(t, gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(gitRepo{"git://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt)) dir, err = parseRemoteURL("https://github.com/user/repo.git") - require.NoError(t, err) - assert.NotEmpty(t, dir) - assert.Equal(t, gitRepo{"https://github.com/user/repo.git", "master", ""}, dir) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "master", ""}, dir, cmpGitRepoOpt)) dir, err = parseRemoteURL("https://github.com/user/repo.git#mybranch:mydir/mysubdir/") - require.NoError(t, err) - assert.NotEmpty(t, dir) - assert.Equal(t, gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(gitRepo{"https://github.com/user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt)) dir, err = parseRemoteURL("git@github.com:user/repo.git") - require.NoError(t, err) - assert.NotEmpty(t, dir) - assert.Equal(t, gitRepo{"git@github.com:user/repo.git", "master", ""}, dir) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "master", ""}, dir, cmpGitRepoOpt)) dir, err = parseRemoteURL("git@github.com:user/repo.git#mybranch:mydir/mysubdir/") - require.NoError(t, err) - assert.NotEmpty(t, dir) - assert.Equal(t, gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(gitRepo{"git@github.com:user/repo.git", "mybranch", "mydir/mysubdir/"}, dir, cmpGitRepoOpt)) } +var cmpGitRepoOpt = cmp.AllowUnexported(gitRepo{}) + func TestCloneArgsSmartHttp(t *testing.T) { mux := http.NewServeMux() server := httptest.NewServer(mux) @@ -63,7 +60,7 @@ func TestCloneArgsSmartHttp(t *testing.T) { args := fetchArgs(serverURL.String(), "master") exp := []string{"fetch", "--depth", "1", "origin", "master"} - assert.Equal(t, exp, args) + assert.Check(t, is.DeepEqual(exp, args)) } func TestCloneArgsDumbHttp(t *testing.T) { @@ -79,13 +76,13 @@ func TestCloneArgsDumbHttp(t *testing.T) { args := fetchArgs(serverURL.String(), "master") exp := []string{"fetch", "origin", "master"} - assert.Equal(t, exp, args) + assert.Check(t, is.DeepEqual(exp, args)) } func TestCloneArgsGit(t *testing.T) { args := fetchArgs("git://github.com/docker/docker", "master") exp := []string{"fetch", "--depth", "1", "origin", "master"} - assert.Equal(t, exp, args) + assert.Check(t, is.DeepEqual(exp, args)) } func gitGetConfig(name string) string { @@ -100,7 +97,7 @@ func gitGetConfig(name string) string { func TestCheckoutGit(t *testing.T) { root, err := ioutil.TempDir("", "docker-build-git-checkout") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(root) autocrlf := gitGetConfig("core.autocrlf") @@ -115,22 +112,22 @@ func TestCheckoutGit(t *testing.T) { gitDir := filepath.Join(root, "repo") _, err = git("init", gitDir) - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "config", "user.email", "test@docker.com") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "config", "user.name", "Docker test") - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch"), 0644) - require.NoError(t, err) + assert.NilError(t, err) subDir := filepath.Join(gitDir, "subdir") - require.NoError(t, os.Mkdir(subDir, 0755)) + assert.NilError(t, os.Mkdir(subDir, 0755)) err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 5000"), 0644) - require.NoError(t, err) + assert.NilError(t, err) if runtime.GOOS != "windows" { if err = os.Symlink("../subdir", filepath.Join(gitDir, "parentlink")); err != nil { @@ -143,58 +140,58 @@ func TestCheckoutGit(t *testing.T) { } _, err = gitWithinDir(gitDir, "add", "-A") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "commit", "-am", "First commit") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "checkout", "-b", "test") - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(gitDir, "Dockerfile"), []byte("FROM scratch\nEXPOSE 3000"), 0644) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(subDir, "Dockerfile"), []byte("FROM busybox\nEXPOSE 5000"), 0644) - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "add", "-A") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "commit", "-am", "Branch commit") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "checkout", "master") - require.NoError(t, err) + assert.NilError(t, err) // set up submodule subrepoDir := filepath.Join(root, "subrepo") _, err = git("init", subrepoDir) - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(subrepoDir, "config", "user.email", "test@docker.com") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(subrepoDir, "config", "user.name", "Docker test") - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(subrepoDir, "subfile"), []byte("subcontents"), 0644) - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(subrepoDir, "add", "-A") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(subrepoDir, "commit", "-am", "Subrepo initial") - require.NoError(t, err) + assert.NilError(t, err) cmd := exec.Command("git", "submodule", "add", subrepoDir, "sub") // this command doesn't work with --work-tree cmd.Dir = gitDir - require.NoError(t, cmd.Run()) + assert.NilError(t, cmd.Run()) _, err = gitWithinDir(gitDir, "add", "-A") - require.NoError(t, err) + assert.NilError(t, err) _, err = gitWithinDir(gitDir, "commit", "-am", "With submodule") - require.NoError(t, err) + assert.NilError(t, err) type singleCase struct { frag string @@ -232,24 +229,24 @@ func TestCheckoutGit(t *testing.T) { r, err := cloneGitRepo(gitRepo{remote: gitDir, ref: ref, subdir: subdir}) if c.fail { - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) continue } - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(r) if c.submodule { b, err := ioutil.ReadFile(filepath.Join(r, "sub/subfile")) - require.NoError(t, err) - assert.Equal(t, "subcontents", string(b)) + assert.NilError(t, err) + assert.Check(t, is.Equal("subcontents", string(b))) } else { _, err := os.Stat(filepath.Join(r, "sub/subfile")) - require.Error(t, err) - require.True(t, os.IsNotExist(err)) + assert.Assert(t, is.ErrorContains(err, "")) + assert.Assert(t, os.IsNotExist(err)) } b, err := ioutil.ReadFile(filepath.Join(r, "Dockerfile")) - require.NoError(t, err) - assert.Equal(t, c.exp, string(b)) + assert.NilError(t, err) + assert.Check(t, is.Equal(c.exp, string(b))) } } diff --git a/components/engine/builder/remotecontext/mimetype_test.go b/components/engine/builder/remotecontext/mimetype_test.go index ff097c2e7b..b13429cfa8 100644 --- a/components/engine/builder/remotecontext/mimetype_test.go +++ b/components/engine/builder/remotecontext/mimetype_test.go @@ -3,14 +3,14 @@ package remotecontext // import "github.com/docker/docker/builder/remotecontext" import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestDetectContentType(t *testing.T) { input := []byte("That is just a plain text") contentType, _, err := detectContentType(input) - require.NoError(t, err) - assert.Equal(t, "text/plain", contentType) + assert.NilError(t, err) + assert.Check(t, is.Equal("text/plain", contentType)) } diff --git a/components/engine/builder/remotecontext/remote_test.go b/components/engine/builder/remotecontext/remote_test.go index 3983bd1b6c..5267d23969 100644 --- a/components/engine/builder/remotecontext/remote_test.go +++ b/components/engine/builder/remotecontext/remote_test.go @@ -11,9 +11,9 @@ import ( "github.com/docker/docker/builder" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var binaryContext = []byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00} //xz magic @@ -189,12 +189,12 @@ func TestDownloadRemote(t *testing.T) { mux.Handle("/", http.FileServer(http.Dir(contextDir.Path()))) contentType, content, err := downloadRemote(remoteURL) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, mimeTypes.TextPlain, contentType) + assert.Check(t, is.Equal(mimeTypes.TextPlain, contentType)) raw, err := ioutil.ReadAll(content) - require.NoError(t, err) - assert.Equal(t, dockerfileContents, string(raw)) + assert.NilError(t, err) + assert.Check(t, is.Equal(dockerfileContents, string(raw))) } func TestGetWithStatusError(t *testing.T) { @@ -226,11 +226,11 @@ func TestGetWithStatusError(t *testing.T) { response, err := GetWithStatusError(ts.URL) if testcase.expectedErr == "" { - require.NoError(t, err) + assert.NilError(t, err) body, err := readBody(response.Body) - require.NoError(t, err) - assert.Contains(t, string(body), testcase.expectedBody) + assert.NilError(t, err) + assert.Check(t, is.Contains(string(body), testcase.expectedBody)) } else { testutil.ErrorContains(t, err, testcase.expectedErr) } diff --git a/components/engine/client/client_test.go b/components/engine/client/client_test.go index d6b8f67352..7cca04ac72 100644 --- a/components/engine/client/client_test.go +++ b/components/engine/client/client_test.go @@ -11,10 +11,10 @@ import ( "github.com/docker/docker/api" "github.com/docker/docker/api/types" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/env" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNewEnvClient(t *testing.T) { @@ -89,19 +89,18 @@ func TestNewEnvClient(t *testing.T) { env.PatchAll(t, c.envs) apiclient, err := NewEnvClient() if c.expectedError != "" { - assert.Error(t, err, c.doc) - assert.Equal(t, c.expectedError, err.Error(), c.doc) + assert.Check(t, is.Error(err, c.expectedError), c.doc) } else { - assert.NoError(t, err, c.doc) + assert.Check(t, err, c.doc) version := apiclient.ClientVersion() - assert.Equal(t, c.expectedVersion, version, c.doc) + assert.Check(t, is.Equal(c.expectedVersion, version), c.doc) } if c.envs["DOCKER_TLS_VERIFY"] != "" { // pedantic checking that this is handled correctly tr := apiclient.client.Transport.(*http.Transport) - assert.NotNil(t, tr.TLSClientConfig, c.doc) - assert.Equal(t, tr.TLSClientConfig.InsecureSkipVerify, false, c.doc) + assert.Assert(t, tr.TLSClientConfig != nil, c.doc) + assert.Check(t, is.Equal(tr.TLSClientConfig.InsecureSkipVerify, false), c.doc) } } } @@ -128,7 +127,7 @@ func TestGetAPIPath(t *testing.T) { for _, testcase := range testcases { c := Client{version: testcase.version, basePath: "/"} actual := c.getAPIPath(testcase.path, testcase.query) - assert.Equal(t, actual, testcase.expected) + assert.Check(t, is.Equal(actual, testcase.expected)) } } @@ -165,7 +164,7 @@ func TestParseHostURL(t *testing.T) { if testcase.expectedErr != "" { testutil.ErrorContains(t, err, testcase.expectedErr) } - assert.Equal(t, testcase.expected, actual) + assert.Check(t, is.DeepEqual(testcase.expected, actual)) } } @@ -181,7 +180,7 @@ func TestNewEnvClientSetsDefaultVersion(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, client.version, api.DefaultVersion) + assert.Check(t, is.Equal(client.version, api.DefaultVersion)) expected := "1.22" os.Setenv("DOCKER_API_VERSION", expected) @@ -189,7 +188,7 @@ func TestNewEnvClientSetsDefaultVersion(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, expected, client.version) + assert.Check(t, is.Equal(expected, client.version)) } // TestNegotiateAPIVersionEmpty asserts that client.Client can @@ -198,7 +197,7 @@ func TestNegotiateAPIVersionEmpty(t *testing.T) { defer env.PatchAll(t, map[string]string{"DOCKER_API_VERSION": ""}) client, err := NewEnvClient() - require.NoError(t, err) + assert.NilError(t, err) ping := types.Ping{ APIVersion: "", @@ -215,14 +214,14 @@ func TestNegotiateAPIVersionEmpty(t *testing.T) { // test downgrade client.NegotiateAPIVersionPing(ping) - assert.Equal(t, expected, client.version) + assert.Check(t, is.Equal(expected, client.version)) } // TestNegotiateAPIVersion asserts that client.Client can // negotiate a compatible APIVersion with the server func TestNegotiateAPIVersion(t *testing.T) { client, err := NewEnvClient() - require.NoError(t, err) + assert.NilError(t, err) expected := "1.21" ping := types.Ping{ @@ -236,14 +235,14 @@ func TestNegotiateAPIVersion(t *testing.T) { // test downgrade client.NegotiateAPIVersionPing(ping) - assert.Equal(t, expected, client.version) + assert.Check(t, is.Equal(expected, client.version)) // set the client version to something older, and verify that we keep the // original setting. expected = "1.20" client.version = expected client.NegotiateAPIVersionPing(ping) - assert.Equal(t, expected, client.version) + assert.Check(t, is.Equal(expected, client.version)) } @@ -254,7 +253,7 @@ func TestNegotiateAPVersionOverride(t *testing.T) { defer env.PatchAll(t, map[string]string{"DOCKER_API_VERSION": expected})() client, err := NewEnvClient() - require.NoError(t, err) + assert.NilError(t, err) ping := types.Ping{ APIVersion: "1.24", @@ -264,7 +263,7 @@ func TestNegotiateAPVersionOverride(t *testing.T) { // test that we honored the env var client.NegotiateAPIVersionPing(ping) - assert.Equal(t, expected, client.version) + assert.Check(t, is.Equal(expected, client.version)) } type roundTripFunc func(*http.Request) (*http.Response, error) @@ -298,7 +297,7 @@ func TestClientRedirect(t *testing.T) { cases := []struct { httpMethod string - expectedErr error + expectedErr *url.Error statusCode int }{ {http.MethodGet, nil, 301}, @@ -309,9 +308,15 @@ func TestClientRedirect(t *testing.T) { for _, tc := range cases { req, err := http.NewRequest(tc.httpMethod, "/redirectme", nil) - assert.NoError(t, err) + assert.Check(t, err) resp, err := client.Do(req) - assert.Equal(t, tc.expectedErr, err) - assert.Equal(t, tc.statusCode, resp.StatusCode) + assert.Check(t, is.Equal(tc.statusCode, resp.StatusCode)) + if tc.expectedErr == nil { + assert.Check(t, is.Nil(err)) + } else { + urlError, ok := err.(*url.Error) + assert.Assert(t, ok, "%T is not *url.Error", err) + assert.Check(t, is.Equal(*tc.expectedErr, *urlError)) + } } } diff --git a/components/engine/client/config_create_test.go b/components/engine/client/config_create_test.go index 3f3cb3fc56..2ee8f1fd40 100644 --- a/components/engine/client/config_create_test.go +++ b/components/engine/client/config_create_test.go @@ -11,7 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -21,7 +22,7 @@ func TestConfigCreateUnsupported(t *testing.T) { client: &http.Client{}, } _, err := client.ConfigCreate(context.Background(), swarm.ConfigSpec{}) - assert.EqualError(t, err, `"config create" requires API version 1.30, but the Docker daemon API version is 1.29`) + assert.Check(t, is.Error(err, `"config create" requires API version 1.30, but the Docker daemon API version is 1.29`)) } func TestConfigCreateError(t *testing.T) { diff --git a/components/engine/client/config_inspect_test.go b/components/engine/client/config_inspect_test.go index c6d73e5c02..9d5af0bf8c 100644 --- a/components/engine/client/config_inspect_test.go +++ b/components/engine/client/config_inspect_test.go @@ -10,8 +10,9 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -44,7 +45,7 @@ func TestConfigInspectUnsupported(t *testing.T) { client: &http.Client{}, } _, _, err := client.ConfigInspectWithRaw(context.Background(), "nothing") - assert.EqualError(t, err, `"config inspect" requires API version 1.30, but the Docker daemon API version is 1.29`) + assert.Check(t, is.Error(err, `"config inspect" requires API version 1.30, but the Docker daemon API version is 1.29`)) } func TestConfigInspectError(t *testing.T) { diff --git a/components/engine/client/config_list_test.go b/components/engine/client/config_list_test.go index 4b4a5e84ce..0cd99c50d1 100644 --- a/components/engine/client/config_list_test.go +++ b/components/engine/client/config_list_test.go @@ -12,7 +12,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -22,7 +23,7 @@ func TestConfigListUnsupported(t *testing.T) { client: &http.Client{}, } _, err := client.ConfigList(context.Background(), types.ConfigListOptions{}) - assert.EqualError(t, err, `"config list" requires API version 1.30, but the Docker daemon API version is 1.29`) + assert.Check(t, is.Error(err, `"config list" requires API version 1.30, but the Docker daemon API version is 1.29`)) } func TestConfigListError(t *testing.T) { diff --git a/components/engine/client/config_remove_test.go b/components/engine/client/config_remove_test.go index 290395aae5..25a5c4ac87 100644 --- a/components/engine/client/config_remove_test.go +++ b/components/engine/client/config_remove_test.go @@ -8,7 +8,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -18,7 +19,7 @@ func TestConfigRemoveUnsupported(t *testing.T) { client: &http.Client{}, } err := client.ConfigRemove(context.Background(), "config_id") - assert.EqualError(t, err, `"config remove" requires API version 1.30, but the Docker daemon API version is 1.29`) + assert.Check(t, is.Error(err, `"config remove" requires API version 1.30, but the Docker daemon API version is 1.29`)) } func TestConfigRemoveError(t *testing.T) { diff --git a/components/engine/client/config_update_test.go b/components/engine/client/config_update_test.go index 99f2e173c2..a7eea2f8b1 100644 --- a/components/engine/client/config_update_test.go +++ b/components/engine/client/config_update_test.go @@ -9,7 +9,8 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -19,7 +20,7 @@ func TestConfigUpdateUnsupported(t *testing.T) { client: &http.Client{}, } err := client.ConfigUpdate(context.Background(), "config_id", swarm.Version{}, swarm.ConfigSpec{}) - assert.EqualError(t, err, `"config update" requires API version 1.30, but the Docker daemon API version is 1.29`) + assert.Check(t, is.Error(err, `"config update" requires API version 1.30, but the Docker daemon API version is 1.29`)) } func TestConfigUpdateError(t *testing.T) { diff --git a/components/engine/client/container_prune_test.go b/components/engine/client/container_prune_test.go index 1f8c22cbfe..7ffd9c7ecf 100644 --- a/components/engine/client/container_prune_test.go +++ b/components/engine/client/container_prune_test.go @@ -11,7 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -24,7 +25,7 @@ func TestContainersPruneError(t *testing.T) { filters := filters.NewArgs() _, err := client.ContainersPrune(context.Background(), filters) - assert.EqualError(t, err, "Error response from daemon: Server error") + assert.Check(t, is.Error(err, "Error response from daemon: Server error")) } func TestContainersPrune(t *testing.T) { @@ -99,7 +100,7 @@ func TestContainersPrune(t *testing.T) { query := req.URL.Query() for key, expected := range listCase.expectedQueryParams { actual := query.Get(key) - assert.Equal(t, expected, actual) + assert.Check(t, is.Equal(expected, actual)) } content, err := json.Marshal(types.ContainersPruneReport{ ContainersDeleted: []string{"container_id1", "container_id2"}, @@ -117,8 +118,8 @@ func TestContainersPrune(t *testing.T) { } report, err := client.ContainersPrune(context.Background(), listCase.filters) - assert.NoError(t, err) - assert.Len(t, report.ContainersDeleted, 2) - assert.Equal(t, uint64(9999), report.SpaceReclaimed) + assert.Check(t, err) + assert.Check(t, is.Len(report.ContainersDeleted, 2)) + assert.Check(t, is.Equal(uint64(9999), report.SpaceReclaimed)) } } diff --git a/components/engine/client/container_remove_test.go b/components/engine/client/container_remove_test.go index 0b1b64fa3a..537272cd1d 100644 --- a/components/engine/client/container_remove_test.go +++ b/components/engine/client/container_remove_test.go @@ -9,7 +9,8 @@ import ( "testing" "github.com/docker/docker/api/types" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -18,7 +19,7 @@ func TestContainerRemoveError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{}) - assert.EqualError(t, err, "Error response from daemon: Server error") + assert.Check(t, is.Error(err, "Error response from daemon: Server error")) } func TestContainerRemoveNotFoundError(t *testing.T) { @@ -26,8 +27,8 @@ func TestContainerRemoveNotFoundError(t *testing.T) { client: newMockClient(errorMock(http.StatusNotFound, "missing")), } err := client.ContainerRemove(context.Background(), "container_id", types.ContainerRemoveOptions{}) - assert.EqualError(t, err, "Error: No such container: container_id") - assert.True(t, IsErrNotFound(err)) + assert.Check(t, is.Error(err, "Error: No such container: container_id")) + assert.Check(t, IsErrNotFound(err)) } func TestContainerRemove(t *testing.T) { @@ -61,5 +62,5 @@ func TestContainerRemove(t *testing.T) { RemoveVolumes: true, Force: true, }) - assert.NoError(t, err) + assert.Check(t, err) } diff --git a/components/engine/client/distribution_inspect_test.go b/components/engine/client/distribution_inspect_test.go index 90b35a285b..d4124bfa15 100644 --- a/components/engine/client/distribution_inspect_test.go +++ b/components/engine/client/distribution_inspect_test.go @@ -4,8 +4,9 @@ import ( "net/http" "testing" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -15,7 +16,7 @@ func TestDistributionInspectUnsupported(t *testing.T) { client: &http.Client{}, } _, err := client.DistributionInspect(context.Background(), "foobar:1.0", "") - assert.EqualError(t, err, `"distribution inspect" requires API version 1.30, but the Docker daemon API version is 1.29`) + assert.Check(t, is.Error(err, `"distribution inspect" requires API version 1.30, but the Docker daemon API version is 1.29`)) } func TestDistributionInspectWithEmptyID(t *testing.T) { diff --git a/components/engine/client/image_prune_test.go b/components/engine/client/image_prune_test.go index f165e5c746..9b161531f2 100644 --- a/components/engine/client/image_prune_test.go +++ b/components/engine/client/image_prune_test.go @@ -11,7 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -24,7 +25,7 @@ func TestImagesPruneError(t *testing.T) { filters := filters.NewArgs() _, err := client.ImagesPrune(context.Background(), filters) - assert.EqualError(t, err, "Error response from daemon: Server error") + assert.Check(t, is.Error(err, "Error response from daemon: Server error")) } func TestImagesPrune(t *testing.T) { @@ -87,7 +88,7 @@ func TestImagesPrune(t *testing.T) { query := req.URL.Query() for key, expected := range listCase.expectedQueryParams { actual := query.Get(key) - assert.Equal(t, expected, actual) + assert.Check(t, is.Equal(expected, actual)) } content, err := json.Marshal(types.ImagesPruneReport{ ImagesDeleted: []types.ImageDeleteResponseItem{ @@ -112,8 +113,8 @@ func TestImagesPrune(t *testing.T) { } report, err := client.ImagesPrune(context.Background(), listCase.filters) - assert.NoError(t, err) - assert.Len(t, report.ImagesDeleted, 2) - assert.Equal(t, uint64(9999), report.SpaceReclaimed) + assert.Check(t, err) + assert.Check(t, is.Len(report.ImagesDeleted, 2)) + assert.Check(t, is.Equal(uint64(9999), report.SpaceReclaimed)) } } diff --git a/components/engine/client/image_remove_test.go b/components/engine/client/image_remove_test.go index 8f5aa0120d..a1686e6496 100644 --- a/components/engine/client/image_remove_test.go +++ b/components/engine/client/image_remove_test.go @@ -10,7 +10,8 @@ import ( "testing" "github.com/docker/docker/api/types" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -20,7 +21,7 @@ func TestImageRemoveError(t *testing.T) { } _, err := client.ImageRemove(context.Background(), "image_id", types.ImageRemoveOptions{}) - assert.EqualError(t, err, "Error response from daemon: Server error") + assert.Check(t, is.Error(err, "Error response from daemon: Server error")) } func TestImageRemoveImageNotFound(t *testing.T) { @@ -29,8 +30,8 @@ func TestImageRemoveImageNotFound(t *testing.T) { } _, err := client.ImageRemove(context.Background(), "unknown", types.ImageRemoveOptions{}) - assert.EqualError(t, err, "Error: No such image: unknown") - assert.True(t, IsErrNotFound(err)) + assert.Check(t, is.Error(err, "Error: No such image: unknown")) + assert.Check(t, IsErrNotFound(err)) } func TestImageRemove(t *testing.T) { diff --git a/components/engine/client/network_inspect_test.go b/components/engine/client/network_inspect_test.go index 7031611911..8778021ed9 100644 --- a/components/engine/client/network_inspect_test.go +++ b/components/engine/client/network_inspect_test.go @@ -11,8 +11,9 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -22,7 +23,7 @@ func TestNetworkInspectError(t *testing.T) { } _, err := client.NetworkInspect(context.Background(), "nothing", types.NetworkInspectOptions{}) - assert.EqualError(t, err, "Error response from daemon: Server error") + assert.Check(t, is.Error(err, "Error response from daemon: Server error")) } func TestNetworkInspectNotFoundError(t *testing.T) { @@ -31,8 +32,8 @@ func TestNetworkInspectNotFoundError(t *testing.T) { } _, err := client.NetworkInspect(context.Background(), "unknown", types.NetworkInspectOptions{}) - assert.EqualError(t, err, "Error: No such network: unknown") - assert.True(t, IsErrNotFound(err)) + assert.Check(t, is.Error(err, "Error: No such network: unknown")) + assert.Check(t, IsErrNotFound(err)) } func TestNetworkInspectWithEmptyID(t *testing.T) { @@ -113,5 +114,5 @@ func TestNetworkInspect(t *testing.T) { } _, err = client.NetworkInspect(context.Background(), "network_id", types.NetworkInspectOptions{Scope: "global"}) - assert.EqualError(t, err, "Error: No such network: network_id") + assert.Check(t, is.Error(err, "Error: No such network: network_id")) } diff --git a/components/engine/client/network_prune_test.go b/components/engine/client/network_prune_test.go index 8bba3751e7..85908f0cf3 100644 --- a/components/engine/client/network_prune_test.go +++ b/components/engine/client/network_prune_test.go @@ -11,7 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -89,7 +90,7 @@ func TestNetworksPrune(t *testing.T) { query := req.URL.Query() for key, expected := range listCase.expectedQueryParams { actual := query.Get(key) - assert.Equal(t, expected, actual) + assert.Check(t, is.Equal(expected, actual)) } content, err := json.Marshal(types.NetworksPruneReport{ NetworksDeleted: []string{"network_id1", "network_id2"}, @@ -106,7 +107,7 @@ func TestNetworksPrune(t *testing.T) { } report, err := client.NetworksPrune(context.Background(), listCase.filters) - assert.NoError(t, err) - assert.Len(t, report.NetworksDeleted, 2) + assert.Check(t, err) + assert.Check(t, is.Len(report.NetworksDeleted, 2)) } } diff --git a/components/engine/client/ping_test.go b/components/engine/client/ping_test.go index 69ff86269d..f83233aceb 100644 --- a/components/engine/client/ping_test.go +++ b/components/engine/client/ping_test.go @@ -7,7 +7,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -31,15 +32,15 @@ func TestPingFail(t *testing.T) { } ping, err := client.Ping(context.Background()) - assert.Error(t, err) - assert.Equal(t, false, ping.Experimental) - assert.Equal(t, "", ping.APIVersion) + assert.Check(t, is.ErrorContains(err, "")) + assert.Check(t, is.Equal(false, ping.Experimental)) + assert.Check(t, is.Equal("", ping.APIVersion)) withHeader = true ping2, err := client.Ping(context.Background()) - assert.Error(t, err) - assert.Equal(t, true, ping2.Experimental) - assert.Equal(t, "awesome", ping2.APIVersion) + assert.Check(t, is.ErrorContains(err, "")) + assert.Check(t, is.Equal(true, ping2.Experimental)) + assert.Check(t, is.Equal("awesome", ping2.APIVersion)) } // TestPingWithError tests the case where there is a protocol error in the ping. @@ -57,9 +58,9 @@ func TestPingWithError(t *testing.T) { } ping, err := client.Ping(context.Background()) - assert.Error(t, err) - assert.Equal(t, false, ping.Experimental) - assert.Equal(t, "", ping.APIVersion) + assert.Check(t, is.ErrorContains(err, "")) + assert.Check(t, is.Equal(false, ping.Experimental)) + assert.Check(t, is.Equal("", ping.APIVersion)) } // TestPingSuccess tests that we are able to get the expected API headers/ping @@ -76,7 +77,7 @@ func TestPingSuccess(t *testing.T) { }), } ping, err := client.Ping(context.Background()) - assert.Error(t, err) - assert.Equal(t, true, ping.Experimental) - assert.Equal(t, "awesome", ping.APIVersion) + assert.Check(t, is.ErrorContains(err, "")) + assert.Check(t, is.Equal(true, ping.Experimental)) + assert.Check(t, is.Equal("awesome", ping.APIVersion)) } diff --git a/components/engine/client/request_test.go b/components/engine/client/request_test.go index 1dbfed62c7..1a0a87e2f4 100644 --- a/components/engine/client/request_test.go +++ b/components/engine/client/request_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/docker/docker/api/types" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" "golang.org/x/net/context" ) @@ -46,7 +46,7 @@ func TestSetHostHeader(t *testing.T) { for c, test := range testCases { hostURL, err := ParseHostURL(test.host) - require.NoError(t, err) + assert.NilError(t, err) client := &Client{ client: newMockClient(func(req *http.Request) (*http.Response, error) { @@ -71,7 +71,7 @@ func TestSetHostHeader(t *testing.T) { } _, err = client.sendRequest(context.Background(), "GET", testURL, nil, nil, nil) - require.NoError(t, err) + assert.NilError(t, err) } } diff --git a/components/engine/client/secret_create_test.go b/components/engine/client/secret_create_test.go index 7d54e1aeb0..b31cab509f 100644 --- a/components/engine/client/secret_create_test.go +++ b/components/engine/client/secret_create_test.go @@ -11,7 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -21,7 +22,7 @@ func TestSecretCreateUnsupported(t *testing.T) { client: &http.Client{}, } _, err := client.SecretCreate(context.Background(), swarm.SecretSpec{}) - assert.EqualError(t, err, `"secret create" requires API version 1.25, but the Docker daemon API version is 1.24`) + assert.Check(t, is.Error(err, `"secret create" requires API version 1.25, but the Docker daemon API version is 1.24`)) } func TestSecretCreateError(t *testing.T) { diff --git a/components/engine/client/secret_inspect_test.go b/components/engine/client/secret_inspect_test.go index eb63162c18..0bb3ae24cc 100644 --- a/components/engine/client/secret_inspect_test.go +++ b/components/engine/client/secret_inspect_test.go @@ -10,8 +10,9 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -21,7 +22,7 @@ func TestSecretInspectUnsupported(t *testing.T) { client: &http.Client{}, } _, _, err := client.SecretInspectWithRaw(context.Background(), "nothing") - assert.EqualError(t, err, `"secret inspect" requires API version 1.25, but the Docker daemon API version is 1.24`) + assert.Check(t, is.Error(err, `"secret inspect" requires API version 1.25, but the Docker daemon API version is 1.24`)) } func TestSecretInspectError(t *testing.T) { diff --git a/components/engine/client/secret_list_test.go b/components/engine/client/secret_list_test.go index 2bd427898b..36d8e8e2f0 100644 --- a/components/engine/client/secret_list_test.go +++ b/components/engine/client/secret_list_test.go @@ -12,7 +12,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -22,7 +23,7 @@ func TestSecretListUnsupported(t *testing.T) { client: &http.Client{}, } _, err := client.SecretList(context.Background(), types.SecretListOptions{}) - assert.EqualError(t, err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`) + assert.Check(t, is.Error(err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`)) } func TestSecretListError(t *testing.T) { diff --git a/components/engine/client/secret_remove_test.go b/components/engine/client/secret_remove_test.go index 44cc0cbcc4..37c22650d1 100644 --- a/components/engine/client/secret_remove_test.go +++ b/components/engine/client/secret_remove_test.go @@ -8,7 +8,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -18,7 +19,7 @@ func TestSecretRemoveUnsupported(t *testing.T) { client: &http.Client{}, } err := client.SecretRemove(context.Background(), "secret_id") - assert.EqualError(t, err, `"secret remove" requires API version 1.25, but the Docker daemon API version is 1.24`) + assert.Check(t, is.Error(err, `"secret remove" requires API version 1.25, but the Docker daemon API version is 1.24`)) } func TestSecretRemoveError(t *testing.T) { diff --git a/components/engine/client/secret_update_test.go b/components/engine/client/secret_update_test.go index d2fca4b2d5..3ff172ba53 100644 --- a/components/engine/client/secret_update_test.go +++ b/components/engine/client/secret_update_test.go @@ -9,7 +9,8 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -19,7 +20,7 @@ func TestSecretUpdateUnsupported(t *testing.T) { client: &http.Client{}, } err := client.SecretUpdate(context.Background(), "secret_id", swarm.Version{}, swarm.SecretSpec{}) - assert.EqualError(t, err, `"secret update" requires API version 1.25, but the Docker daemon API version is 1.24`) + assert.Check(t, is.Error(err, `"secret update" requires API version 1.25, but the Docker daemon API version is 1.24`)) } func TestSecretUpdateError(t *testing.T) { diff --git a/components/engine/client/service_create_test.go b/components/engine/client/service_create_test.go index 9e859b18ac..c5d8ae4ff9 100644 --- a/components/engine/client/service_create_test.go +++ b/components/engine/client/service_create_test.go @@ -12,9 +12,10 @@ import ( "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" "github.com/docker/docker/api/types/swarm" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/specs-go/v1" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -73,8 +74,8 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) { return nil, err } - assert.Equal(t, "foobar:1.0@sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96", serviceSpec.TaskTemplate.ContainerSpec.Image) - assert.Len(t, serviceSpec.TaskTemplate.Placement.Platforms, 1) + assert.Check(t, is.Equal("foobar:1.0@sha256:c0537ff6a5218ef531ece93d4984efc99bbf3f7497c0a7726c88e2bb7584dc96", serviceSpec.TaskTemplate.ContainerSpec.Image)) + assert.Check(t, is.Len(serviceSpec.TaskTemplate.Placement.Platforms, 1)) p := serviceSpec.TaskTemplate.Placement.Platforms[0] b, err := json.Marshal(types.ServiceCreateResponse{ @@ -115,8 +116,8 @@ func TestServiceCreateCompatiblePlatforms(t *testing.T) { spec := swarm.ServiceSpec{TaskTemplate: swarm.TaskSpec{ContainerSpec: &swarm.ContainerSpec{Image: "foobar:1.0"}}} r, err := client.ServiceCreate(context.Background(), spec, types.ServiceCreateOptions{QueryRegistry: true}) - assert.NoError(t, err) - assert.Equal(t, "service_linux_amd64", r.ID) + assert.Check(t, err) + assert.Check(t, is.Equal("service_linux_amd64", r.ID)) } func TestServiceCreateDigestPinning(t *testing.T) { diff --git a/components/engine/client/service_remove_test.go b/components/engine/client/service_remove_test.go index 0909c9e064..9198763f8e 100644 --- a/components/engine/client/service_remove_test.go +++ b/components/engine/client/service_remove_test.go @@ -8,7 +8,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -18,7 +19,7 @@ func TestServiceRemoveError(t *testing.T) { } err := client.ServiceRemove(context.Background(), "service_id") - assert.EqualError(t, err, "Error response from daemon: Server error") + assert.Check(t, is.Error(err, "Error response from daemon: Server error")) } func TestServiceRemoveNotFoundError(t *testing.T) { @@ -27,8 +28,8 @@ func TestServiceRemoveNotFoundError(t *testing.T) { } err := client.ServiceRemove(context.Background(), "service_id") - assert.EqualError(t, err, "Error: No such service: service_id") - assert.True(t, IsErrNotFound(err)) + assert.Check(t, is.Error(err, "Error: No such service: service_id")) + assert.Check(t, IsErrNotFound(err)) } func TestServiceRemove(t *testing.T) { diff --git a/components/engine/client/swarm_get_unlock_key_test.go b/components/engine/client/swarm_get_unlock_key_test.go index c4ac70738a..aff79440fe 100644 --- a/components/engine/client/swarm_get_unlock_key_test.go +++ b/components/engine/client/swarm_get_unlock_key_test.go @@ -11,8 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -55,6 +55,6 @@ func TestSwarmGetUnlockKey(t *testing.T) { } resp, err := client.SwarmGetUnlockKey(context.Background()) - require.NoError(t, err) - assert.Equal(t, unlockKey, resp.UnlockKey) + assert.NilError(t, err) + assert.Check(t, is.Equal(unlockKey, resp.UnlockKey)) } diff --git a/components/engine/client/volume_inspect_test.go b/components/engine/client/volume_inspect_test.go index c97f5c7215..4a2cf7c7d7 100644 --- a/components/engine/client/volume_inspect_test.go +++ b/components/engine/client/volume_inspect_test.go @@ -11,9 +11,9 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -32,7 +32,7 @@ func TestVolumeInspectNotFound(t *testing.T) { } _, err := client.VolumeInspect(context.Background(), "unknown") - assert.True(t, IsErrNotFound(err)) + assert.Check(t, IsErrNotFound(err)) } func TestVolumeInspectWithEmptyID(t *testing.T) { @@ -75,6 +75,6 @@ func TestVolumeInspect(t *testing.T) { } volume, err := client.VolumeInspect(context.Background(), "volume_id") - require.NoError(t, err) - assert.Equal(t, expected, volume) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(expected, volume)) } diff --git a/components/engine/cmd/dockerd/config_unix_test.go b/components/engine/cmd/dockerd/config_unix_test.go index 2705d671ba..eaa53d8f6f 100644 --- a/components/engine/cmd/dockerd/config_unix_test.go +++ b/components/engine/cmd/dockerd/config_unix_test.go @@ -6,8 +6,9 @@ import ( "testing" "github.com/docker/docker/daemon/config" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" ) func TestDaemonParseShmSize(t *testing.T) { @@ -16,7 +17,7 @@ func TestDaemonParseShmSize(t *testing.T) { conf := &config.Config{} installConfigFlags(conf, flags) // By default `--default-shm-size=64M` - assert.Equal(t, int64(64*1024*1024), conf.ShmSize.Value()) - assert.NoError(t, flags.Set("default-shm-size", "128M")) - assert.Equal(t, int64(128*1024*1024), conf.ShmSize.Value()) + assert.Check(t, is.Equal(int64(64*1024*1024), conf.ShmSize.Value())) + assert.Check(t, flags.Set("default-shm-size", "128M")) + assert.Check(t, is.Equal(int64(128*1024*1024), conf.ShmSize.Value())) } diff --git a/components/engine/cmd/dockerd/daemon_test.go b/components/engine/cmd/dockerd/daemon_test.go index b065831871..e5c2c2ec7c 100644 --- a/components/engine/cmd/dockerd/daemon_test.go +++ b/components/engine/cmd/dockerd/daemon_test.go @@ -5,11 +5,11 @@ import ( "github.com/docker/docker/daemon/config" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" "github.com/sirupsen/logrus" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func defaultOptions(configFile string) *daemonOptions { @@ -27,8 +27,8 @@ func TestLoadDaemonCliConfigWithoutOverriding(t *testing.T) { opts.Debug = true loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) if !loadedConfig.Debug { t.Fatalf("expected debug to be copied from the common flags, got false") } @@ -40,9 +40,9 @@ func TestLoadDaemonCliConfigWithTLS(t *testing.T) { opts.TLS = true loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.Equal(t, "/tmp/ca.pem", loadedConfig.CommonTLSOptions.CAFile) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, is.Equal("/tmp/ca.pem", loadedConfig.CommonTLSOptions.CAFile)) } func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { @@ -53,9 +53,9 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { opts := defaultOptions(configFile) flags := opts.flags - assert.NoError(t, flags.Set("config-file", configFile)) - assert.NoError(t, flags.Set("label", "l1=bar")) - assert.NoError(t, flags.Set("label", "l2=baz")) + assert.Check(t, flags.Set("config-file", configFile)) + assert.Check(t, flags.Set("label", "l1=bar")) + assert.Check(t, flags.Set("label", "l2=baz")) _, err := loadDaemonCliConfig(opts) testutil.ErrorContains(t, err, "as a flag and in the configuration file: labels") @@ -69,9 +69,9 @@ func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) { opts := defaultOptions(configFile) flags := opts.flags - assert.NoError(t, flags.Set("config-file", configFile)) - assert.NoError(t, flags.Set("node-generic-resource", "r1=bar")) - assert.NoError(t, flags.Set("node-generic-resource", "r2=baz")) + assert.Check(t, flags.Set("config-file", configFile)) + assert.Check(t, flags.Set("node-generic-resource", "r1=bar")) + assert.Check(t, flags.Set("node-generic-resource", "r2=baz")) _, err := loadDaemonCliConfig(opts) testutil.ErrorContains(t, err, "as a flag and in the configuration file: node-generic-resources") @@ -81,22 +81,22 @@ func TestLoadDaemonCliWithConflictingLabels(t *testing.T) { opts := defaultOptions("") flags := opts.flags - assert.NoError(t, flags.Set("label", "foo=bar")) - assert.NoError(t, flags.Set("label", "foo=baz")) + assert.Check(t, flags.Set("label", "foo=bar")) + assert.Check(t, flags.Set("label", "foo=baz")) _, err := loadDaemonCliConfig(opts) - assert.EqualError(t, err, "conflict labels for foo=baz and foo=bar") + assert.Check(t, is.Error(err, "conflict labels for foo=baz and foo=bar")) } func TestLoadDaemonCliWithDuplicateLabels(t *testing.T) { opts := defaultOptions("") flags := opts.flags - assert.NoError(t, flags.Set("label", "foo=the-same")) - assert.NoError(t, flags.Set("label", "foo=the-same")) + assert.Check(t, flags.Set("label", "foo=the-same")) + assert.Check(t, flags.Set("label", "foo=the-same")) _, err := loadDaemonCliConfig(opts) - assert.NoError(t, err) + assert.Check(t, err) } func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) { @@ -107,9 +107,9 @@ func TestLoadDaemonCliConfigWithTLSVerify(t *testing.T) { opts.TLSOptions.CAFile = "/tmp/ca.pem" loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.Equal(t, loadedConfig.TLS, true) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, is.Equal(loadedConfig.TLS, true)) } func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) { @@ -120,9 +120,9 @@ func TestLoadDaemonCliConfigWithExplicitTLSVerifyFalse(t *testing.T) { opts.TLSOptions.CAFile = "/tmp/ca.pem" loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.True(t, loadedConfig.TLS) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, loadedConfig.TLS) } func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) { @@ -133,9 +133,9 @@ func TestLoadDaemonCliConfigWithoutTLSVerify(t *testing.T) { opts.TLSOptions.CAFile = "/tmp/ca.pem" loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.False(t, loadedConfig.TLS) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, !loadedConfig.TLS) } func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) { @@ -144,10 +144,10 @@ func TestLoadDaemonCliConfigWithLogLevel(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.Equal(t, "warn", loadedConfig.LogLevel) - assert.Equal(t, logrus.WarnLevel, logrus.GetLevel()) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, is.Equal("warn", loadedConfig.LogLevel)) + assert.Check(t, is.Equal(logrus.WarnLevel, logrus.GetLevel())) } func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) { @@ -157,10 +157,10 @@ func TestLoadDaemonConfigWithEmbeddedOptions(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.Equal(t, "/etc/certs/ca.pem", loadedConfig.CommonTLSOptions.CAFile) - assert.Equal(t, "syslog", loadedConfig.LogConfig.Type) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, is.Equal("/etc/certs/ca.pem", loadedConfig.CommonTLSOptions.CAFile)) + assert.Check(t, is.Equal("syslog", loadedConfig.LogConfig.Type)) } func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) { @@ -174,10 +174,10 @@ func TestLoadDaemonConfigWithRegistryOptions(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) - assert.Len(t, loadedConfig.AllowNondistributableArtifacts, 1) - assert.Len(t, loadedConfig.Mirrors, 1) - assert.Len(t, loadedConfig.InsecureRegistries, 1) + assert.Check(t, is.Len(loadedConfig.AllowNondistributableArtifacts, 1)) + assert.Check(t, is.Len(loadedConfig.Mirrors, 1)) + assert.Check(t, is.Len(loadedConfig.InsecureRegistries, 1)) } diff --git a/components/engine/cmd/dockerd/daemon_unix_test.go b/components/engine/cmd/dockerd/daemon_unix_test.go index 41c392e1b1..39ff1e6822 100644 --- a/components/engine/cmd/dockerd/daemon_unix_test.go +++ b/components/engine/cmd/dockerd/daemon_unix_test.go @@ -6,9 +6,9 @@ import ( "testing" "github.com/docker/docker/daemon/config" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) { @@ -19,17 +19,17 @@ func TestLoadDaemonCliConfigWithDaemonFlags(t *testing.T) { opts := defaultOptions(tempFile.Path()) opts.Debug = true opts.LogLevel = "info" - assert.NoError(t, opts.flags.Set("selinux-enabled", "true")) + assert.Check(t, opts.flags.Set("selinux-enabled", "true")) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) - assert.True(t, loadedConfig.Debug) - assert.Equal(t, "info", loadedConfig.LogLevel) - assert.True(t, loadedConfig.EnableSelinuxSupport) - assert.Equal(t, "json-file", loadedConfig.LogConfig.Type) - assert.Equal(t, "1k", loadedConfig.LogConfig.Config["max-size"]) + assert.Check(t, loadedConfig.Debug) + assert.Check(t, is.Equal("info", loadedConfig.LogLevel)) + assert.Check(t, loadedConfig.EnableSelinuxSupport) + assert.Check(t, is.Equal("json-file", loadedConfig.LogConfig.Type)) + assert.Check(t, is.Equal("1k", loadedConfig.LogConfig.Config["max-size"])) } func TestLoadDaemonConfigWithNetwork(t *testing.T) { @@ -39,11 +39,11 @@ func TestLoadDaemonConfigWithNetwork(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) - assert.Equal(t, "127.0.0.2", loadedConfig.IP) - assert.Equal(t, "127.0.0.1", loadedConfig.DefaultIP.String()) + assert.Check(t, is.Equal("127.0.0.2", loadedConfig.IP)) + assert.Check(t, is.Equal("127.0.0.1", loadedConfig.DefaultIP.String())) } func TestLoadDaemonConfigWithMapOptions(t *testing.T) { @@ -56,14 +56,14 @@ func TestLoadDaemonConfigWithMapOptions(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) - assert.NotNil(t, loadedConfig.ClusterOpts) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) + assert.Check(t, loadedConfig.ClusterOpts != nil) expectedPath := "/var/lib/docker/discovery_certs/ca.pem" - assert.Equal(t, expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"]) - assert.NotNil(t, loadedConfig.LogConfig.Config) - assert.Equal(t, "test", loadedConfig.LogConfig.Config["tag"]) + assert.Check(t, is.Equal(expectedPath, loadedConfig.ClusterOpts["kv.cacertfile"])) + assert.Check(t, loadedConfig.LogConfig.Config != nil) + assert.Check(t, is.Equal("test", loadedConfig.LogConfig.Config["tag"])) } func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) { @@ -73,17 +73,17 @@ func TestLoadDaemonConfigWithTrueDefaultValues(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) - assert.False(t, loadedConfig.EnableUserlandProxy) + assert.Check(t, !loadedConfig.EnableUserlandProxy) // make sure reloading doesn't generate configuration // conflicts after normalizing boolean values. reload := func(reloadedConfig *config.Config) { - assert.False(t, reloadedConfig.EnableUserlandProxy) + assert.Check(t, !reloadedConfig.EnableUserlandProxy) } - assert.NoError(t, config.Reload(opts.configFile, opts.flags, reload)) + assert.Check(t, config.Reload(opts.configFile, opts.flags, reload)) } func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { @@ -92,8 +92,8 @@ func TestLoadDaemonConfigWithTrueDefaultValuesLeaveDefaults(t *testing.T) { opts := defaultOptions(tempFile.Path()) loadedConfig, err := loadDaemonCliConfig(opts) - require.NoError(t, err) - require.NotNil(t, loadedConfig) + assert.NilError(t, err) + assert.Assert(t, loadedConfig != nil) - assert.True(t, loadedConfig.EnableUserlandProxy) + assert.Check(t, loadedConfig.EnableUserlandProxy) } diff --git a/components/engine/cmd/dockerd/options_test.go b/components/engine/cmd/dockerd/options_test.go index c3298a0ac6..2a4e63b6b6 100644 --- a/components/engine/cmd/dockerd/options_test.go +++ b/components/engine/cmd/dockerd/options_test.go @@ -6,8 +6,9 @@ import ( cliconfig "github.com/docker/docker/cli/config" "github.com/docker/docker/daemon/config" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" ) func TestCommonOptionsInstallFlags(t *testing.T) { @@ -20,10 +21,10 @@ func TestCommonOptionsInstallFlags(t *testing.T) { "--tlscert=\"/foo/cert\"", "--tlskey=\"/foo/key\"", }) - assert.NoError(t, err) - assert.Equal(t, "/foo/cafile", opts.TLSOptions.CAFile) - assert.Equal(t, "/foo/cert", opts.TLSOptions.CertFile) - assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key") + assert.Check(t, err) + assert.Check(t, is.Equal("/foo/cafile", opts.TLSOptions.CAFile)) + assert.Check(t, is.Equal("/foo/cert", opts.TLSOptions.CertFile)) + assert.Check(t, is.Equal(opts.TLSOptions.KeyFile, "/foo/key")) } func defaultPath(filename string) string { @@ -36,8 +37,8 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) { opts.InstallFlags(flags) err := flags.Parse([]string{}) - assert.NoError(t, err) - assert.Equal(t, defaultPath("ca.pem"), opts.TLSOptions.CAFile) - assert.Equal(t, defaultPath("cert.pem"), opts.TLSOptions.CertFile) - assert.Equal(t, defaultPath("key.pem"), opts.TLSOptions.KeyFile) + assert.Check(t, err) + assert.Check(t, is.Equal(defaultPath("ca.pem"), opts.TLSOptions.CAFile)) + assert.Check(t, is.Equal(defaultPath("cert.pem"), opts.TLSOptions.CertFile)) + assert.Check(t, is.Equal(defaultPath("key.pem"), opts.TLSOptions.KeyFile)) } diff --git a/components/engine/container/container_unit_test.go b/components/engine/container/container_unit_test.go index 863a47a1f2..bf45df942e 100644 --- a/components/engine/container/container_unit_test.go +++ b/components/engine/container/container_unit_test.go @@ -11,7 +11,7 @@ import ( swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/daemon/logger/jsonfilelog" "github.com/docker/docker/pkg/signal" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestContainerStopSignal(t *testing.T) { @@ -74,7 +74,7 @@ func TestContainerSecretReferenceDestTarget(t *testing.T) { func TestContainerLogPathSetForJSONFileLogger(t *testing.T) { containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForJSONFileLogger") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(containerRoot) c := &Container{ @@ -89,17 +89,17 @@ func TestContainerLogPathSetForJSONFileLogger(t *testing.T) { } logger, err := c.StartLogger() - require.NoError(t, err) + assert.NilError(t, err) defer logger.Close() expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID))) - require.NoError(t, err) - require.Equal(t, c.LogPath, expectedLogPath) + assert.NilError(t, err) + assert.Equal(t, c.LogPath, expectedLogPath) } func TestContainerLogPathSetForRingLogger(t *testing.T) { containerRoot, err := ioutil.TempDir("", "TestContainerLogPathSetForRingLogger") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(containerRoot) c := &Container{ @@ -117,10 +117,10 @@ func TestContainerLogPathSetForRingLogger(t *testing.T) { } logger, err := c.StartLogger() - require.NoError(t, err) + assert.NilError(t, err) defer logger.Close() expectedLogPath, err := filepath.Abs(filepath.Join(containerRoot, fmt.Sprintf("%s-json.log", c.ID))) - require.NoError(t, err) - require.Equal(t, c.LogPath, expectedLogPath) + assert.NilError(t, err) + assert.Equal(t, c.LogPath, expectedLogPath) } diff --git a/components/engine/container/view_test.go b/components/engine/container/view_test.go index 26803b04e6..a872dffea6 100644 --- a/components/engine/container/view_test.go +++ b/components/engine/container/view_test.go @@ -8,8 +8,9 @@ import ( "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pborman/uuid" - "github.com/stretchr/testify/assert" ) var root string @@ -109,56 +110,56 @@ func TestNames(t *testing.T) { if err != nil { t.Fatal(err) } - assert.NoError(t, db.ReserveName("name1", "containerid1")) - assert.NoError(t, db.ReserveName("name1", "containerid1")) // idempotent - assert.NoError(t, db.ReserveName("name2", "containerid2")) - assert.EqualError(t, db.ReserveName("name2", "containerid3"), ErrNameReserved.Error()) + assert.Check(t, db.ReserveName("name1", "containerid1")) + assert.Check(t, db.ReserveName("name1", "containerid1")) // idempotent + assert.Check(t, db.ReserveName("name2", "containerid2")) + assert.Check(t, is.Error(db.ReserveName("name2", "containerid3"), ErrNameReserved.Error())) // Releasing a name allows the name to point to something else later. - assert.NoError(t, db.ReleaseName("name2")) - assert.NoError(t, db.ReserveName("name2", "containerid3")) + assert.Check(t, db.ReleaseName("name2")) + assert.Check(t, db.ReserveName("name2", "containerid3")) view := db.Snapshot() id, err := view.GetID("name1") - assert.NoError(t, err) - assert.Equal(t, "containerid1", id) + assert.Check(t, err) + assert.Check(t, is.Equal("containerid1", id)) id, err = view.GetID("name2") - assert.NoError(t, err) - assert.Equal(t, "containerid3", id) + assert.Check(t, err) + assert.Check(t, is.Equal("containerid3", id)) _, err = view.GetID("notreserved") - assert.EqualError(t, err, ErrNameNotReserved.Error()) + assert.Check(t, is.Error(err, ErrNameNotReserved.Error())) // Releasing and re-reserving a name doesn't affect the snapshot. - assert.NoError(t, db.ReleaseName("name2")) - assert.NoError(t, db.ReserveName("name2", "containerid4")) + assert.Check(t, db.ReleaseName("name2")) + assert.Check(t, db.ReserveName("name2", "containerid4")) id, err = view.GetID("name1") - assert.NoError(t, err) - assert.Equal(t, "containerid1", id) + assert.Check(t, err) + assert.Check(t, is.Equal("containerid1", id)) id, err = view.GetID("name2") - assert.NoError(t, err) - assert.Equal(t, "containerid3", id) + assert.Check(t, err) + assert.Check(t, is.Equal("containerid3", id)) // GetAllNames - assert.Equal(t, map[string][]string{"containerid1": {"name1"}, "containerid3": {"name2"}}, view.GetAllNames()) + assert.Check(t, is.DeepEqual(map[string][]string{"containerid1": {"name1"}, "containerid3": {"name2"}}, view.GetAllNames())) - assert.NoError(t, db.ReserveName("name3", "containerid1")) - assert.NoError(t, db.ReserveName("name4", "containerid1")) + assert.Check(t, db.ReserveName("name3", "containerid1")) + assert.Check(t, db.ReserveName("name4", "containerid1")) view = db.Snapshot() - assert.Equal(t, map[string][]string{"containerid1": {"name1", "name3", "name4"}, "containerid4": {"name2"}}, view.GetAllNames()) + assert.Check(t, is.DeepEqual(map[string][]string{"containerid1": {"name1", "name3", "name4"}, "containerid4": {"name2"}}, view.GetAllNames())) // Release containerid1's names with Delete even though no container exists - assert.NoError(t, db.Delete(&Container{ID: "containerid1"})) + assert.Check(t, db.Delete(&Container{ID: "containerid1"})) // Reusing one of those names should work - assert.NoError(t, db.ReserveName("name1", "containerid4")) + assert.Check(t, db.ReserveName("name1", "containerid4")) view = db.Snapshot() - assert.Equal(t, map[string][]string{"containerid4": {"name1", "name2"}}, view.GetAllNames()) + assert.Check(t, is.DeepEqual(map[string][]string{"containerid4": {"name1", "name2"}}, view.GetAllNames())) } // Test case for GitHub issue 35920 diff --git a/components/engine/daemon/cluster/convert/service_test.go b/components/engine/daemon/cluster/convert/service_test.go index 347aa028be..0794af99a6 100644 --- a/components/engine/daemon/cluster/convert/service_test.go +++ b/components/engine/daemon/cluster/convert/service_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/docker/api/types/swarm/runtime" swarmapi "github.com/docker/swarmkit/api" google_protobuf3 "github.com/gogo/protobuf/types" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestServiceConvertFromGRPCRuntimeContainer(t *testing.T) { @@ -178,12 +178,12 @@ func TestServiceConvertToGRPCIsolation(t *testing.T) { }, } res, err := ServiceSpecToGRPC(s) - require.NoError(t, err) + assert.NilError(t, err) v, ok := res.Task.Runtime.(*swarmapi.TaskSpec_Container) if !ok { t.Fatal("expected type swarmapi.TaskSpec_Container") } - require.Equal(t, c.to, v.Container.Isolation) + assert.Equal(t, c.to, v.Container.Isolation) }) } } @@ -228,7 +228,7 @@ func TestServiceConvertFromGRPCIsolation(t *testing.T) { t.Fatal(err) } - require.Equal(t, c.to, svc.Spec.TaskTemplate.ContainerSpec.Isolation) + assert.Equal(t, c.to, svc.Spec.TaskTemplate.ContainerSpec.Isolation) }) } } diff --git a/components/engine/daemon/cluster/executor/container/container_test.go b/components/engine/daemon/cluster/executor/container/container_test.go index 456cd403b1..1e94171974 100644 --- a/components/engine/daemon/cluster/executor/container/container_test.go +++ b/components/engine/daemon/cluster/executor/container/container_test.go @@ -5,7 +5,7 @@ import ( container "github.com/docker/docker/api/types/container" swarmapi "github.com/docker/swarmkit/api" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestIsolationConversion(t *testing.T) { @@ -31,7 +31,7 @@ func TestIsolationConversion(t *testing.T) { }, } config := containerConfig{task: &task} - require.Equal(t, c.to, config.hostConfig().Isolation) + assert.Equal(t, c.to, config.hostConfig().Isolation) }) } } diff --git a/components/engine/daemon/config/config_test.go b/components/engine/daemon/config/config_test.go index 53db2922cb..2fe2b3805c 100644 --- a/components/engine/daemon/config/config_test.go +++ b/components/engine/daemon/config/config_test.go @@ -9,9 +9,10 @@ import ( "github.com/docker/docker/daemon/discovery" "github.com/docker/docker/internal/testutil" "github.com/docker/docker/opts" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" ) func TestDaemonConfigurationNotFound(t *testing.T) { @@ -59,7 +60,7 @@ func TestFindConfigurationConflicts(t *testing.T) { flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.String("authorization-plugins", "", "") - assert.NoError(t, flags.Set("authorization-plugins", "asdf")) + assert.Check(t, flags.Set("authorization-plugins", "asdf")) testutil.ErrorContains(t, findConfigurationConflicts(config, flags), @@ -72,8 +73,8 @@ func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) { var hosts []string flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to") - assert.NoError(t, flags.Set("host", "tcp://127.0.0.1:4444")) - assert.NoError(t, flags.Set("host", "unix:///var/run/docker.sock")) + assert.Check(t, flags.Set("host", "tcp://127.0.0.1:4444")) + assert.Check(t, flags.Set("host", "unix:///var/run/docker.sock")) testutil.ErrorContains(t, findConfigurationConflicts(config, flags), "hosts") } @@ -424,7 +425,7 @@ func TestReloadSetConfigFileNotExist(t *testing.T) { flags.Set("config-file", configFile) err := Reload(configFile, flags, func(c *Config) {}) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) testutil.ErrorContains(t, err, "unable to configure the Docker daemon with file") } @@ -438,8 +439,8 @@ func TestReloadDefaultConfigNotExist(t *testing.T) { err := Reload(configFile, flags, func(c *Config) { reloaded = true }) - assert.Nil(t, err) - assert.True(t, reloaded) + assert.Check(t, err) + assert.Check(t, reloaded) } // TestReloadBadDefaultConfig tests that when `--config-file` is not set @@ -457,7 +458,7 @@ func TestReloadBadDefaultConfig(t *testing.T) { flags := pflag.NewFlagSet("test", pflag.ContinueOnError) flags.String("config-file", configFile, "") err = Reload(configFile, flags, func(c *Config) {}) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) testutil.ErrorContains(t, err, "unable to configure the Docker daemon with file") } @@ -484,5 +485,5 @@ func TestReloadWithDuplicateLabels(t *testing.T) { flags.String("config-file", configFile, "") flags.StringSlice("labels", lbls, "") err := Reload(configFile, flags, func(c *Config) {}) - assert.NoError(t, err) + assert.Check(t, err) } diff --git a/components/engine/daemon/config/config_unix_test.go b/components/engine/daemon/config/config_unix_test.go index b4efa95e0e..53eb428264 100644 --- a/components/engine/daemon/config/config_unix_test.go +++ b/components/engine/daemon/config/config_unix_test.go @@ -7,10 +7,10 @@ import ( "github.com/docker/docker/opts" units "github.com/docker/go-units" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestGetConflictFreeConfiguration(t *testing.T) { @@ -39,9 +39,9 @@ func TestGetConflictFreeConfiguration(t *testing.T) { flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "") cc, err := getConflictFreeConfiguration(file.Path(), flags) - require.NoError(t, err) + assert.NilError(t, err) - assert.True(t, cc.Debug) + assert.Check(t, cc.Debug) expectedUlimits := map[string]*units.Ulimit{ "nofile": { @@ -51,7 +51,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) { }, } - assert.Equal(t, expectedUlimits, cc.Ulimits) + assert.Check(t, is.DeepEqual(expectedUlimits, cc.Ulimits)) } func TestDaemonConfigurationMerge(t *testing.T) { @@ -91,17 +91,17 @@ func TestDaemonConfigurationMerge(t *testing.T) { flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "") cc, err := MergeDaemonConfigurations(c, flags, file.Path()) - require.NoError(t, err) + assert.NilError(t, err) - assert.True(t, cc.Debug) - assert.True(t, cc.AutoRestart) + assert.Check(t, cc.Debug) + assert.Check(t, cc.AutoRestart) expectedLogConfig := LogConfig{ Type: "syslog", Config: map[string]string{"tag": "test_tag"}, } - assert.Equal(t, expectedLogConfig, cc.LogConfig) + assert.Check(t, is.DeepEqual(expectedLogConfig, cc.LogConfig)) expectedUlimits := map[string]*units.Ulimit{ "nofile": { @@ -111,7 +111,7 @@ func TestDaemonConfigurationMerge(t *testing.T) { }, } - assert.Equal(t, expectedUlimits, cc.Ulimits) + assert.Check(t, is.DeepEqual(expectedUlimits, cc.Ulimits)) } func TestDaemonConfigurationMergeShmSize(t *testing.T) { @@ -127,8 +127,8 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) { flags.Var(&shmSize, "default-shm-size", "") cc, err := MergeDaemonConfigurations(c, flags, file.Path()) - require.NoError(t, err) + assert.NilError(t, err) expectedValue := 1 * 1024 * 1024 * 1024 - assert.Equal(t, int64(expectedValue), cc.ShmSize.Value()) + assert.Check(t, is.Equal(int64(expectedValue), cc.ShmSize.Value())) } diff --git a/components/engine/daemon/config/config_windows_test.go b/components/engine/daemon/config/config_windows_test.go index 5382bb3b77..fff98014f9 100644 --- a/components/engine/daemon/config/config_windows_test.go +++ b/components/engine/daemon/config/config_windows_test.go @@ -7,9 +7,9 @@ import ( "testing" "github.com/docker/docker/opts" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/spf13/pflag" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestDaemonConfigurationMerge(t *testing.T) { @@ -46,15 +46,15 @@ func TestDaemonConfigurationMerge(t *testing.T) { flags.Var(opts.NewNamedMapOpts("log-opts", nil, nil), "log-opt", "") cc, err := MergeDaemonConfigurations(c, flags, configFile) - require.NoError(t, err) + assert.NilError(t, err) - assert.True(t, cc.Debug) - assert.True(t, cc.AutoRestart) + assert.Check(t, cc.Debug) + assert.Check(t, cc.AutoRestart) expectedLogConfig := LogConfig{ Type: "syslog", Config: map[string]string{"tag": "test_tag"}, } - assert.Equal(t, expectedLogConfig, cc.LogConfig) + assert.Check(t, is.DeepEqual(expectedLogConfig, cc.LogConfig)) } diff --git a/components/engine/daemon/container_unix_test.go b/components/engine/daemon/container_unix_test.go index e102be6cdc..12075f8b8d 100644 --- a/components/engine/daemon/container_unix_test.go +++ b/components/engine/daemon/container_unix_test.go @@ -9,7 +9,7 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/daemon/config" "github.com/docker/go-connections/nat" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) // TestContainerWarningHostAndPublishPorts that a warning is returned when setting network mode to host and specifying published ports. @@ -38,7 +38,7 @@ func TestContainerWarningHostAndPublishPorts(t *testing.T) { } d := &Daemon{configStore: cs} wrns, err := d.verifyContainerSettings("", hostConfig, &containertypes.Config{}, false) - require.NoError(t, err) - require.Equal(t, tc.warnings, wrns) + assert.NilError(t, err) + assert.DeepEqual(t, tc.warnings, wrns) } } diff --git a/components/engine/daemon/create_test.go b/components/engine/daemon/create_test.go index 3e355f6473..7ef49d7623 100644 --- a/components/engine/daemon/create_test.go +++ b/components/engine/daemon/create_test.go @@ -5,7 +5,7 @@ import ( "github.com/docker/docker/api/types/network" "github.com/docker/docker/errdefs" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" ) // Test case for 35752 @@ -17,5 +17,5 @@ func TestVerifyNetworkingConfig(t *testing.T) { EndpointsConfig: endpoints, } err := verifyNetworkingConfig(nwConfig) - assert.True(t, errdefs.IsInvalidParameter(err)) + assert.Check(t, errdefs.IsInvalidParameter(err)) } diff --git a/components/engine/daemon/daemon_linux_test.go b/components/engine/daemon/daemon_linux_test.go index ad651e3e1c..195afb1e0f 100644 --- a/components/engine/daemon/daemon_linux_test.go +++ b/components/engine/daemon/daemon_linux_test.go @@ -11,8 +11,8 @@ import ( "github.com/docker/docker/oci" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/mount" - - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) const mountsFixture = `142 78 0:38 / / rw,relatime - aufs none rw,si=573b861da0b3a05b,dio @@ -138,7 +138,7 @@ func TestTmpfsDevShmSizeOverride(t *testing.T) { // convert ms to spec spec := oci.DefaultSpec() err := setMounts(&d, &spec, c, ms) - assert.NoError(t, err) + assert.Check(t, err) // Check the resulting spec for the correct size found := false @@ -149,7 +149,7 @@ func TestTmpfsDevShmSizeOverride(t *testing.T) { continue } t.Logf("%+v\n", m.Options) - assert.Equal(t, "size="+size, o) + assert.Check(t, is.Equal("size="+size, o)) found = true } } @@ -163,7 +163,7 @@ func TestValidateContainerIsolationLinux(t *testing.T) { d := Daemon{} _, err := d.verifyContainerSettings("linux", &containertypes.HostConfig{Isolation: containertypes.IsolationHyperV}, nil, false) - assert.EqualError(t, err, "invalid isolation 'hyperv' on linux") + assert.Check(t, is.Error(err, "invalid isolation 'hyperv' on linux")) } func TestShouldUnmountRoot(t *testing.T) { @@ -222,7 +222,7 @@ func TestShouldUnmountRoot(t *testing.T) { if test.info != nil { test.info.Optional = options.Optional } - assert.Equal(t, expect, shouldUnmountRoot(test.root, test.info)) + assert.Check(t, is.Equal(expect, shouldUnmountRoot(test.root, test.info))) }) } }) diff --git a/components/engine/daemon/daemon_test.go b/components/engine/daemon/daemon_test.go index 5d40e11143..2fb4ff902a 100644 --- a/components/engine/daemon/daemon_test.go +++ b/components/engine/daemon/daemon_test.go @@ -19,8 +19,9 @@ import ( "github.com/docker/docker/volume/store" "github.com/docker/go-connections/nat" "github.com/docker/libnetwork" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" ) // @@ -312,7 +313,7 @@ func TestValidateContainerIsolation(t *testing.T) { d := Daemon{} _, err := d.verifyContainerSettings(runtime.GOOS, &containertypes.HostConfig{Isolation: containertypes.Isolation("invalid")}, nil, false) - assert.EqualError(t, err, "invalid isolation 'invalid' on "+runtime.GOOS) + assert.Check(t, is.Error(err, "invalid isolation 'invalid' on "+runtime.GOOS)) } func TestFindNetworkErrorType(t *testing.T) { @@ -320,6 +321,6 @@ func TestFindNetworkErrorType(t *testing.T) { _, err := d.FindNetwork("fakeNet") _, ok := errors.Cause(err).(libnetwork.ErrNoSuchNetwork) if !errdefs.IsNotFound(err) || !ok { - assert.Fail(t, "The FindNetwork method MUST always return an error that implements the NotFound interface and is ErrNoSuchNetwork") + t.Error("The FindNetwork method MUST always return an error that implements the NotFound interface and is ErrNoSuchNetwork") } } diff --git a/components/engine/daemon/daemon_unix_test.go b/components/engine/daemon/daemon_unix_test.go index cd88b38335..84281c0b8c 100644 --- a/components/engine/daemon/daemon_unix_test.go +++ b/components/engine/daemon/daemon_unix_test.go @@ -17,7 +17,7 @@ import ( "github.com/docker/docker/volume/drivers" "github.com/docker/docker/volume/local" "github.com/docker/docker/volume/store" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) type fakeContainerGetter struct { @@ -290,12 +290,12 @@ func TestMigratePre17Volumes(t *testing.T) { containerRoot := filepath.Join(rootDir, "containers") cid := "1234" err = os.MkdirAll(filepath.Join(containerRoot, cid), 0755) - require.NoError(t, err) + assert.NilError(t, err) vid := "5678" vfsPath := filepath.Join(rootDir, "vfs", "dir", vid) err = os.MkdirAll(vfsPath, 0755) - require.NoError(t, err) + assert.NilError(t, err) config := []byte(` { diff --git a/components/engine/daemon/delete_test.go b/components/engine/daemon/delete_test.go index 48a8afec48..8bfa5d8170 100644 --- a/components/engine/daemon/delete_test.go +++ b/components/engine/daemon/delete_test.go @@ -10,12 +10,12 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func newDaemonWithTmpRoot(t *testing.T) (*Daemon, func()) { tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-") - require.NoError(t, err) + assert.NilError(t, err) d := &Daemon{ repository: tmp, root: tmp, diff --git a/components/engine/daemon/discovery/discovery_test.go b/components/engine/daemon/discovery/discovery_test.go index 4560af2878..d00e02e10b 100644 --- a/components/engine/daemon/discovery/discovery_test.go +++ b/components/engine/daemon/discovery/discovery_test.go @@ -5,8 +5,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestDiscoveryOptsErrors(t *testing.T) { @@ -42,26 +42,26 @@ func TestDiscoveryOptsErrors(t *testing.T) { for _, testcase := range testcases { _, _, err := discoveryOpts(testcase.opts) - assert.Error(t, err, testcase.doc) + assert.Check(t, is.ErrorContains(err, ""), testcase.doc) } } func TestDiscoveryOpts(t *testing.T) { clusterOpts := map[string]string{"discovery.heartbeat": "10", "discovery.ttl": "20"} heartbeat, ttl, err := discoveryOpts(clusterOpts) - require.NoError(t, err) - assert.Equal(t, 10*time.Second, heartbeat) - assert.Equal(t, 20*time.Second, ttl) + assert.NilError(t, err) + assert.Check(t, is.Equal(10*time.Second, heartbeat)) + assert.Check(t, is.Equal(20*time.Second, ttl)) clusterOpts = map[string]string{"discovery.heartbeat": "10"} heartbeat, ttl, err = discoveryOpts(clusterOpts) - require.NoError(t, err) - assert.Equal(t, 10*time.Second, heartbeat) - assert.Equal(t, 10*defaultDiscoveryTTLFactor*time.Second, ttl) + assert.NilError(t, err) + assert.Check(t, is.Equal(10*time.Second, heartbeat)) + assert.Check(t, is.Equal(10*defaultDiscoveryTTLFactor*time.Second, ttl)) clusterOpts = map[string]string{"discovery.ttl": "30"} heartbeat, ttl, err = discoveryOpts(clusterOpts) - require.NoError(t, err) + assert.NilError(t, err) if ttl != 30*time.Second { t.Fatalf("TTL - Expected : %v, Actual : %v", 30*time.Second, ttl) diff --git a/components/engine/daemon/graphdriver/aufs/aufs_test.go b/components/engine/daemon/graphdriver/aufs/aufs_test.go index d0641abe35..2338ad320d 100644 --- a/components/engine/daemon/graphdriver/aufs/aufs_test.go +++ b/components/engine/daemon/graphdriver/aufs/aufs_test.go @@ -17,8 +17,8 @@ import ( "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/stringid" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) var ( @@ -189,7 +189,7 @@ func TestCleanupWithNoDirs(t *testing.T) { defer os.RemoveAll(tmp) err := d.Cleanup() - assert.NoError(t, err) + assert.Check(t, err) } func TestCleanupWithDir(t *testing.T) { @@ -210,11 +210,11 @@ func TestMountedFalseResponse(t *testing.T) { defer os.RemoveAll(tmp) err := d.Create("1", "", nil) - require.NoError(t, err) + assert.NilError(t, err) response, err := d.mounted(d.getDiffPath("1")) - require.NoError(t, err) - assert.False(t, response) + assert.NilError(t, err) + assert.Check(t, !response) } func TestMountedTrueResponse(t *testing.T) { @@ -223,16 +223,16 @@ func TestMountedTrueResponse(t *testing.T) { defer d.Cleanup() err := d.Create("1", "", nil) - require.NoError(t, err) + assert.NilError(t, err) err = d.Create("2", "1", nil) - require.NoError(t, err) + assert.NilError(t, err) _, err = d.Get("2", "") - require.NoError(t, err) + assert.NilError(t, err) response, err := d.mounted(d.pathCache["2"]) - require.NoError(t, err) - assert.True(t, response) + assert.NilError(t, err) + assert.Check(t, response) } func TestMountWithParent(t *testing.T) { @@ -567,7 +567,7 @@ func TestStatus(t *testing.T) { } status := d.Status() - assert.Len(t, status, 4) + assert.Check(t, is.Len(status, 4)) rootDir := status[0] dirs := status[2] @@ -670,18 +670,18 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) { current = hash(current) err := d.CreateReadWrite(current, parent, nil) - require.NoError(t, err, "current layer %d", i) + assert.NilError(t, err, "current layer %d", i) point, err := driverGet(d, current, "") - require.NoError(t, err, "current layer %d", i) + assert.NilError(t, err, "current layer %d", i) f, err := os.Create(path.Join(point, current)) - require.NoError(t, err, "current layer %d", i) + assert.NilError(t, err, "current layer %d", i) f.Close() if i%10 == 0 { err := os.Remove(path.Join(point, parent)) - require.NoError(t, err, "current layer %d", i) + assert.NilError(t, err, "current layer %d", i) expected-- } last = current @@ -689,10 +689,10 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) { // Perform the actual mount for the top most image point, err := driverGet(d, last, "") - require.NoError(t, err) + assert.NilError(t, err) files, err := ioutil.ReadDir(point) - require.NoError(t, err) - assert.Len(t, files, expected) + assert.NilError(t, err) + assert.Check(t, is.Len(files, expected)) } func TestMountMoreThan42Layers(t *testing.T) { diff --git a/components/engine/daemon/graphdriver/copy/copy_test.go b/components/engine/daemon/graphdriver/copy/copy_test.go index 6d4387c94e..a09bb2637e 100644 --- a/components/engine/daemon/graphdriver/copy/copy_test.go +++ b/components/engine/daemon/graphdriver/copy/copy_test.go @@ -14,8 +14,8 @@ import ( "github.com/docker/docker/pkg/parsers/kernel" "github.com/docker/docker/pkg/system" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/sys/unix" ) @@ -24,16 +24,16 @@ func TestIsCopyFileRangeSyscallAvailable(t *testing.T) { // 1. That copyFileRangeEnabled is being set to true when copy_file_range syscall is available // 2. That isCopyFileRangeSyscallAvailable() works on "new" kernels v, err := kernel.GetKernelVersion() - require.NoError(t, err) + assert.NilError(t, err) copyWithFileRange := true copyWithFileClone := false doCopyTest(t, ©WithFileRange, ©WithFileClone) if kernel.CompareKernelVersion(*v, kernel.VersionInfo{Kernel: 4, Major: 5, Minor: 0}) < 0 { - assert.False(t, copyWithFileRange) + assert.Check(t, !copyWithFileRange) } else { - assert.True(t, copyWithFileRange) + assert.Check(t, copyWithFileRange) } } @@ -52,47 +52,47 @@ func TestCopyWithoutRange(t *testing.T) { func TestCopyDir(t *testing.T) { srcDir, err := ioutil.TempDir("", "srcDir") - require.NoError(t, err) + assert.NilError(t, err) populateSrcDir(t, srcDir, 3) dstDir, err := ioutil.TempDir("", "testdst") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dstDir) - assert.NoError(t, DirCopy(srcDir, dstDir, Content, false)) - require.NoError(t, filepath.Walk(srcDir, func(srcPath string, f os.FileInfo, err error) error { + assert.Check(t, DirCopy(srcDir, dstDir, Content, false)) + assert.NilError(t, filepath.Walk(srcDir, func(srcPath string, f os.FileInfo, err error) error { if err != nil { return err } // Rebase path relPath, err := filepath.Rel(srcDir, srcPath) - require.NoError(t, err) + assert.NilError(t, err) if relPath == "." { return nil } dstPath := filepath.Join(dstDir, relPath) - require.NoError(t, err) + assert.NilError(t, err) // If we add non-regular dirs and files to the test // then we need to add more checks here. dstFileInfo, err := os.Lstat(dstPath) - require.NoError(t, err) + assert.NilError(t, err) srcFileSys := f.Sys().(*syscall.Stat_t) dstFileSys := dstFileInfo.Sys().(*syscall.Stat_t) t.Log(relPath) if srcFileSys.Dev == dstFileSys.Dev { - assert.NotEqual(t, srcFileSys.Ino, dstFileSys.Ino) + assert.Check(t, srcFileSys.Ino != dstFileSys.Ino) } // Todo: check size, and ctim is not equal /// on filesystems that have granular ctimes - assert.Equal(t, srcFileSys.Mode, dstFileSys.Mode) - assert.Equal(t, srcFileSys.Uid, dstFileSys.Uid) - assert.Equal(t, srcFileSys.Gid, dstFileSys.Gid) - assert.Equal(t, srcFileSys.Mtim, dstFileSys.Mtim) + assert.Check(t, is.DeepEqual(srcFileSys.Mode, dstFileSys.Mode)) + assert.Check(t, is.DeepEqual(srcFileSys.Uid, dstFileSys.Uid)) + assert.Check(t, is.DeepEqual(srcFileSys.Gid, dstFileSys.Gid)) + assert.Check(t, is.DeepEqual(srcFileSys.Mtim, dstFileSys.Mtim)) return nil })) @@ -115,22 +115,22 @@ func populateSrcDir(t *testing.T, srcDir string, remainingDepth int) { for i := 0; i < 10; i++ { dirName := filepath.Join(srcDir, fmt.Sprintf("srcdir-%d", i)) // Owner all bits set - require.NoError(t, os.Mkdir(dirName, randomMode(0700))) + assert.NilError(t, os.Mkdir(dirName, randomMode(0700))) populateSrcDir(t, dirName, remainingDepth-1) - require.NoError(t, system.Chtimes(dirName, aTime, mTime)) + assert.NilError(t, system.Chtimes(dirName, aTime, mTime)) } for i := 0; i < 10; i++ { fileName := filepath.Join(srcDir, fmt.Sprintf("srcfile-%d", i)) // Owner read bit set - require.NoError(t, ioutil.WriteFile(fileName, []byte{}, randomMode(0400))) - require.NoError(t, system.Chtimes(fileName, aTime, mTime)) + assert.NilError(t, ioutil.WriteFile(fileName, []byte{}, randomMode(0400))) + assert.NilError(t, system.Chtimes(fileName, aTime, mTime)) } } func doCopyTest(t *testing.T, copyWithFileRange, copyWithFileClone *bool) { dir, err := ioutil.TempDir("", "docker-copy-check") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dir) srcFilename := filepath.Join(dir, "srcFilename") dstFilename := filepath.Join(dir, "dstilename") @@ -138,42 +138,42 @@ func doCopyTest(t *testing.T, copyWithFileRange, copyWithFileClone *bool) { r := rand.New(rand.NewSource(0)) buf := make([]byte, 1024) _, err = r.Read(buf) - require.NoError(t, err) - require.NoError(t, ioutil.WriteFile(srcFilename, buf, 0777)) + assert.NilError(t, err) + assert.NilError(t, ioutil.WriteFile(srcFilename, buf, 0777)) fileinfo, err := os.Stat(srcFilename) - require.NoError(t, err) + assert.NilError(t, err) - require.NoError(t, copyRegular(srcFilename, dstFilename, fileinfo, copyWithFileRange, copyWithFileClone)) + assert.NilError(t, copyRegular(srcFilename, dstFilename, fileinfo, copyWithFileRange, copyWithFileClone)) readBuf, err := ioutil.ReadFile(dstFilename) - require.NoError(t, err) - assert.Equal(t, buf, readBuf) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(buf, readBuf)) } func TestCopyHardlink(t *testing.T) { var srcFile1FileInfo, srcFile2FileInfo, dstFile1FileInfo, dstFile2FileInfo unix.Stat_t srcDir, err := ioutil.TempDir("", "srcDir") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(srcDir) dstDir, err := ioutil.TempDir("", "dstDir") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dstDir) srcFile1 := filepath.Join(srcDir, "file1") srcFile2 := filepath.Join(srcDir, "file2") dstFile1 := filepath.Join(dstDir, "file1") dstFile2 := filepath.Join(dstDir, "file2") - require.NoError(t, ioutil.WriteFile(srcFile1, []byte{}, 0777)) - require.NoError(t, os.Link(srcFile1, srcFile2)) + assert.NilError(t, ioutil.WriteFile(srcFile1, []byte{}, 0777)) + assert.NilError(t, os.Link(srcFile1, srcFile2)) - assert.NoError(t, DirCopy(srcDir, dstDir, Content, false)) + assert.Check(t, DirCopy(srcDir, dstDir, Content, false)) - require.NoError(t, unix.Stat(srcFile1, &srcFile1FileInfo)) - require.NoError(t, unix.Stat(srcFile2, &srcFile2FileInfo)) - require.Equal(t, srcFile1FileInfo.Ino, srcFile2FileInfo.Ino) + assert.NilError(t, unix.Stat(srcFile1, &srcFile1FileInfo)) + assert.NilError(t, unix.Stat(srcFile2, &srcFile2FileInfo)) + assert.Equal(t, srcFile1FileInfo.Ino, srcFile2FileInfo.Ino) - require.NoError(t, unix.Stat(dstFile1, &dstFile1FileInfo)) - require.NoError(t, unix.Stat(dstFile2, &dstFile2FileInfo)) - assert.Equal(t, dstFile1FileInfo.Ino, dstFile2FileInfo.Ino) + assert.NilError(t, unix.Stat(dstFile1, &dstFile1FileInfo)) + assert.NilError(t, unix.Stat(dstFile2, &dstFile2FileInfo)) + assert.Check(t, is.Equal(dstFile1FileInfo.Ino, dstFile2FileInfo.Ino)) } diff --git a/components/engine/daemon/graphdriver/driver_test.go b/components/engine/daemon/graphdriver/driver_test.go index 777bac7af9..4a29465f15 100644 --- a/components/engine/daemon/graphdriver/driver_test.go +++ b/components/engine/daemon/graphdriver/driver_test.go @@ -6,32 +6,31 @@ import ( "path/filepath" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestIsEmptyDir(t *testing.T) { tmp, err := ioutil.TempDir("", "test-is-empty-dir") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmp) d := filepath.Join(tmp, "empty-dir") err = os.Mkdir(d, 0755) - require.NoError(t, err) + assert.NilError(t, err) empty := isEmptyDir(d) - assert.True(t, empty) + assert.Check(t, empty) d = filepath.Join(tmp, "dir-with-subdir") err = os.MkdirAll(filepath.Join(d, "subdir"), 0755) - require.NoError(t, err) + assert.NilError(t, err) empty = isEmptyDir(d) - assert.False(t, empty) + assert.Check(t, !empty) d = filepath.Join(tmp, "dir-with-empty-file") err = os.Mkdir(d, 0755) - require.NoError(t, err) + assert.NilError(t, err) _, err = ioutil.TempFile(d, "file") - require.NoError(t, err) + assert.NilError(t, err) empty = isEmptyDir(d) - assert.False(t, empty) + assert.Check(t, !empty) } diff --git a/components/engine/daemon/graphdriver/graphtest/graphbench_unix.go b/components/engine/daemon/graphdriver/graphtest/graphbench_unix.go index 2eb4184c0f..1b221dabef 100644 --- a/components/engine/daemon/graphdriver/graphtest/graphbench_unix.go +++ b/components/engine/daemon/graphdriver/graphtest/graphbench_unix.go @@ -9,7 +9,7 @@ import ( contdriver "github.com/containerd/continuity/driver" "github.com/docker/docker/pkg/stringid" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) // DriverBenchExists benchmarks calls to exist @@ -251,7 +251,7 @@ func DriverBenchDeepLayerRead(b *testing.B, layerCount int, drivername string, d } b.StopTimer() - require.Equal(b, content, c) + assert.DeepEqual(b, content, c) b.StartTimer() } } diff --git a/components/engine/daemon/graphdriver/graphtest/graphtest_unix.go b/components/engine/daemon/graphdriver/graphtest/graphtest_unix.go index a7bdd8cdaa..1e068535f3 100644 --- a/components/engine/daemon/graphdriver/graphtest/graphtest_unix.go +++ b/components/engine/daemon/graphdriver/graphtest/graphtest_unix.go @@ -15,9 +15,9 @@ import ( "github.com/docker/docker/daemon/graphdriver" "github.com/docker/docker/daemon/graphdriver/quota" "github.com/docker/docker/pkg/stringid" - "github.com/docker/go-units" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + units "github.com/docker/go-units" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/sys/unix" ) @@ -36,9 +36,9 @@ type Driver struct { func newDriver(t testing.TB, name string, options []string) *Driver { root, err := ioutil.TempDir("", "docker-graphtest-") - require.NoError(t, err) + assert.NilError(t, err) - require.NoError(t, os.MkdirAll(root, 0755)) + assert.NilError(t, os.MkdirAll(root, 0755)) d, err := graphdriver.GetDriver(name, nil, graphdriver.Options{DriverOptions: options, Root: root}) if err != nil { t.Logf("graphdriver: %v\n", err) @@ -85,10 +85,10 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str defer PutDriver(t) err := driver.Create("empty", "", nil) - require.NoError(t, err) + assert.NilError(t, err) defer func() { - require.NoError(t, driver.Remove("empty")) + assert.NilError(t, driver.Remove("empty")) }() if !driver.Exists("empty") { @@ -96,14 +96,14 @@ func DriverTestCreateEmpty(t testing.TB, drivername string, driverOptions ...str } dir, err := driver.Get("empty", "") - require.NoError(t, err) + assert.NilError(t, err) verifyFile(t, dir.Path(), 0755|os.ModeDir, 0, 0) // Verify that the directory is empty fis, err := readDir(dir, dir.Path()) - require.NoError(t, err) - assert.Len(t, fis, 0) + assert.NilError(t, err) + assert.Check(t, is.Len(fis, 0)) driver.Put("empty") } @@ -115,7 +115,7 @@ func DriverTestCreateBase(t testing.TB, drivername string, driverOptions ...stri createBase(t, driver, "Base") defer func() { - require.NoError(t, driver.Remove("Base")) + assert.NilError(t, driver.Remove("Base")) }() verifyBase(t, driver, "Base") } @@ -127,13 +127,13 @@ func DriverTestCreateSnap(t testing.TB, drivername string, driverOptions ...stri createBase(t, driver, "Base") defer func() { - require.NoError(t, driver.Remove("Base")) + assert.NilError(t, driver.Remove("Base")) }() err := driver.Create("Snap", "Base", nil) - require.NoError(t, err) + assert.NilError(t, err) defer func() { - require.NoError(t, driver.Remove("Snap")) + assert.NilError(t, driver.Remove("Snap")) }() verifyBase(t, driver, "Snap") diff --git a/components/engine/daemon/graphdriver/graphtest/testutil_unix.go b/components/engine/daemon/graphdriver/graphtest/testutil_unix.go index 4659bf2a19..3103df150d 100644 --- a/components/engine/daemon/graphdriver/graphtest/testutil_unix.go +++ b/components/engine/daemon/graphdriver/graphtest/testutil_unix.go @@ -9,25 +9,25 @@ import ( contdriver "github.com/containerd/continuity/driver" "github.com/docker/docker/daemon/graphdriver" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/sys/unix" ) func verifyFile(t testing.TB, path string, mode os.FileMode, uid, gid uint32) { fi, err := os.Stat(path) - require.NoError(t, err) + assert.NilError(t, err) actual := fi.Mode() - assert.Equal(t, mode&os.ModeType, actual&os.ModeType, path) - assert.Equal(t, mode&os.ModePerm, actual&os.ModePerm, path) - assert.Equal(t, mode&os.ModeSticky, actual&os.ModeSticky, path) - assert.Equal(t, mode&os.ModeSetuid, actual&os.ModeSetuid, path) - assert.Equal(t, mode&os.ModeSetgid, actual&os.ModeSetgid, path) + assert.Check(t, is.Equal(mode&os.ModeType, actual&os.ModeType), path) + assert.Check(t, is.Equal(mode&os.ModePerm, actual&os.ModePerm), path) + assert.Check(t, is.Equal(mode&os.ModeSticky, actual&os.ModeSticky), path) + assert.Check(t, is.Equal(mode&os.ModeSetuid, actual&os.ModeSetuid), path) + assert.Check(t, is.Equal(mode&os.ModeSetgid, actual&os.ModeSetgid), path) if stat, ok := fi.Sys().(*syscall.Stat_t); ok { - assert.Equal(t, uid, stat.Uid, path) - assert.Equal(t, gid, stat.Gid, path) + assert.Check(t, is.Equal(uid, stat.Uid), path) + assert.Check(t, is.Equal(gid, stat.Gid), path) } } @@ -37,24 +37,24 @@ func createBase(t testing.TB, driver graphdriver.Driver, name string) { defer unix.Umask(oldmask) err := driver.CreateReadWrite(name, "", nil) - require.NoError(t, err) + assert.NilError(t, err) dirFS, err := driver.Get(name, "") - require.NoError(t, err) + assert.NilError(t, err) defer driver.Put(name) subdir := dirFS.Join(dirFS.Path(), "a subdir") - require.NoError(t, dirFS.Mkdir(subdir, 0705|os.ModeSticky)) - require.NoError(t, dirFS.Lchown(subdir, 1, 2)) + assert.NilError(t, dirFS.Mkdir(subdir, 0705|os.ModeSticky)) + assert.NilError(t, dirFS.Lchown(subdir, 1, 2)) file := dirFS.Join(dirFS.Path(), "a file") err = contdriver.WriteFile(dirFS, file, []byte("Some data"), 0222|os.ModeSetuid) - require.NoError(t, err) + assert.NilError(t, err) } func verifyBase(t testing.TB, driver graphdriver.Driver, name string) { dirFS, err := driver.Get(name, "") - require.NoError(t, err) + assert.NilError(t, err) defer driver.Put(name) subdir := dirFS.Join(dirFS.Path(), "a subdir") @@ -64,6 +64,6 @@ func verifyBase(t testing.TB, driver graphdriver.Driver, name string) { verifyFile(t, file, 0222|os.ModeSetuid, 0, 0) files, err := readDir(dirFS, dirFS.Path()) - require.NoError(t, err) - assert.Len(t, files, 2) + assert.NilError(t, err) + assert.Check(t, is.Len(files, 2)) } diff --git a/components/engine/daemon/graphdriver/quota/projectquota_test.go b/components/engine/daemon/graphdriver/quota/projectquota_test.go index 939044fdc3..2f1bf593de 100644 --- a/components/engine/daemon/graphdriver/quota/projectquota_test.go +++ b/components/engine/daemon/graphdriver/quota/projectquota_test.go @@ -10,9 +10,9 @@ import ( "path/filepath" "testing" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/sys/unix" ) @@ -80,14 +80,14 @@ func wrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *test } } - require.NoError(t, err, "mount failed: %s", out) + assert.NilError(t, err, "mount failed: %s", out) defer func() { - require.NoError(t, unix.Unmount(mountPoint, 0)) + assert.NilError(t, unix.Unmount(mountPoint, 0)) }() backingFsDev, err := makeBackingFsDev(mountPoint) - require.NoError(t, err) + assert.NilError(t, err) testFunc(t, mountPoint, backingFsDev) } @@ -95,58 +95,58 @@ func wrapMountTest(imageFileName string, enableQuota bool, testFunc func(t *test func testBlockDevQuotaDisabled(t *testing.T, mountPoint, backingFsDev string) { hasSupport, err := hasQuotaSupport(backingFsDev) - require.NoError(t, err) - assert.False(t, hasSupport) + assert.NilError(t, err) + assert.Check(t, !hasSupport) } func testBlockDevQuotaEnabled(t *testing.T, mountPoint, backingFsDev string) { hasSupport, err := hasQuotaSupport(backingFsDev) - require.NoError(t, err) - assert.True(t, hasSupport) + assert.NilError(t, err) + assert.Check(t, hasSupport) } func wrapQuotaTest(testFunc func(t *testing.T, ctrl *Control, mountPoint, testDir, testSubDir string)) func(t *testing.T, mountPoint, backingFsDev string) { return func(t *testing.T, mountPoint, backingFsDev string) { testDir, err := ioutil.TempDir(mountPoint, "per-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(testDir) ctrl, err := NewControl(testDir) - require.NoError(t, err) + assert.NilError(t, err) testSubDir, err := ioutil.TempDir(testDir, "quota-test") - require.NoError(t, err) + assert.NilError(t, err) testFunc(t, ctrl, mountPoint, testDir, testSubDir) } } func testSmallerThanQuota(t *testing.T, ctrl *Control, homeDir, testDir, testSubDir string) { - require.NoError(t, ctrl.SetQuota(testSubDir, Quota{testQuotaSize})) + assert.NilError(t, ctrl.SetQuota(testSubDir, Quota{testQuotaSize})) smallerThanQuotaFile := filepath.Join(testSubDir, "smaller-than-quota") - require.NoError(t, ioutil.WriteFile(smallerThanQuotaFile, make([]byte, testQuotaSize/2), 0644)) - require.NoError(t, os.Remove(smallerThanQuotaFile)) + assert.NilError(t, ioutil.WriteFile(smallerThanQuotaFile, make([]byte, testQuotaSize/2), 0644)) + assert.NilError(t, os.Remove(smallerThanQuotaFile)) } func testBiggerThanQuota(t *testing.T, ctrl *Control, homeDir, testDir, testSubDir string) { // Make sure the quota is being enforced // TODO: When we implement this under EXT4, we need to shed CAP_SYS_RESOURCE, otherwise // we're able to violate quota without issue - require.NoError(t, ctrl.SetQuota(testSubDir, Quota{testQuotaSize})) + assert.NilError(t, ctrl.SetQuota(testSubDir, Quota{testQuotaSize})) biggerThanQuotaFile := filepath.Join(testSubDir, "bigger-than-quota") err := ioutil.WriteFile(biggerThanQuotaFile, make([]byte, testQuotaSize+1), 0644) - require.Error(t, err) + assert.Assert(t, is.ErrorContains(err, "")) if err == io.ErrShortWrite { - require.NoError(t, os.Remove(biggerThanQuotaFile)) + assert.NilError(t, os.Remove(biggerThanQuotaFile)) } } func testRetrieveQuota(t *testing.T, ctrl *Control, homeDir, testDir, testSubDir string) { // Validate that we can retrieve quota - require.NoError(t, ctrl.SetQuota(testSubDir, Quota{testQuotaSize})) + assert.NilError(t, ctrl.SetQuota(testSubDir, Quota{testQuotaSize})) var q Quota - require.NoError(t, ctrl.GetQuota(testSubDir, &q)) - assert.EqualValues(t, testQuotaSize, q.Size) + assert.NilError(t, ctrl.GetQuota(testSubDir, &q)) + assert.Check(t, is.Equal(uint64(testQuotaSize), q.Size)) } diff --git a/components/engine/daemon/info_unix_test.go b/components/engine/daemon/info_unix_test.go index 92a336162a..7ff1009326 100644 --- a/components/engine/daemon/info_unix_test.go +++ b/components/engine/daemon/info_unix_test.go @@ -7,7 +7,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/dockerversion" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestParseInitVersion(t *testing.T) { @@ -43,10 +44,10 @@ func TestParseInitVersion(t *testing.T) { for _, test := range tests { ver, err := parseInitVersion(string(test.version)) if test.invalid { - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) } else { - assert.NoError(t, err) + assert.Check(t, err) } - assert.Equal(t, test.result, ver) + assert.Check(t, is.DeepEqual(test.result, ver)) } } diff --git a/components/engine/daemon/inspect_test.go b/components/engine/daemon/inspect_test.go index c10cc56796..d1ad5b0e0a 100644 --- a/components/engine/daemon/inspect_test.go +++ b/components/engine/daemon/inspect_test.go @@ -7,8 +7,8 @@ import ( "github.com/docker/docker/container" "github.com/docker/docker/daemon/config" "github.com/docker/docker/daemon/exec" - - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestGetInspectData(t *testing.T) { @@ -25,9 +25,9 @@ func TestGetInspectData(t *testing.T) { } _, err := d.getInspectData(c) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) c.Dead = true _, err = d.getInspectData(c) - assert.NoError(t, err) + assert.Check(t, err) } diff --git a/components/engine/daemon/logger/adapter_test.go b/components/engine/daemon/logger/adapter_test.go index 25abab5717..94d14eaef1 100644 --- a/components/engine/daemon/logger/adapter_test.go +++ b/components/engine/daemon/logger/adapter_test.go @@ -10,7 +10,8 @@ import ( "github.com/docker/docker/api/types/plugins/logdriver" protoio "github.com/gogo/protobuf/io" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) // mockLoggingPlugin implements the loggingPlugin interface for testing purposes @@ -88,7 +89,7 @@ func (l *mockLoggingPlugin) ReadLogs(info Info, config ReadConfig) (io.ReadClose func newMockPluginAdapter(t *testing.T) Logger { r, w := io.Pipe() f, err := ioutil.TempFile("", "mock-plugin-adapter") - assert.NoError(t, err) + assert.Check(t, err) enc := logdriver.NewLogEntryEncoder(w) a := &pluginAdapterWithRead{ @@ -116,11 +117,11 @@ func TestAdapterReadLogs(t *testing.T) { } for _, msg := range testMsg { m := msg.copy() - assert.NoError(t, l.Log(m)) + assert.Check(t, l.Log(m)) } lr, ok := l.(LogReader) - assert.NotNil(t, ok) + assert.Check(t, ok, "Logger does not implement LogReader") lw := lr.ReadLogs(ReadConfig{}) @@ -135,7 +136,7 @@ func TestAdapterReadLogs(t *testing.T) { select { case _, ok := <-lw.Msg: - assert.False(t, ok, "expected message channel to be closed") + assert.Check(t, !ok, "expected message channel to be closed") case <-time.After(10 * time.Second): t.Fatal("timeout waiting for message channel to close") @@ -153,11 +154,11 @@ func TestAdapterReadLogs(t *testing.T) { } x := Message{Line: []byte("Too infinity and beyond!"), Timestamp: time.Now()} - assert.NoError(t, l.Log(x.copy())) + assert.Check(t, l.Log(x.copy())) select { case msg, ok := <-lw.Msg: - assert.NotNil(t, ok, "message channel unexpectedly closed") + assert.Check(t, ok, "message channel unexpectedly closed") testMessageEqual(t, &x, msg) case <-time.After(10 * time.Second): t.Fatal("timeout reading logs") @@ -166,15 +167,15 @@ func TestAdapterReadLogs(t *testing.T) { l.Close() select { case msg, ok := <-lw.Msg: - assert.False(t, ok, "expected message channel to be closed") - assert.Nil(t, msg) + assert.Check(t, !ok, "expected message channel to be closed") + assert.Check(t, is.Nil(msg)) case <-time.After(10 * time.Second): t.Fatal("timeout waiting for logger to close") } } func testMessageEqual(t *testing.T, a, b *Message) { - assert.Equal(t, a.Line, b.Line) - assert.Equal(t, a.Timestamp.UnixNano(), b.Timestamp.UnixNano()) - assert.Equal(t, a.Source, b.Source) + assert.Check(t, is.DeepEqual(a.Line, b.Line)) + assert.Check(t, is.DeepEqual(a.Timestamp.UnixNano(), b.Timestamp.UnixNano())) + assert.Check(t, is.Equal(a.Source, b.Source)) } diff --git a/components/engine/daemon/logger/awslogs/cloudwatchlogs.go b/components/engine/daemon/logger/awslogs/cloudwatchlogs.go index 835379b3b4..d6312b660a 100644 --- a/components/engine/daemon/logger/awslogs/cloudwatchlogs.go +++ b/components/engine/daemon/logger/awslogs/cloudwatchlogs.go @@ -69,6 +69,8 @@ type logStream struct { sequenceToken *string } +var _ logger.SizedLogger = &logStream{} + type api interface { CreateLogGroup(*cloudwatchlogs.CreateLogGroupInput) (*cloudwatchlogs.CreateLogGroupOutput, error) CreateLogStream(*cloudwatchlogs.CreateLogStreamInput) (*cloudwatchlogs.CreateLogStreamOutput, error) diff --git a/components/engine/daemon/logger/awslogs/cloudwatchlogs_test.go b/components/engine/daemon/logger/awslogs/cloudwatchlogs_test.go index 080157b2ea..4a37d98167 100644 --- a/components/engine/daemon/logger/awslogs/cloudwatchlogs_test.go +++ b/components/engine/daemon/logger/awslogs/cloudwatchlogs_test.go @@ -21,7 +21,8 @@ import ( "github.com/docker/docker/daemon/logger" "github.com/docker/docker/daemon/logger/loggerutils" "github.com/docker/docker/dockerversion" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) const ( @@ -544,17 +545,17 @@ func TestCollectBatchMultilinePattern(t *testing.T) { // Verify single multiline event argument := <-mockClient.putLogEventsArgument - assert.NotNil(t, argument, "Expected non-nil PutLogEventsInput") - assert.Equal(t, 1, len(argument.LogEvents), "Expected single multiline event") - assert.Equal(t, logline+"\n"+logline+"\n", *argument.LogEvents[0].Message, "Received incorrect multiline message") + assert.Check(t, argument != nil, "Expected non-nil PutLogEventsInput") + assert.Check(t, is.Equal(1, len(argument.LogEvents)), "Expected single multiline event") + assert.Check(t, is.Equal(logline+"\n"+logline+"\n", *argument.LogEvents[0].Message), "Received incorrect multiline message") stream.Close() // Verify single event argument = <-mockClient.putLogEventsArgument - assert.NotNil(t, argument, "Expected non-nil PutLogEventsInput") - assert.Equal(t, 1, len(argument.LogEvents), "Expected single multiline event") - assert.Equal(t, "xxxx "+logline+"\n", *argument.LogEvents[0].Message, "Received incorrect multiline message") + assert.Check(t, argument != nil, "Expected non-nil PutLogEventsInput") + assert.Check(t, is.Equal(1, len(argument.LogEvents)), "Expected single multiline event") + assert.Check(t, is.Equal("xxxx "+logline+"\n", *argument.LogEvents[0].Message), "Received incorrect multiline message") } func BenchmarkCollectBatch(b *testing.B) { @@ -657,9 +658,9 @@ func TestCollectBatchMultilinePatternMaxEventAge(t *testing.T) { // Verify single multiline event is flushed after maximum event buffer age (batchPublishFrequency) argument := <-mockClient.putLogEventsArgument - assert.NotNil(t, argument, "Expected non-nil PutLogEventsInput") - assert.Equal(t, 1, len(argument.LogEvents), "Expected single multiline event") - assert.Equal(t, logline+"\n"+logline+"\n", *argument.LogEvents[0].Message, "Received incorrect multiline message") + assert.Check(t, argument != nil, "Expected non-nil PutLogEventsInput") + assert.Check(t, is.Equal(1, len(argument.LogEvents)), "Expected single multiline event") + assert.Check(t, is.Equal(logline+"\n"+logline+"\n", *argument.LogEvents[0].Message), "Received incorrect multiline message") // Log an event 1 second later stream.Log(&logger.Message{ @@ -672,9 +673,9 @@ func TestCollectBatchMultilinePatternMaxEventAge(t *testing.T) { // Verify the event buffer is truly flushed - we should only receive a single event argument = <-mockClient.putLogEventsArgument - assert.NotNil(t, argument, "Expected non-nil PutLogEventsInput") - assert.Equal(t, 1, len(argument.LogEvents), "Expected single multiline event") - assert.Equal(t, logline+"\n", *argument.LogEvents[0].Message, "Received incorrect multiline message") + assert.Check(t, argument != nil, "Expected non-nil PutLogEventsInput") + assert.Check(t, is.Equal(1, len(argument.LogEvents)), "Expected single multiline event") + assert.Check(t, is.Equal(logline+"\n", *argument.LogEvents[0].Message), "Received incorrect multiline message") stream.Close() } @@ -719,9 +720,9 @@ func TestCollectBatchMultilinePatternNegativeEventAge(t *testing.T) { // Verify single multiline event is flushed with a negative event buffer age argument := <-mockClient.putLogEventsArgument - assert.NotNil(t, argument, "Expected non-nil PutLogEventsInput") - assert.Equal(t, 1, len(argument.LogEvents), "Expected single multiline event") - assert.Equal(t, logline+"\n"+logline+"\n", *argument.LogEvents[0].Message, "Received incorrect multiline message") + assert.Check(t, argument != nil, "Expected non-nil PutLogEventsInput") + assert.Check(t, is.Equal(1, len(argument.LogEvents)), "Expected single multiline event") + assert.Check(t, is.Equal(logline+"\n"+logline+"\n", *argument.LogEvents[0].Message), "Received incorrect multiline message") stream.Close() } @@ -772,10 +773,10 @@ func TestCollectBatchMultilinePatternMaxEventSize(t *testing.T) { // We expect a maximum sized event with no new line characters and a // second short event with a new line character at the end argument := <-mockClient.putLogEventsArgument - assert.NotNil(t, argument, "Expected non-nil PutLogEventsInput") - assert.Equal(t, 2, len(argument.LogEvents), "Expected two events") - assert.Equal(t, longline, *argument.LogEvents[0].Message, "Received incorrect multiline message") - assert.Equal(t, shortline+"\n", *argument.LogEvents[1].Message, "Received incorrect multiline message") + assert.Check(t, argument != nil, "Expected non-nil PutLogEventsInput") + assert.Check(t, is.Equal(2, len(argument.LogEvents)), "Expected two events") + assert.Check(t, is.Equal(longline, *argument.LogEvents[0].Message), "Received incorrect multiline message") + assert.Check(t, is.Equal(shortline+"\n", *argument.LogEvents[1].Message), "Received incorrect multiline message") stream.Close() } @@ -1069,8 +1070,8 @@ func TestParseLogOptionsMultilinePattern(t *testing.T) { } multilinePattern, err := parseMultilineOptions(info) - assert.Nil(t, err, "Received unexpected error") - assert.True(t, multilinePattern.MatchString("xxxx"), "No multiline pattern match found") + assert.Check(t, err, "Received unexpected error") + assert.Check(t, multilinePattern.MatchString("xxxx"), "No multiline pattern match found") } func TestParseLogOptionsDatetimeFormat(t *testing.T) { @@ -1094,8 +1095,8 @@ func TestParseLogOptionsDatetimeFormat(t *testing.T) { }, } multilinePattern, err := parseMultilineOptions(info) - assert.Nil(t, err, "Received unexpected error") - assert.True(t, multilinePattern.MatchString(dt.match), "No multiline pattern match found") + assert.Check(t, err, "Received unexpected error") + assert.Check(t, multilinePattern.MatchString(dt.match), "No multiline pattern match found") }) } } @@ -1109,8 +1110,8 @@ func TestValidateLogOptionsDatetimeFormatAndMultilinePattern(t *testing.T) { conflictingLogOptionsError := "you cannot configure log opt 'awslogs-datetime-format' and 'awslogs-multiline-pattern' at the same time" err := ValidateLogOpt(cfg) - assert.NotNil(t, err, "Expected an error") - assert.Equal(t, err.Error(), conflictingLogOptionsError, "Received invalid error") + assert.Check(t, err != nil, "Expected an error") + assert.Check(t, is.Equal(err.Error(), conflictingLogOptionsError), "Received invalid error") } func TestCreateTagSuccess(t *testing.T) { @@ -1143,11 +1144,6 @@ func TestCreateTagSuccess(t *testing.T) { } } -func TestIsSizedLogger(t *testing.T) { - awslogs := &logStream{} - assert.Implements(t, (*logger.SizedLogger)(nil), awslogs, "awslogs should implement SizedLogger") -} - func BenchmarkUnwrapEvents(b *testing.B) { events := make([]wrappedEvent, maximumLogEventsPerPut) for i := 0; i < maximumLogEventsPerPut; i++ { @@ -1157,11 +1153,10 @@ func BenchmarkUnwrapEvents(b *testing.B) { } } - as := assert.New(b) b.ResetTimer() for i := 0; i < b.N; i++ { res := unwrapEvents(events) - as.Len(res, maximumLogEventsPerPut) + assert.Check(b, is.Len(res, maximumLogEventsPerPut)) } } @@ -1194,15 +1189,15 @@ func TestNewAWSLogsClientCredentialEndpointDetect(t *testing.T) { info.Config["awslogs-credentials-endpoint"] = "/creds" c, err := newAWSLogsClient(info) - assert.NoError(t, err) + assert.Check(t, err) client := c.(*cloudwatchlogs.CloudWatchLogs) creds, err := client.Config.Credentials.Get() - assert.NoError(t, err) + assert.Check(t, err) - assert.Equal(t, expectedAccessKeyID, creds.AccessKeyID) - assert.Equal(t, expectedSecretAccessKey, creds.SecretAccessKey) + assert.Check(t, is.Equal(expectedAccessKeyID, creds.AccessKeyID)) + assert.Check(t, is.Equal(expectedSecretAccessKey, creds.SecretAccessKey)) } func TestNewAWSLogsClientCredentialEnvironmentVariable(t *testing.T) { @@ -1224,15 +1219,15 @@ func TestNewAWSLogsClientCredentialEnvironmentVariable(t *testing.T) { } c, err := newAWSLogsClient(info) - assert.NoError(t, err) + assert.Check(t, err) client := c.(*cloudwatchlogs.CloudWatchLogs) creds, err := client.Config.Credentials.Get() - assert.NoError(t, err) + assert.Check(t, err) - assert.Equal(t, expectedAccessKeyID, creds.AccessKeyID) - assert.Equal(t, expectedSecretAccessKey, creds.SecretAccessKey) + assert.Check(t, is.Equal(expectedAccessKeyID, creds.AccessKeyID)) + assert.Check(t, is.Equal(expectedSecretAccessKey, creds.SecretAccessKey)) } @@ -1253,13 +1248,13 @@ func TestNewAWSLogsClientCredentialSharedFile(t *testing.T) { tmpfile, err := ioutil.TempFile("", "example") defer os.Remove(tmpfile.Name()) // clean up - assert.NoError(t, err) + assert.Check(t, err) _, err = tmpfile.Write(content) - assert.NoError(t, err) + assert.Check(t, err) err = tmpfile.Close() - assert.NoError(t, err) + assert.Check(t, err) os.Unsetenv("AWS_ACCESS_KEY_ID") os.Unsetenv("AWS_SECRET_ACCESS_KEY") @@ -1272,13 +1267,13 @@ func TestNewAWSLogsClientCredentialSharedFile(t *testing.T) { } c, err := newAWSLogsClient(info) - assert.NoError(t, err) + assert.Check(t, err) client := c.(*cloudwatchlogs.CloudWatchLogs) creds, err := client.Config.Credentials.Get() - assert.NoError(t, err) + assert.Check(t, err) - assert.Equal(t, expectedAccessKeyID, creds.AccessKeyID) - assert.Equal(t, expectedSecretAccessKey, creds.SecretAccessKey) + assert.Check(t, is.Equal(expectedAccessKeyID, creds.AccessKeyID)) + assert.Check(t, is.Equal(expectedSecretAccessKey, creds.SecretAccessKey)) } diff --git a/components/engine/daemon/logger/jsonfilelog/jsonfilelog_test.go b/components/engine/daemon/logger/jsonfilelog/jsonfilelog_test.go index 2f74e26091..0174d88c0d 100644 --- a/components/engine/daemon/logger/jsonfilelog/jsonfilelog_test.go +++ b/components/engine/daemon/logger/jsonfilelog/jsonfilelog_test.go @@ -13,9 +13,9 @@ import ( "github.com/docker/docker/daemon/logger" "github.com/docker/docker/daemon/logger/jsonfilelog/jsonlog" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestJSONFileLogger(t *testing.T) { @@ -63,7 +63,7 @@ func TestJSONFileLoggerWithTags(t *testing.T) { cname := "test-container" tmp, err := ioutil.TempDir("", "docker-logger-") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmp) filename := filepath.Join(tmp, "container.log") @@ -76,26 +76,26 @@ func TestJSONFileLoggerWithTags(t *testing.T) { LogPath: filename, }) - require.NoError(t, err) + assert.NilError(t, err) defer l.Close() err = l.Log(&logger.Message{Line: []byte("line1"), Source: "src1"}) - require.NoError(t, err) + assert.NilError(t, err) err = l.Log(&logger.Message{Line: []byte("line2"), Source: "src2"}) - require.NoError(t, err) + assert.NilError(t, err) err = l.Log(&logger.Message{Line: []byte("line3"), Source: "src3"}) - require.NoError(t, err) + assert.NilError(t, err) res, err := ioutil.ReadFile(filename) - require.NoError(t, err) + assert.NilError(t, err) expected := `{"log":"line1\n","stream":"src1","attrs":{"tag":"a7317399f3f8/test-container"},"time":"0001-01-01T00:00:00Z"} {"log":"line2\n","stream":"src2","attrs":{"tag":"a7317399f3f8/test-container"},"time":"0001-01-01T00:00:00Z"} {"log":"line3\n","stream":"src3","attrs":{"tag":"a7317399f3f8/test-container"},"time":"0001-01-01T00:00:00Z"} ` - assert.Equal(t, expected, string(res)) + assert.Check(t, is.Equal(expected, string(res))) } func BenchmarkJSONFileLoggerLog(b *testing.B) { @@ -113,7 +113,7 @@ func BenchmarkJSONFileLoggerLog(b *testing.B) { "second": "label_foo", }, }) - require.NoError(b, err) + assert.NilError(b, err) defer jsonlogger.Close() msg := &logger.Message{ @@ -123,7 +123,7 @@ func BenchmarkJSONFileLoggerLog(b *testing.B) { } buf := bytes.NewBuffer(nil) - require.NoError(b, marshalMessage(msg, nil, buf)) + assert.NilError(b, marshalMessage(msg, nil, buf)) b.SetBytes(int64(buf.Len())) b.ResetTimer() diff --git a/components/engine/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go b/components/engine/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go index 3701124354..b3bfe6b18c 100644 --- a/components/engine/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go +++ b/components/engine/daemon/logger/jsonfilelog/jsonlog/jsonlogbytes_test.go @@ -3,12 +3,12 @@ package jsonlog // import "github.com/docker/docker/daemon/logger/jsonfilelog/js import ( "bytes" "encoding/json" + "fmt" "regexp" "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestJSONLogsMarshalJSONBuf(t *testing.T) { @@ -35,8 +35,17 @@ func TestJSONLogsMarshalJSONBuf(t *testing.T) { for jsonLog, expression := range logs { var buf bytes.Buffer err := jsonLog.MarshalJSONBuf(&buf) - require.NoError(t, err) - assert.Regexp(t, regexp.MustCompile(expression), buf.String()) - assert.NoError(t, json.Unmarshal(buf.Bytes(), &map[string]interface{}{})) + assert.NilError(t, err) + + assert.Assert(t, regexP(buf.String(), expression)) + assert.NilError(t, json.Unmarshal(buf.Bytes(), &map[string]interface{}{})) + } +} + +func regexP(value string, pattern string) func() (bool, string) { + return func() (bool, string) { + re := regexp.MustCompile(pattern) + msg := fmt.Sprintf("%q did not match pattern %q", value, pattern) + return re.MatchString(value), msg } } diff --git a/components/engine/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go b/components/engine/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go index fee091eb6c..76f299a0f6 100644 --- a/components/engine/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go +++ b/components/engine/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go @@ -5,8 +5,8 @@ import ( "time" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestFastTimeMarshalJSONWithInvalidYear(t *testing.T) { @@ -22,14 +22,14 @@ func TestFastTimeMarshalJSONWithInvalidYear(t *testing.T) { func TestFastTimeMarshalJSON(t *testing.T) { aTime := time.Date(2015, 5, 29, 11, 1, 2, 3, time.UTC) json, err := fastTimeMarshalJSON(aTime) - require.NoError(t, err) - assert.Equal(t, "\"2015-05-29T11:01:02.000000003Z\"", json) + assert.NilError(t, err) + assert.Check(t, is.Equal("\"2015-05-29T11:01:02.000000003Z\"", json)) location, err := time.LoadLocation("Europe/Paris") - require.NoError(t, err) + assert.NilError(t, err) aTime = time.Date(2015, 5, 29, 11, 1, 2, 3, location) json, err = fastTimeMarshalJSON(aTime) - require.NoError(t, err) - assert.Equal(t, "\"2015-05-29T11:01:02.000000003+02:00\"", json) + assert.NilError(t, err) + assert.Check(t, is.Equal("\"2015-05-29T11:01:02.000000003+02:00\"", json)) } diff --git a/components/engine/daemon/logger/jsonfilelog/read_test.go b/components/engine/daemon/logger/jsonfilelog/read_test.go index 342b538c28..f89fabfe1c 100644 --- a/components/engine/daemon/logger/jsonfilelog/read_test.go +++ b/components/engine/daemon/logger/jsonfilelog/read_test.go @@ -6,8 +6,8 @@ import ( "time" "github.com/docker/docker/daemon/logger" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/require" ) func BenchmarkJSONFileLoggerReadLogs(b *testing.B) { @@ -25,7 +25,7 @@ func BenchmarkJSONFileLoggerReadLogs(b *testing.B) { "second": "label_foo", }, }) - require.NoError(b, err) + assert.NilError(b, err) defer jsonlogger.Close() msg := &logger.Message{ @@ -35,7 +35,7 @@ func BenchmarkJSONFileLoggerReadLogs(b *testing.B) { } buf := bytes.NewBuffer(nil) - require.NoError(b, marshalMessage(msg, nil, buf)) + assert.NilError(b, marshalMessage(msg, nil, buf)) b.SetBytes(int64(buf.Len())) b.ResetTimer() diff --git a/components/engine/daemon/logger/splunk/splunk_test.go b/components/engine/daemon/logger/splunk/splunk_test.go index 9744cb561a..62895a6dd6 100644 --- a/components/engine/daemon/logger/splunk/splunk_test.go +++ b/components/engine/daemon/logger/splunk/splunk_test.go @@ -11,8 +11,8 @@ import ( "time" "github.com/docker/docker/daemon/logger" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/env" - "github.com/stretchr/testify/require" ) // Validate options @@ -99,19 +99,19 @@ func TestNewWithProxy(t *testing.T) { }, ContainerID: "containeriid", }) - require.NoError(t, err) + assert.NilError(t, err) splunkLogger := logger.(*splunkLoggerInline) proxyFunc := splunkLogger.transport.Proxy - require.NotNil(t, proxyFunc) + assert.Assert(t, proxyFunc != nil) req, err := http.NewRequest("GET", splunkURL, nil) - require.NoError(t, err) + assert.NilError(t, err) proxyURL, err := proxyFunc(req) - require.NoError(t, err) - require.NotNil(t, proxyURL) - require.Equal(t, proxy, proxyURL.String()) + assert.NilError(t, err) + assert.Assert(t, proxyURL != nil) + assert.Equal(t, proxy, proxyURL.String()) } // Test default settings @@ -483,10 +483,10 @@ func TestRawFormat(t *testing.T) { } hostname, err := info.Hostname() - require.NoError(t, err) + assert.NilError(t, err) loggerDriver, err := New(info) - require.NoError(t, err) + assert.NilError(t, err) if !hec.connectionVerified { t.Fatal("By default connection should be verified") diff --git a/components/engine/daemon/logger/templates/templates_test.go b/components/engine/daemon/logger/templates/templates_test.go index 5e71d96f26..b767037477 100644 --- a/components/engine/daemon/logger/templates/templates_test.go +++ b/components/engine/daemon/logger/templates/templates_test.go @@ -4,15 +4,16 @@ import ( "bytes" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestNewParse(t *testing.T) { tm, err := NewParse("foo", "this is a {{ . }}") - assert.NoError(t, err) + assert.Check(t, err) var b bytes.Buffer - assert.NoError(t, tm.Execute(&b, "string")) + assert.Check(t, tm.Execute(&b, "string")) want := "this is a string" - assert.Equal(t, want, b.String()) + assert.Check(t, is.Equal(want, b.String())) } diff --git a/components/engine/daemon/oci_linux_test.go b/components/engine/daemon/oci_linux_test.go index f6bda79745..5f2731b8d6 100644 --- a/components/engine/daemon/oci_linux_test.go +++ b/components/engine/daemon/oci_linux_test.go @@ -8,8 +8,8 @@ import ( "github.com/docker/docker/daemon/config" "github.com/docker/docker/oci" "github.com/docker/docker/pkg/idtools" - - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) // TestTmpfsDevShmNoDupMount checks that a user-specified /dev/shm tmpfs @@ -36,17 +36,17 @@ func TestTmpfsDevShmNoDupMount(t *testing.T) { // Mimick the code flow of daemon.createSpec(), enough to reproduce the issue ms, err := d.setupMounts(c) - assert.NoError(t, err) + assert.Check(t, err) ms = append(ms, c.IpcMounts()...) tmpfsMounts, err := c.TmpfsMounts() - assert.NoError(t, err) + assert.Check(t, err) ms = append(ms, tmpfsMounts...) s := oci.DefaultSpec() err = setMounts(&d, &s, c, ms) - assert.NoError(t, err) + assert.Check(t, err) } // TestIpcPrivateVsReadonly checks that in case of IpcMode: private @@ -70,19 +70,19 @@ func TestIpcPrivateVsReadonly(t *testing.T) { // We can't call createSpec() so mimick the minimal part // of its code flow, just enough to reproduce the issue. ms, err := d.setupMounts(c) - assert.NoError(t, err) + assert.Check(t, err) s := oci.DefaultSpec() s.Root.Readonly = c.HostConfig.ReadonlyRootfs err = setMounts(&d, &s, c, ms) - assert.NoError(t, err) + assert.Check(t, err) // Find the /dev/shm mount in ms, check it does not have ro for _, m := range s.Mounts { if m.Destination != "/dev/shm" { continue } - assert.Equal(t, false, inSlice(m.Options, "ro")) + assert.Check(t, is.Equal(false, inSlice(m.Options, "ro"))) } } diff --git a/components/engine/daemon/reload_test.go b/components/engine/daemon/reload_test.go index a2500b2bb2..9174bfba54 100644 --- a/components/engine/daemon/reload_test.go +++ b/components/engine/daemon/reload_test.go @@ -12,7 +12,8 @@ import ( _ "github.com/docker/docker/pkg/discovery/memory" "github.com/docker/docker/registry" "github.com/docker/libnetwork" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestDaemonReloadLabels(t *testing.T) { @@ -97,7 +98,7 @@ func TestDaemonReloadAllowNondistributableArtifacts(t *testing.T) { sort.Strings(registries) sort.Strings(actual) - assert.Equal(t, registries, actual) + assert.Check(t, is.DeepEqual(registries, actual)) } func TestDaemonReloadMirrors(t *testing.T) { diff --git a/components/engine/daemon/trustkey_test.go b/components/engine/daemon/trustkey_test.go index c49341d2a9..ebc7e28ee3 100644 --- a/components/engine/daemon/trustkey_test.go +++ b/components/engine/daemon/trustkey_test.go @@ -7,19 +7,19 @@ import ( "testing" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) // LoadOrCreateTrustKey func TestLoadOrCreateTrustKeyInvalidKeyFile(t *testing.T) { tmpKeyFolderPath, err := ioutil.TempDir("", "api-trustkey-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpKeyFolderPath) tmpKeyFile, err := ioutil.TempFile(tmpKeyFolderPath, "keyfile") - require.NoError(t, err) + assert.NilError(t, err) _, err = loadOrCreateTrustKey(tmpKeyFile.Name()) testutil.ErrorContains(t, err, "Error loading key file") @@ -33,11 +33,11 @@ func TestLoadOrCreateTrustKeyCreateKeyWhenFileDoesNotExist(t *testing.T) { tmpKeyFile := tmpKeyFolderPath.Join("keyfile") key, err := loadOrCreateTrustKey(tmpKeyFile) - require.NoError(t, err) - assert.NotNil(t, key) + assert.NilError(t, err) + assert.Check(t, key != nil) _, err = os.Stat(tmpKeyFile) - require.NoError(t, err, "key file doesn't exist") + assert.NilError(t, err, "key file doesn't exist") } func TestLoadOrCreateTrustKeyCreateKeyWhenDirectoryDoesNotExist(t *testing.T) { @@ -46,27 +46,27 @@ func TestLoadOrCreateTrustKeyCreateKeyWhenDirectoryDoesNotExist(t *testing.T) { tmpKeyFile := tmpKeyFolderPath.Join("folder/hierarchy/keyfile") key, err := loadOrCreateTrustKey(tmpKeyFile) - require.NoError(t, err) - assert.NotNil(t, key) + assert.NilError(t, err) + assert.Check(t, key != nil) _, err = os.Stat(tmpKeyFile) - require.NoError(t, err, "key file doesn't exist") + assert.NilError(t, err, "key file doesn't exist") } func TestLoadOrCreateTrustKeyCreateKeyNoPath(t *testing.T) { defer os.Remove("keyfile") key, err := loadOrCreateTrustKey("keyfile") - require.NoError(t, err) - assert.NotNil(t, key) + assert.NilError(t, err) + assert.Check(t, key != nil) _, err = os.Stat("keyfile") - require.NoError(t, err, "key file doesn't exist") + assert.NilError(t, err, "key file doesn't exist") } func TestLoadOrCreateTrustKeyLoadValidKey(t *testing.T) { tmpKeyFile := filepath.Join("testdata", "keyfile") key, err := loadOrCreateTrustKey(tmpKeyFile) - require.NoError(t, err) + assert.NilError(t, err) expected := "AWX2:I27X:WQFX:IOMK:CNAK:O7PW:VYNB:ZLKC:CVAE:YJP2:SI4A:XXAY" - assert.Contains(t, key.String(), expected) + assert.Check(t, is.Contains(key.String(), expected)) } diff --git a/components/engine/distribution/metadata/v1_id_service_test.go b/components/engine/distribution/metadata/v1_id_service_test.go index 8a3647b3b3..7bac8e8212 100644 --- a/components/engine/distribution/metadata/v1_id_service_test.go +++ b/components/engine/distribution/metadata/v1_id_service_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/docker/docker/layer" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestV1IDService(t *testing.T) { @@ -24,7 +24,7 @@ func TestV1IDService(t *testing.T) { ns := v1IDService.namespace() - require.Equal(t, "v1id", ns) + assert.Equal(t, "v1id", ns) testVectors := []struct { registry string diff --git a/components/engine/image/fs_test.go b/components/engine/image/fs_test.go index 6a634377e7..dcf4da75f8 100644 --- a/components/engine/image/fs_test.go +++ b/components/engine/image/fs_test.go @@ -11,16 +11,17 @@ import ( "testing" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" digest "github.com/opencontainers/go-digest" - "github.com/stretchr/testify/assert" ) func defaultFSStoreBackend(t *testing.T) (StoreBackend, func()) { tmpdir, err := ioutil.TempDir("", "images-fs-store") - assert.NoError(t, err) + assert.Check(t, err) fsBackend, err := NewFSStoreBackend(tmpdir) - assert.NoError(t, err) + assert.Check(t, err) return fsBackend, func() { os.RemoveAll(tmpdir) } } @@ -30,12 +31,12 @@ func TestFSGetInvalidData(t *testing.T) { defer cleanup() id, err := store.Set([]byte("foobar")) - assert.NoError(t, err) + assert.Check(t, err) dgst := digest.Digest(id) err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, string(dgst.Algorithm()), dgst.Hex()), []byte("foobar2"), 0600) - assert.NoError(t, err) + assert.Check(t, err) _, err = store.Get(id) testutil.ErrorContains(t, err, "failed to verify") @@ -47,7 +48,7 @@ func TestFSInvalidSet(t *testing.T) { id := digest.FromBytes([]byte("foobar")) err := os.Mkdir(filepath.Join(store.(*fs).root, contentDirName, string(id.Algorithm()), id.Hex()), 0700) - assert.NoError(t, err) + assert.Check(t, err) _, err = store.Set([]byte("foobar")) testutil.ErrorContains(t, err, "failed to write digest data") @@ -55,7 +56,7 @@ func TestFSInvalidSet(t *testing.T) { func TestFSInvalidRoot(t *testing.T) { tmpdir, err := ioutil.TempDir("", "images-fs-store") - assert.NoError(t, err) + assert.Check(t, err) defer os.RemoveAll(tmpdir) tcases := []struct { @@ -70,10 +71,10 @@ func TestFSInvalidRoot(t *testing.T) { root := filepath.Join(tmpdir, tc.root) filePath := filepath.Join(tmpdir, tc.invalidFile) err := os.MkdirAll(filepath.Dir(filePath), 0700) - assert.NoError(t, err) + assert.Check(t, err) f, err := os.Create(filePath) - assert.NoError(t, err) + assert.Check(t, err) f.Close() _, err = NewFSStoreBackend(root) @@ -89,10 +90,10 @@ func TestFSMetadataGetSet(t *testing.T) { defer cleanup() id, err := store.Set([]byte("foo")) - assert.NoError(t, err) + assert.Check(t, err) id2, err := store.Set([]byte("bar")) - assert.NoError(t, err) + assert.Check(t, err) tcases := []struct { id digest.Digest @@ -106,12 +107,12 @@ func TestFSMetadataGetSet(t *testing.T) { for _, tc := range tcases { err = store.SetMetadata(tc.id, tc.key, tc.value) - assert.NoError(t, err) + assert.Check(t, err) actual, err := store.GetMetadata(tc.id, tc.key) - assert.NoError(t, err) + assert.Check(t, err) - assert.Equal(t, tc.value, actual) + assert.Check(t, is.DeepEqual(tc.value, actual)) } _, err = store.GetMetadata(id2, "tkey2") @@ -130,19 +131,19 @@ func TestFSInvalidWalker(t *testing.T) { defer cleanup() fooID, err := store.Set([]byte("foo")) - assert.NoError(t, err) + assert.Check(t, err) err = ioutil.WriteFile(filepath.Join(store.(*fs).root, contentDirName, "sha256/foobar"), []byte("foobar"), 0600) - assert.NoError(t, err) + assert.Check(t, err) n := 0 err = store.Walk(func(id digest.Digest) error { - assert.Equal(t, fooID, id) + assert.Check(t, is.Equal(fooID, id)) n++ return nil }) - assert.NoError(t, err) - assert.Equal(t, 1, n) + assert.Check(t, err) + assert.Check(t, is.Equal(1, n)) } func TestFSGetSet(t *testing.T) { @@ -159,12 +160,12 @@ func TestFSGetSet(t *testing.T) { randomInput := make([]byte, 8*1024) _, err := rand.Read(randomInput) - assert.NoError(t, err) + assert.Check(t, err) // skipping use of digest pkg because it is used by the implementation h := sha256.New() _, err = h.Write(randomInput) - assert.NoError(t, err) + assert.Check(t, err) tcases = append(tcases, tcase{ input: randomInput, @@ -173,14 +174,14 @@ func TestFSGetSet(t *testing.T) { for _, tc := range tcases { id, err := store.Set([]byte(tc.input)) - assert.NoError(t, err) - assert.Equal(t, tc.expected, id) + assert.Check(t, err) + assert.Check(t, is.Equal(tc.expected, id)) } for _, tc := range tcases { data, err := store.Get(tc.expected) - assert.NoError(t, err) - assert.Equal(t, tc.input, data) + assert.Check(t, err) + assert.Check(t, is.DeepEqual(tc.input, data)) } } @@ -209,22 +210,22 @@ func TestFSDelete(t *testing.T) { defer cleanup() id, err := store.Set([]byte("foo")) - assert.NoError(t, err) + assert.Check(t, err) id2, err := store.Set([]byte("bar")) - assert.NoError(t, err) + assert.Check(t, err) err = store.Delete(id) - assert.NoError(t, err) + assert.Check(t, err) _, err = store.Get(id) testutil.ErrorContains(t, err, "failed to get digest") _, err = store.Get(id2) - assert.NoError(t, err) + assert.Check(t, err) err = store.Delete(id2) - assert.NoError(t, err) + assert.Check(t, err) _, err = store.Get(id2) testutil.ErrorContains(t, err, "failed to get digest") @@ -235,10 +236,10 @@ func TestFSWalker(t *testing.T) { defer cleanup() id, err := store.Set([]byte("foo")) - assert.NoError(t, err) + assert.Check(t, err) id2, err := store.Set([]byte("bar")) - assert.NoError(t, err) + assert.Check(t, err) tcases := make(map[digest.Digest]struct{}) tcases[id] = struct{}{} @@ -249,9 +250,9 @@ func TestFSWalker(t *testing.T) { n++ return nil }) - assert.NoError(t, err) - assert.Equal(t, 2, n) - assert.Len(t, tcases, 0) + assert.Check(t, err) + assert.Check(t, is.Equal(2, n)) + assert.Check(t, is.Len(tcases, 0)) } func TestFSWalkerStopOnError(t *testing.T) { @@ -259,7 +260,7 @@ func TestFSWalkerStopOnError(t *testing.T) { defer cleanup() id, err := store.Set([]byte("foo")) - assert.NoError(t, err) + assert.Check(t, err) tcases := make(map[digest.Digest]struct{}) tcases[id] = struct{}{} diff --git a/components/engine/image/image_test.go b/components/engine/image/image_test.go index 429f202978..dfb438b4d3 100644 --- a/components/engine/image/image_test.go +++ b/components/engine/image/image_test.go @@ -9,8 +9,9 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/layer" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/google/go-cmp/cmp" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) const sampleImageJSON = `{ @@ -25,13 +26,13 @@ const sampleImageJSON = `{ func TestNewFromJSON(t *testing.T) { img, err := NewFromJSON([]byte(sampleImageJSON)) - require.NoError(t, err) - assert.Equal(t, sampleImageJSON, string(img.RawJSON())) + assert.NilError(t, err) + assert.Check(t, is.Equal(sampleImageJSON, string(img.RawJSON()))) } func TestNewFromJSONWithInvalidJSON(t *testing.T) { _, err := NewFromJSON([]byte("{}")) - assert.EqualError(t, err, "invalid image JSON, no RootFS key") + assert.Check(t, is.Error(err, "invalid image JSON, no RootFS key")) } func TestMarshalKeyOrder(t *testing.T) { @@ -42,7 +43,7 @@ func TestMarshalKeyOrder(t *testing.T) { Architecture: "c", }, }) - assert.NoError(t, err) + assert.Check(t, err) expectedOrder := []string{"architecture", "author", "comment"} var indexes []int @@ -71,10 +72,10 @@ func TestImage(t *testing.T) { computedID: ID(cid), } - assert.Equal(t, cid, img.ImageID()) - assert.Equal(t, cid, img.ID().String()) - assert.Equal(t, os, img.OperatingSystem()) - assert.Equal(t, config, img.RunConfig()) + assert.Check(t, is.Equal(cid, img.ImageID())) + assert.Check(t, is.Equal(cid, img.ID().String())) + assert.Check(t, is.Equal(os, img.OperatingSystem())) + assert.Check(t, is.DeepEqual(config, img.RunConfig())) } func TestImageOSNotEmpty(t *testing.T) { @@ -85,7 +86,7 @@ func TestImageOSNotEmpty(t *testing.T) { }, OSVersion: "osversion", } - assert.Equal(t, os, img.OperatingSystem()) + assert.Check(t, is.Equal(os, img.OperatingSystem())) } func TestNewChildImageFromImageWithRootFS(t *testing.T) { @@ -109,16 +110,16 @@ func TestNewChildImageFromImageWithRootFS(t *testing.T) { newImage := NewChildImage(parent, childConfig, "platform") expectedDiffIDs := []layer.DiffID{layer.DiffID("ba5e"), layer.DiffID("abcdef")} - assert.Equal(t, expectedDiffIDs, newImage.RootFS.DiffIDs) - assert.Equal(t, childConfig.Author, newImage.Author) - assert.Equal(t, childConfig.Config, newImage.Config) - assert.Equal(t, *childConfig.ContainerConfig, newImage.ContainerConfig) - assert.Equal(t, "platform", newImage.OS) - assert.Equal(t, childConfig.Config, newImage.Config) + assert.Check(t, is.DeepEqual(expectedDiffIDs, newImage.RootFS.DiffIDs)) + assert.Check(t, is.Equal(childConfig.Author, newImage.Author)) + assert.Check(t, is.DeepEqual(childConfig.Config, newImage.Config)) + assert.Check(t, is.DeepEqual(*childConfig.ContainerConfig, newImage.ContainerConfig)) + assert.Check(t, is.Equal("platform", newImage.OS)) + assert.Check(t, is.DeepEqual(childConfig.Config, newImage.Config)) - assert.Len(t, newImage.History, 2) - assert.Equal(t, childConfig.Comment, newImage.History[1].Comment) + assert.Check(t, is.Len(newImage.History, 2)) + assert.Check(t, is.Equal(childConfig.Comment, newImage.History[1].Comment)) - // RootFS should be copied not mutated - assert.NotEqual(t, parent.RootFS.DiffIDs, newImage.RootFS.DiffIDs) + assert.Check(t, !cmp.Equal(parent.RootFS.DiffIDs, newImage.RootFS.DiffIDs), + "RootFS should be copied not mutated") } diff --git a/components/engine/image/store_test.go b/components/engine/image/store_test.go index b1300657a0..d59cde9195 100644 --- a/components/engine/image/store_test.go +++ b/components/engine/image/store_test.go @@ -5,10 +5,10 @@ import ( "runtime" "testing" - "github.com/docker/docker/internal/testutil" "github.com/docker/docker/layer" + "github.com/gotestyourself/gotestyourself/assert" + "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/opencontainers/go-digest" - "github.com/stretchr/testify/assert" ) func TestRestore(t *testing.T) { @@ -16,57 +16,57 @@ func TestRestore(t *testing.T) { defer cleanup() id1, err := fs.Set([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`)) - assert.NoError(t, err) + assert.NilError(t, err) _, err = fs.Set([]byte(`invalid`)) - assert.NoError(t, err) + assert.NilError(t, err) id2, err := fs.Set([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) - assert.NoError(t, err) + assert.NilError(t, err) err = fs.SetMetadata(id2, "parent", []byte(id1)) - assert.NoError(t, err) + assert.NilError(t, err) mlgrMap := make(map[string]LayerGetReleaser) mlgrMap[runtime.GOOS] = &mockLayerGetReleaser{} is, err := NewImageStore(fs, mlgrMap) - assert.NoError(t, err) + assert.NilError(t, err) - assert.Len(t, is.Map(), 2) + assert.Check(t, cmp.Len(is.Map(), 2)) img1, err := is.Get(ID(id1)) - assert.NoError(t, err) - assert.Equal(t, ID(id1), img1.computedID) - assert.Equal(t, string(id1), img1.computedID.String()) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(ID(id1), img1.computedID)) + assert.Check(t, cmp.Equal(string(id1), img1.computedID.String())) img2, err := is.Get(ID(id2)) - assert.NoError(t, err) - assert.Equal(t, "abc", img1.Comment) - assert.Equal(t, "def", img2.Comment) + assert.NilError(t, err) + assert.Check(t, cmp.Equal("abc", img1.Comment)) + assert.Check(t, cmp.Equal("def", img2.Comment)) _, err = is.GetParent(ID(id1)) - testutil.ErrorContains(t, err, "failed to read metadata") + assert.ErrorContains(t, err, "failed to read metadata") p, err := is.GetParent(ID(id2)) - assert.NoError(t, err) - assert.Equal(t, ID(id1), p) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(ID(id1), p)) children := is.Children(ID(id1)) - assert.Len(t, children, 1) - assert.Equal(t, ID(id2), children[0]) - assert.Len(t, is.Heads(), 1) + assert.Check(t, cmp.Len(children, 1)) + assert.Check(t, cmp.Equal(ID(id2), children[0])) + assert.Check(t, cmp.Len(is.Heads(), 1)) sid1, err := is.Search(string(id1)[:10]) - assert.NoError(t, err) - assert.Equal(t, ID(id1), sid1) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(ID(id1), sid1)) sid1, err = is.Search(digest.Digest(id1).Hex()[:6]) - assert.NoError(t, err) - assert.Equal(t, ID(id1), sid1) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(ID(id1), sid1)) invalidPattern := digest.Digest(id1).Hex()[1:6] _, err = is.Search(invalidPattern) - testutil.ErrorContains(t, err, "No such image") + assert.ErrorContains(t, err, "No such image") } func TestAddDelete(t *testing.T) { @@ -74,34 +74,34 @@ func TestAddDelete(t *testing.T) { defer cleanup() id1, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) - assert.NoError(t, err) - assert.Equal(t, ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(ID("sha256:8d25a9c45df515f9d0fe8e4a6b1c64dd3b965a84790ddbcc7954bb9bc89eb993"), id1)) img, err := is.Get(id1) - assert.NoError(t, err) - assert.Equal(t, "abc", img.Comment) + assert.NilError(t, err) + assert.Check(t, cmp.Equal("abc", img.Comment)) id2, err := is.Create([]byte(`{"comment": "def", "rootfs": {"type": "layers", "diff_ids": ["2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"]}}`)) - assert.NoError(t, err) + assert.NilError(t, err) err = is.SetParent(id2, id1) - assert.NoError(t, err) + assert.NilError(t, err) pid1, err := is.GetParent(id2) - assert.NoError(t, err) - assert.Equal(t, pid1, id1) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(pid1, id1)) _, err = is.Delete(id1) - assert.NoError(t, err) + assert.NilError(t, err) _, err = is.Get(id1) - testutil.ErrorContains(t, err, "failed to get digest") + assert.ErrorContains(t, err, "failed to get digest") _, err = is.Get(id2) - assert.NoError(t, err) + assert.NilError(t, err) _, err = is.GetParent(id2) - testutil.ErrorContains(t, err, "failed to read metadata") + assert.ErrorContains(t, err, "failed to read metadata") } func TestSearchAfterDelete(t *testing.T) { @@ -109,17 +109,17 @@ func TestSearchAfterDelete(t *testing.T) { defer cleanup() id, err := is.Create([]byte(`{"comment": "abc", "rootfs": {"type": "layers"}}`)) - assert.NoError(t, err) + assert.NilError(t, err) id1, err := is.Search(string(id)[:15]) - assert.NoError(t, err) - assert.Equal(t, id1, id) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(id1, id)) _, err = is.Delete(id) - assert.NoError(t, err) + assert.NilError(t, err) _, err = is.Search(string(id)[:15]) - testutil.ErrorContains(t, err, "No such image") + assert.ErrorContains(t, err, "No such image") } func TestParentReset(t *testing.T) { @@ -127,20 +127,20 @@ func TestParentReset(t *testing.T) { defer cleanup() id, err := is.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`)) - assert.NoError(t, err) + assert.NilError(t, err) id2, err := is.Create([]byte(`{"comment": "abc2", "rootfs": {"type": "layers"}}`)) - assert.NoError(t, err) + assert.NilError(t, err) id3, err := is.Create([]byte(`{"comment": "abc3", "rootfs": {"type": "layers"}}`)) - assert.NoError(t, err) + assert.NilError(t, err) - assert.NoError(t, is.SetParent(id, id2)) - assert.Len(t, is.Children(id2), 1) + assert.Check(t, is.SetParent(id, id2)) + assert.Check(t, cmp.Len(is.Children(id2), 1)) - assert.NoError(t, is.SetParent(id, id3)) - assert.Len(t, is.Children(id2), 0) - assert.Len(t, is.Children(id3), 1) + assert.Check(t, is.SetParent(id, id3)) + assert.Check(t, cmp.Len(is.Children(id2), 0)) + assert.Check(t, cmp.Len(is.Children(id3), 1)) } func defaultImageStore(t *testing.T) (Store, func()) { @@ -149,7 +149,7 @@ func defaultImageStore(t *testing.T) (Store, func()) { mlgrMap := make(map[string]LayerGetReleaser) mlgrMap[runtime.GOOS] = &mockLayerGetReleaser{} store, err := NewImageStore(fsBackend, mlgrMap) - assert.NoError(t, err) + assert.NilError(t, err) return store, cleanup } @@ -159,17 +159,17 @@ func TestGetAndSetLastUpdated(t *testing.T) { defer cleanup() id, err := store.Create([]byte(`{"comment": "abc1", "rootfs": {"type": "layers"}}`)) - assert.NoError(t, err) + assert.NilError(t, err) updated, err := store.GetLastUpdated(id) - assert.NoError(t, err) - assert.Equal(t, updated.IsZero(), true) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(updated.IsZero(), true)) - assert.NoError(t, store.SetLastUpdated(id)) + assert.Check(t, store.SetLastUpdated(id)) updated, err = store.GetLastUpdated(id) - assert.NoError(t, err) - assert.Equal(t, updated.IsZero(), false) + assert.NilError(t, err) + assert.Check(t, cmp.Equal(updated.IsZero(), false)) } func TestStoreLen(t *testing.T) { @@ -179,7 +179,7 @@ func TestStoreLen(t *testing.T) { expected := 10 for i := 0; i < expected; i++ { _, err := store.Create([]byte(fmt.Sprintf(`{"comment": "abc%d", "rootfs": {"type": "layers"}}`, i))) - assert.NoError(t, err) + assert.NilError(t, err) } numImages := store.Len() assert.Equal(t, expected, numImages) diff --git a/components/engine/integration-cli/cli/build/fakegit/fakegit.go b/components/engine/integration-cli/cli/build/fakegit/fakegit.go index eb175365a5..b05bfc322b 100644 --- a/components/engine/integration-cli/cli/build/fakegit/fakegit.go +++ b/components/engine/integration-cli/cli/build/fakegit/fakegit.go @@ -11,11 +11,11 @@ import ( "github.com/docker/docker/integration-cli/cli/build/fakecontext" "github.com/docker/docker/integration-cli/cli/build/fakestorage" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) type testingT interface { - require.TestingT + assert.TestingT logT Fatal(args ...interface{}) Fatalf(string, ...interface{}) diff --git a/components/engine/integration-cli/cli/build/fakestorage/storage.go b/components/engine/integration-cli/cli/build/fakestorage/storage.go index c8c837ed2a..bd49a33cfe 100644 --- a/components/engine/integration-cli/cli/build/fakestorage/storage.go +++ b/components/engine/integration-cli/cli/build/fakestorage/storage.go @@ -15,13 +15,13 @@ import ( "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/internal/test/environment" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) var testEnv *environment.Execution type testingT interface { - require.TestingT + assert.TestingT logT Fatal(args ...interface{}) Fatalf(string, ...interface{}) diff --git a/components/engine/integration-cli/cli/cli.go b/components/engine/integration-cli/cli/cli.go index eb03b2dd81..17f3fd52ca 100644 --- a/components/engine/integration-cli/cli/cli.go +++ b/components/engine/integration-cli/cli/cli.go @@ -8,6 +8,7 @@ import ( "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration-cli/environment" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/icmd" "github.com/pkg/errors" ) @@ -24,6 +25,7 @@ func SetTestEnvironment(env *environment.Execution) { type CmdOperator func(*icmd.Cmd) func() type testingT interface { + assert.TestingT Fatal(args ...interface{}) Fatalf(string, ...interface{}) } diff --git a/components/engine/integration-cli/daemon/daemon.go b/components/engine/integration-cli/daemon/daemon.go index 9672d160f8..9ca54236f4 100644 --- a/components/engine/integration-cli/daemon/daemon.go +++ b/components/engine/integration-cli/daemon/daemon.go @@ -24,14 +24,14 @@ import ( "github.com/docker/go-connections/sockets" "github.com/docker/go-connections/tlsconfig" "github.com/go-check/check" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/icmd" "github.com/pkg/errors" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) type testingT interface { - require.TestingT + assert.TestingT logT Fatalf(string, ...interface{}) } @@ -487,20 +487,20 @@ func (d *Daemon) handleUserns() { // LoadBusybox image into the daemon func (d *Daemon) LoadBusybox(t testingT) { clientHost, err := client.NewEnvClient() - require.NoError(t, err, "failed to create client") + assert.NilError(t, err, "failed to create client") defer clientHost.Close() ctx := context.Background() reader, err := clientHost.ImageSave(ctx, []string{"busybox:latest"}) - require.NoError(t, err, "failed to download busybox") + assert.NilError(t, err, "failed to download busybox") defer reader.Close() client, err := d.NewClient() - require.NoError(t, err, "failed to create client") + assert.NilError(t, err, "failed to create client") defer client.Close() resp, err := client.ImageLoad(ctx, reader, true) - require.NoError(t, err, "failed to load busybox") + assert.NilError(t, err, "failed to load busybox") defer resp.Body.Close() } @@ -563,11 +563,11 @@ func (d *Daemon) WaitRun(contID string) error { } // Info returns the info struct for this daemon -func (d *Daemon) Info(t require.TestingT) types.Info { +func (d *Daemon) Info(t assert.TestingT) types.Info { apiclient, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) info, err := apiclient.Info(context.Background()) - require.NoError(t, err) + assert.NilError(t, err) return info } diff --git a/components/engine/integration-cli/daemon/daemon_swarm.go b/components/engine/integration-cli/daemon/daemon_swarm.go index cb44f63f23..be0ddef99e 100644 --- a/components/engine/integration-cli/daemon/daemon_swarm.go +++ b/components/engine/integration-cli/daemon/daemon_swarm.go @@ -11,8 +11,8 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" + "github.com/gotestyourself/gotestyourself/assert" "github.com/pkg/errors" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -235,12 +235,12 @@ func (d *Swarm) CheckServiceUpdateState(service string) func(*check.C) (interfac func (d *Swarm) CheckPluginRunning(plugin string) func(c *check.C) (interface{}, check.CommentInterface) { return func(c *check.C) (interface{}, check.CommentInterface) { apiclient, err := d.NewClient() - require.NoError(c, err) + assert.NilError(c, err) resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin) if client.IsErrNotFound(err) { return false, check.Commentf("%v", err) } - require.NoError(c, err) + assert.NilError(c, err) return resp.Enabled, check.Commentf("%+v", resp) } } @@ -249,12 +249,12 @@ func (d *Swarm) CheckPluginRunning(plugin string) func(c *check.C) (interface{}, func (d *Swarm) CheckPluginImage(plugin string) func(c *check.C) (interface{}, check.CommentInterface) { return func(c *check.C) (interface{}, check.CommentInterface) { apiclient, err := d.NewClient() - require.NoError(c, err) + assert.NilError(c, err) resp, _, err := apiclient.PluginInspectWithRaw(context.Background(), plugin) if client.IsErrNotFound(err) { return false, check.Commentf("%v", err) } - require.NoError(c, err) + assert.NilError(c, err) return resp.PluginReference, check.Commentf("%+v", resp) } } diff --git a/components/engine/integration-cli/docker_api_build_test.go b/components/engine/integration-cli/docker_api_build_test.go index e5423a4741..cae7c1afe7 100644 --- a/components/engine/integration-cli/docker_api_build_test.go +++ b/components/engine/integration-cli/docker_api_build_test.go @@ -18,10 +18,10 @@ import ( "github.com/docker/docker/integration-cli/cli/build/fakestorage" "github.com/docker/docker/integration-cli/request" "github.com/go-check/check" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/moby/buildkit/session" "github.com/moby/buildkit/session/filesync" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" "golang.org/x/sync/errgroup" ) @@ -296,12 +296,12 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) { "/build", request.RawContent(ctx.AsTarReader(c)), request.ContentType("application/x-tar")) - require.NoError(c, err) - assert.Equal(c, http.StatusOK, res.StatusCode) + assert.NilError(c, err) + assert.Check(c, is.DeepEqual(http.StatusOK, res.StatusCode)) out, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(out), "Successfully built") + assert.NilError(c, err) + assert.Check(c, is.Contains(string(out), "Successfully built")) return out } @@ -316,15 +316,15 @@ func (s *DockerSuite) TestBuildOnBuildCache(c *check.C) { out := build(dockerfile) imageIDs := getImageIDsFromBuild(c, out) - assert.Len(c, imageIDs, 2) + assert.Check(c, is.Len(imageIDs, 2)) parentID, childID := imageIDs[0], imageIDs[1] client := testEnv.APIClient() // check parentID is correct image, _, err := client.ImageInspectWithRaw(context.Background(), childID) - require.NoError(c, err) - assert.Equal(c, parentID, image.Parent) + assert.NilError(c, err) + assert.Check(c, is.Equal(parentID, image.Parent)) } func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) { @@ -333,12 +333,12 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) { repoName := fmt.Sprintf("%v/dockercli/busybox", privateRegistryURL) // tag the image to upload it to the private registry err := client.ImageTag(context.TODO(), "busybox", repoName) - assert.Nil(c, err) + assert.Check(c, err) // push the image to the registry rc, err := client.ImagePush(context.TODO(), repoName, types.ImagePushOptions{RegistryAuth: "{}"}) - assert.Nil(c, err) + assert.Check(c, err) _, err = io.Copy(ioutil.Discard, rc) - assert.Nil(c, err) + assert.Check(c, err) dockerfile := fmt.Sprintf(` FROM %s AS foo @@ -356,12 +356,12 @@ func (s *DockerRegistrySuite) TestBuildCopyFromForcePull(c *check.C) { "/build?pull=1", request.RawContent(ctx.AsTarReader(c)), request.ContentType("application/x-tar")) - require.NoError(c, err) - assert.Equal(c, http.StatusOK, res.StatusCode) + assert.NilError(c, err) + assert.Check(c, is.DeepEqual(http.StatusOK, res.StatusCode)) out, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(out), "Successfully built") + assert.NilError(c, err) + assert.Check(c, is.Contains(string(out), "Successfully built")) } func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) { @@ -374,11 +374,11 @@ func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) { Mode: 0600, Typeflag: tar.TypeReg, }) - require.NoError(c, err) + assert.NilError(c, err) _, err = tw.Write(dt) - require.NoError(c, err) + assert.NilError(c, err) err = tw.Close() - require.NoError(c, err) + assert.NilError(c, err) server := fakestorage.New(c, "", fakecontext.WithBinaryFiles(map[string]*bytes.Buffer{ "test.tar": buffer, @@ -400,12 +400,12 @@ func (s *DockerSuite) TestBuildAddRemoteNoDecompress(c *check.C) { "/build", request.RawContent(ctx.AsTarReader(c)), request.ContentType("application/x-tar")) - require.NoError(c, err) - assert.Equal(c, http.StatusOK, res.StatusCode) + assert.NilError(c, err) + assert.Check(c, is.DeepEqual(http.StatusOK, res.StatusCode)) out, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(out), "Successfully built") + assert.NilError(c, err) + assert.Check(c, is.Contains(string(out), "Successfully built")) } func (s *DockerSuite) TestBuildChownOnCopy(c *check.C) { @@ -433,8 +433,8 @@ func (s *DockerSuite) TestBuildChownOnCopy(c *check.C) { c.Assert(res.StatusCode, checker.Equals, http.StatusOK) out, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(out), "Successfully built") + assert.NilError(c, err) + assert.Check(c, is.Contains(string(out), "Successfully built")) } func (s *DockerSuite) TestBuildCopyCacheOnFileChange(c *check.C) { @@ -454,11 +454,11 @@ COPY file /file` request.RawContent(ctx.AsTarReader(c)), request.ContentType("application/x-tar")) - require.NoError(c, err) - assert.Equal(c, http.StatusOK, res.StatusCode) + assert.NilError(c, err) + assert.Check(c, is.DeepEqual(http.StatusOK, res.StatusCode)) out, err := request.ReadBody(body) - require.NoError(c, err) + assert.NilError(c, err) ids := getImageIDsFromBuild(c, out) return ids[len(ids)-1] @@ -493,11 +493,11 @@ ADD file /file` request.RawContent(ctx.AsTarReader(c)), request.ContentType("application/x-tar")) - require.NoError(c, err) - assert.Equal(c, http.StatusOK, res.StatusCode) + assert.NilError(c, err) + assert.Check(c, is.DeepEqual(http.StatusOK, res.StatusCode)) out, err := request.ReadBody(body) - require.NoError(c, err) + assert.NilError(c, err) ids := getImageIDsFromBuild(c, out) return ids[len(ids)-1] @@ -530,7 +530,7 @@ func (s *DockerSuite) TestBuildWithSession(c *check.C) { defer fctx.Close() out := testBuildWithSession(c, fctx.Dir, dockerfile) - assert.Contains(c, out, "some content") + assert.Check(c, is.Contains(out, "some content")) fctx.Add("second", "contentcontent") @@ -540,20 +540,20 @@ func (s *DockerSuite) TestBuildWithSession(c *check.C) { ` out = testBuildWithSession(c, fctx.Dir, dockerfile) - assert.Equal(c, strings.Count(out, "Using cache"), 2) - assert.Contains(c, out, "contentcontent") + assert.Check(c, is.Equal(strings.Count(out, "Using cache"), 2)) + assert.Check(c, is.Contains(out, "contentcontent")) client := testEnv.APIClient() du, err := client.DiskUsage(context.TODO()) - assert.Nil(c, err) - assert.True(c, du.BuilderSize > 10) + assert.Check(c, err) + assert.Check(c, du.BuilderSize > 10) out = testBuildWithSession(c, fctx.Dir, dockerfile) - assert.Equal(c, strings.Count(out, "Using cache"), 4) + assert.Check(c, is.Equal(strings.Count(out, "Using cache"), 4)) du2, err := client.DiskUsage(context.TODO()) - assert.Nil(c, err) - assert.Equal(c, du.BuilderSize, du2.BuilderSize) + assert.Check(c, err) + assert.Check(c, is.Equal(du.BuilderSize, du2.BuilderSize)) // rebuild with regular tar, confirm cache still applies fctx.Add("Dockerfile", dockerfile) @@ -561,26 +561,26 @@ func (s *DockerSuite) TestBuildWithSession(c *check.C) { "/build", request.RawContent(fctx.AsTarReader(c)), request.ContentType("application/x-tar")) - require.NoError(c, err) - assert.Equal(c, http.StatusOK, res.StatusCode) + assert.NilError(c, err) + assert.Check(c, is.DeepEqual(http.StatusOK, res.StatusCode)) outBytes, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(outBytes), "Successfully built") - assert.Equal(c, strings.Count(string(outBytes), "Using cache"), 4) + assert.NilError(c, err) + assert.Check(c, is.Contains(string(outBytes), "Successfully built")) + assert.Check(c, is.Equal(strings.Count(string(outBytes), "Using cache"), 4)) _, err = client.BuildCachePrune(context.TODO()) - assert.Nil(c, err) + assert.Check(c, err) du, err = client.DiskUsage(context.TODO()) - assert.Nil(c, err) - assert.Equal(c, du.BuilderSize, int64(0)) + assert.Check(c, err) + assert.Check(c, is.Equal(du.BuilderSize, int64(0))) } func testBuildWithSession(c *check.C, dir, dockerfile string) (outStr string) { client := testEnv.APIClient() sess, err := session.NewSession("foo1", "foo") - assert.Nil(c, err) + assert.Check(c, err) fsProvider := filesync.NewFSSyncProvider([]filesync.SyncedDir{ {Dir: dir}, @@ -601,17 +601,17 @@ func testBuildWithSession(c *check.C, dir, dockerfile string) (outStr string) { if err != nil { return err } - assert.Equal(c, res.StatusCode, http.StatusOK) + assert.Check(c, is.DeepEqual(res.StatusCode, http.StatusOK)) out, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(out), "Successfully built") + assert.NilError(c, err) + assert.Check(c, is.Contains(string(out), "Successfully built")) sess.Close() outStr = string(out) return nil }) err = g.Wait() - assert.Nil(c, err) + assert.Check(c, err) return } @@ -633,8 +633,8 @@ ENV foo bar` c.Assert(res.StatusCode, checker.Equals, http.StatusOK) out, err := request.ReadBody(body) - require.NoError(c, err) - assert.Contains(c, string(out), "Successfully built") + assert.NilError(c, err) + assert.Check(c, is.Contains(string(out), "Successfully built")) } type buildLine struct { @@ -651,7 +651,7 @@ func getImageIDsFromBuild(c *check.C, output []byte) []string { continue } entry := buildLine{} - require.NoError(c, json.Unmarshal(line, &entry)) + assert.NilError(c, json.Unmarshal(line, &entry)) if entry.Aux.ID != "" { ids = append(ids, entry.Aux.ID) } diff --git a/components/engine/integration-cli/docker_api_containers_test.go b/components/engine/integration-cli/docker_api_containers_test.go index ed1941022e..c0e5ff5b17 100644 --- a/components/engine/integration-cli/docker_api_containers_test.go +++ b/components/engine/integration-cli/docker_api_containers_test.go @@ -31,9 +31,9 @@ import ( "github.com/docker/docker/volume" "github.com/docker/go-connections/nat" "github.com/go-check/check" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -2027,47 +2027,47 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { &containertypes.HostConfig{Mounts: []mounttypes.Mount{x.spec}}, &networktypes.NetworkingConfig{}, "") - require.NoError(c, err) + assert.NilError(c, err) containerInspect, err := apiclient.ContainerInspect(ctx, container.ID) - require.NoError(c, err) + assert.NilError(c, err) mps := containerInspect.Mounts - require.Len(c, mps, 1) + assert.Assert(c, is.Len(mps, 1)) mountPoint := mps[0] if x.expected.Source != "" { - assert.Equal(c, x.expected.Source, mountPoint.Source) + assert.Check(c, is.Equal(x.expected.Source, mountPoint.Source)) } if x.expected.Name != "" { - assert.Equal(c, x.expected.Name, mountPoint.Name) + assert.Check(c, is.Equal(x.expected.Name, mountPoint.Name)) } if x.expected.Driver != "" { - assert.Equal(c, x.expected.Driver, mountPoint.Driver) + assert.Check(c, is.Equal(x.expected.Driver, mountPoint.Driver)) } if x.expected.Propagation != "" { - assert.Equal(c, x.expected.Propagation, mountPoint.Propagation) + assert.Check(c, is.Equal(x.expected.Propagation, mountPoint.Propagation)) } - assert.Equal(c, x.expected.RW, mountPoint.RW) - assert.Equal(c, x.expected.Type, mountPoint.Type) - assert.Equal(c, x.expected.Mode, mountPoint.Mode) - assert.Equal(c, x.expected.Destination, mountPoint.Destination) + assert.Check(c, is.Equal(x.expected.RW, mountPoint.RW)) + assert.Check(c, is.Equal(x.expected.Type, mountPoint.Type)) + assert.Check(c, is.Equal(x.expected.Mode, mountPoint.Mode)) + assert.Check(c, is.Equal(x.expected.Destination, mountPoint.Destination)) err = apiclient.ContainerStart(ctx, container.ID, types.ContainerStartOptions{}) - require.NoError(c, err) + assert.NilError(c, err) poll.WaitOn(c, containerExit(apiclient, container.ID), poll.WithDelay(time.Second)) err = apiclient.ContainerRemove(ctx, container.ID, types.ContainerRemoveOptions{ RemoveVolumes: true, Force: true, }) - require.NoError(c, err) + assert.NilError(c, err) switch { // Named volumes still exist after the container is removed case x.spec.Type == "volume" && len(x.spec.Source) > 0: _, err := apiclient.VolumeInspect(ctx, mountPoint.Name) - require.NoError(c, err) + assert.NilError(c, err) // Bind mounts are never removed with the container case x.spec.Type == "bind": @@ -2075,7 +2075,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) { // anonymous volumes are removed default: _, err := apiclient.VolumeInspect(ctx, mountPoint.Name) - assert.True(c, client.IsErrNotFound(err)) + assert.Check(c, client.IsErrNotFound(err)) } } } diff --git a/components/engine/integration-cli/docker_api_containers_windows_test.go b/components/engine/integration-cli/docker_api_containers_windows_test.go index eb2892575c..4c8ace4842 100644 --- a/components/engine/integration-cli/docker_api_containers_windows_test.go +++ b/components/engine/integration-cli/docker_api_containers_windows_test.go @@ -13,8 +13,8 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/mount" "github.com/go-check/check" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -65,12 +65,12 @@ func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *check.C) { }, }, nil, name) - require.NoError(c, err) + assert.NilError(c, err) err = client.ContainerStart(ctx, name, types.ContainerStartOptions{}) - require.NoError(c, err) + assert.NilError(c, err) err = <-ch - require.NoError(c, err) - assert.Equal(c, text, strings.TrimSpace(string(b))) + assert.NilError(c, err) + assert.Check(c, is.Equal(text, strings.TrimSpace(string(b)))) } diff --git a/components/engine/integration-cli/docker_api_inspect_test.go b/components/engine/integration-cli/docker_api_inspect_test.go index 52a889f08b..2f81d6e1eb 100644 --- a/components/engine/integration-cli/docker_api_inspect_test.go +++ b/components/engine/integration-cli/docker_api_inspect_test.go @@ -11,7 +11,8 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/checker" "github.com/go-check/check" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func (s *DockerSuite) TestInspectAPIContainerResponse(c *check.C) { @@ -115,8 +116,8 @@ func (s *DockerSuite) TestInspectAPIImageResponse(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(imageJSON.RepoTags, checker.HasLen, 2) - assert.Contains(c, imageJSON.RepoTags, "busybox:latest") - assert.Contains(c, imageJSON.RepoTags, "busybox:mytag") + assert.Check(c, is.Contains(imageJSON.RepoTags, "busybox:latest")) + assert.Check(c, is.Contains(imageJSON.RepoTags, "busybox:mytag")) } // #17131, #17139, #17173 diff --git a/components/engine/integration-cli/docker_api_swarm_test.go b/components/engine/integration-cli/docker_api_swarm_test.go index b5edfd2c04..2ba69acdb8 100644 --- a/components/engine/integration-cli/docker_api_swarm_test.go +++ b/components/engine/integration-cli/docker_api_swarm_test.go @@ -25,8 +25,8 @@ import ( "github.com/docker/docker/integration-cli/request" "github.com/docker/swarmkit/ca" "github.com/go-check/check" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -1012,16 +1012,16 @@ func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *check.C) { name := "test-scoped-network" ctx := context.Background() apiclient, err := d.NewClient() - require.NoError(c, err) + assert.NilError(c, err) resp, err := apiclient.NetworkCreate(ctx, name, types.NetworkCreate{Driver: "overlay"}) - require.NoError(c, err) + assert.NilError(c, err) network, err := apiclient.NetworkInspect(ctx, name, types.NetworkInspectOptions{}) - require.NoError(c, err) - assert.Equal(c, "swarm", network.Scope) - assert.Equal(c, resp.ID, network.ID) + assert.NilError(c, err) + assert.Check(c, is.Equal("swarm", network.Scope)) + assert.Check(c, is.Equal(resp.ID, network.ID)) _, err = apiclient.NetworkInspect(ctx, name, types.NetworkInspectOptions{Scope: "local"}) - assert.True(c, client.IsErrNotFound(err)) + assert.Check(c, client.IsErrNotFound(err)) } diff --git a/components/engine/integration-cli/docker_cli_by_digest_test.go b/components/engine/integration-cli/docker_cli_by_digest_test.go index 2d5dd486e7..ac97e0aecc 100644 --- a/components/engine/integration-cli/docker_cli_by_digest_test.go +++ b/components/engine/integration-cli/docker_cli_by_digest_test.go @@ -15,8 +15,9 @@ import ( "github.com/docker/docker/integration-cli/cli" "github.com/docker/docker/integration-cli/cli/build" "github.com/go-check/check" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/opencontainers/go-digest" - "github.com/stretchr/testify/assert" ) var ( @@ -403,7 +404,7 @@ func (s *DockerRegistrySuite) TestInspectImageWithDigests(c *check.C) { c.Assert(err, checker.IsNil) c.Assert(imageJSON, checker.HasLen, 1) c.Assert(imageJSON[0].RepoDigests, checker.HasLen, 1) - assert.Contains(c, imageJSON[0].RepoDigests, imageReference) + assert.Check(c, is.Contains(imageJSON[0].RepoDigests, imageReference)) } func (s *DockerRegistrySuite) TestPsListContainersFilterAncestorImageByDigest(c *check.C) { diff --git a/components/engine/integration/build/build_test.go b/components/engine/integration/build/build_test.go index 124f1107fb..9d396da865 100644 --- a/components/engine/integration/build/build_test.go +++ b/components/engine/integration/build/build_test.go @@ -15,8 +15,8 @@ import ( "github.com/docker/docker/integration-cli/cli/build/fakecontext" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/pkg/jsonmessage" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestBuildWithRemoveAndForceRemove(t *testing.T) { @@ -94,21 +94,21 @@ func TestBuildWithRemoveAndForceRemove(t *testing.T) { buff := bytes.NewBuffer(nil) tw := tar.NewWriter(buff) - require.NoError(t, tw.WriteHeader(&tar.Header{ + assert.NilError(t, tw.WriteHeader(&tar.Header{ Name: "Dockerfile", Size: int64(len(dockerfile)), })) _, err := tw.Write(dockerfile) - require.NoError(t, err) - require.NoError(t, tw.Close()) + assert.NilError(t, err) + assert.NilError(t, tw.Close()) resp, err := client.ImageBuild(ctx, buff, types.ImageBuildOptions{Remove: c.rm, ForceRemove: c.forceRm, NoCache: true}) - require.NoError(t, err) + assert.NilError(t, err) defer resp.Body.Close() filter, err := buildContainerIdsFilter(resp.Body) - require.NoError(t, err) + assert.NilError(t, err) remainingContainers, err := client.ContainerList(ctx, types.ContainerListOptions{Filters: filter, All: true}) - require.NoError(t, err) - require.Equal(t, c.numberOfIntermediateContainers, len(remainingContainers), "Expected %v remaining intermediate containers, got %v", c.numberOfIntermediateContainers, len(remainingContainers)) + assert.NilError(t, err) + assert.Equal(t, c.numberOfIntermediateContainers, len(remainingContainers), "Expected %v remaining intermediate containers, got %v", c.numberOfIntermediateContainers, len(remainingContainers)) }) } } @@ -158,16 +158,16 @@ func TestBuildMultiStageParentConfig(t *testing.T) { ForceRemove: true, Tags: []string{"build1"}, }) - require.NoError(t, err) + assert.NilError(t, err) _, err = io.Copy(ioutil.Discard, resp.Body) resp.Body.Close() - require.NoError(t, err) + assert.NilError(t, err) image, _, err := apiclient.ImageInspectWithRaw(ctx, "build1") - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, "/foo/sub2", image.Config.WorkingDir) - assert.Contains(t, image.Config.Env, "WHO=parent") + assert.Check(t, is.Equal("/foo/sub2", image.Config.WorkingDir)) + assert.Check(t, is.Contains(image.Config.Env, "WHO=parent")) } func TestBuildWithEmptyLayers(t *testing.T) { @@ -192,10 +192,10 @@ func TestBuildWithEmptyLayers(t *testing.T) { Remove: true, ForceRemove: true, }) - require.NoError(t, err) + assert.NilError(t, err) _, err = io.Copy(ioutil.Discard, resp.Body) resp.Body.Close() - require.NoError(t, err) + assert.NilError(t, err) } // TestBuildMultiStageOnBuild checks that ONBUILD commands are applied to @@ -228,20 +228,20 @@ RUN cat somefile` }) out := bytes.NewBuffer(nil) - require.NoError(t, err) + assert.NilError(t, err) _, err = io.Copy(out, resp.Body) resp.Body.Close() - require.NoError(t, err) + assert.NilError(t, err) - assert.Contains(t, out.String(), "Successfully built") + assert.Check(t, is.Contains(out.String(), "Successfully built")) imageIDs, err := getImageIDsFromBuild(out.Bytes()) - require.NoError(t, err) - assert.Equal(t, 3, len(imageIDs)) + assert.NilError(t, err) + assert.Check(t, is.Equal(3, len(imageIDs))) image, _, err := apiclient.ImageInspectWithRaw(context.Background(), imageIDs[2]) - require.NoError(t, err) - assert.Contains(t, image.Config.Env, "bar=baz") + assert.NilError(t, err) + assert.Check(t, is.Contains(image.Config.Env, "bar=baz")) } // #35403 #36122 @@ -260,7 +260,7 @@ COPY bar /` writeTarRecord(t, w, "../foo", "foocontents0") writeTarRecord(t, w, "/bar", "barcontents0") err := w.Close() - require.NoError(t, err) + assert.NilError(t, err) apiclient := testEnv.APIClient() resp, err := apiclient.ImageBuild(ctx, @@ -271,10 +271,10 @@ COPY bar /` }) out := bytes.NewBuffer(nil) - require.NoError(t, err) + assert.NilError(t, err) _, err = io.Copy(out, resp.Body) resp.Body.Close() - require.NoError(t, err) + assert.NilError(t, err) // repeat with changed data should not cause cache hits @@ -284,7 +284,7 @@ COPY bar /` writeTarRecord(t, w, "../foo", "foocontents1") writeTarRecord(t, w, "/bar", "barcontents1") err = w.Close() - require.NoError(t, err) + assert.NilError(t, err) resp, err = apiclient.ImageBuild(ctx, buf, @@ -294,11 +294,11 @@ COPY bar /` }) out = bytes.NewBuffer(nil) - require.NoError(t, err) + assert.NilError(t, err) _, err = io.Copy(out, resp.Body) resp.Body.Close() - require.NoError(t, err) - require.NotContains(t, out.String(), "Using cache") + assert.NilError(t, err) + assert.Assert(t, !strings.Contains(out.String(), "Using cache")) } // docker/for-linux#135 @@ -333,12 +333,12 @@ RUN [ ! -f foo ] }) out := bytes.NewBuffer(nil) - require.NoError(t, err) + assert.NilError(t, err) _, err = io.Copy(out, resp.Body) resp.Body.Close() - require.NoError(t, err) + assert.NilError(t, err) - assert.Contains(t, out.String(), "Successfully built") + assert.Check(t, is.Contains(out.String(), "Successfully built")) } func writeTarRecord(t *testing.T, w *tar.Writer, fn, contents string) { @@ -348,9 +348,9 @@ func writeTarRecord(t *testing.T, w *tar.Writer, fn, contents string) { Size: int64(len(contents)), Typeflag: '0', }) - require.NoError(t, err) + assert.NilError(t, err) _, err = w.Write([]byte(contents)) - require.NoError(t, err) + assert.NilError(t, err) } type buildLine struct { diff --git a/components/engine/integration/config/config_test.go b/components/engine/integration/config/config_test.go index 912f55a12a..65323e2e59 100644 --- a/components/engine/integration/config/config_test.go +++ b/components/engine/integration/config/config_test.go @@ -14,9 +14,9 @@ import ( "github.com/docker/docker/integration/internal/swarm" "github.com/docker/docker/internal/testutil" "github.com/docker/docker/pkg/stdcopy" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -27,14 +27,14 @@ func TestConfigList(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() // This test case is ported from the original TestConfigsEmptyList configs, err := client.ConfigList(ctx, types.ConfigListOptions{}) - require.NoError(t, err) - assert.Equal(t, len(configs), 0) + assert.NilError(t, err) + assert.Check(t, is.Equal(len(configs), 0)) testName0 := "test0" testName1 := "test1" @@ -57,8 +57,8 @@ func TestConfigList(t *testing.T) { // test by `config ls` entries, err := client.ConfigList(ctx, types.ConfigListOptions{}) - require.NoError(t, err) - assert.Equal(t, names(entries), testNames) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(names(entries), testNames)) testCases := []struct { filters filters.Args @@ -92,8 +92,8 @@ func TestConfigList(t *testing.T) { entries, err = client.ConfigList(ctx, types.ConfigListOptions{ Filters: tc.filters, }) - require.NoError(t, err) - assert.Equal(t, names(entries), tc.expected) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(names(entries), tc.expected)) } } @@ -106,8 +106,8 @@ func createConfig(ctx context.Context, t *testing.T, client client.APIClient, na }, Data: data, }) - require.NoError(t, err) - assert.NotEqual(t, config.ID, "") + assert.NilError(t, err) + assert.Check(t, config.ID != "") return config.ID } @@ -118,7 +118,7 @@ func TestConfigsCreateAndDelete(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -128,12 +128,12 @@ func TestConfigsCreateAndDelete(t *testing.T) { configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) insp, _, err := client.ConfigInspectWithRaw(ctx, configID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Name, testName) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) // This test case is ported from the original TestConfigsDelete err = client.ConfigRemove(ctx, configID) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.ConfigInspectWithRaw(ctx, configID) testutil.ErrorContains(t, err, "No such config") @@ -146,7 +146,7 @@ func TestConfigsUpdate(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -156,35 +156,35 @@ func TestConfigsUpdate(t *testing.T) { configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) insp, _, err := client.ConfigInspectWithRaw(ctx, configID) - require.NoError(t, err) - assert.Equal(t, insp.ID, configID) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.ID, configID)) // test UpdateConfig with full ID insp.Spec.Labels = map[string]string{"test": "test1"} err = client.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.ConfigInspectWithRaw(ctx, configID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Labels["test"], "test1") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test1")) // test UpdateConfig with full name insp.Spec.Labels = map[string]string{"test": "test2"} err = client.ConfigUpdate(ctx, testName, insp.Version, insp.Spec) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.ConfigInspectWithRaw(ctx, configID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Labels["test"], "test2") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test2")) // test UpdateConfig with prefix ID insp.Spec.Labels = map[string]string{"test": "test3"} err = client.ConfigUpdate(ctx, configID[:1], insp.Version, insp.Spec) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.ConfigInspectWithRaw(ctx, configID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Labels["test"], "test3") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test3")) // test UpdateConfig in updating Data which is not supported in daemon // this test will produce an error in func UpdateConfig @@ -207,7 +207,7 @@ func TestTemplatedConfig(t *testing.T) { Data: []byte("this is a secret"), } referencedSecret, err := client.SecretCreate(ctx, referencedSecretSpec) - assert.NoError(t, err) + assert.Check(t, err) referencedConfigSpec := swarmtypes.ConfigSpec{ Annotations: swarmtypes.Annotations{ @@ -216,7 +216,7 @@ func TestTemplatedConfig(t *testing.T) { Data: []byte("this is a config"), } referencedConfig, err := client.ConfigCreate(ctx, referencedConfigSpec) - assert.NoError(t, err) + assert.Check(t, err) configSpec := swarmtypes.ConfigSpec{ Annotations: swarmtypes.Annotations{ @@ -231,7 +231,7 @@ func TestTemplatedConfig(t *testing.T) { } templatedConfig, err := client.ConfigCreate(ctx, configSpec) - assert.NoError(t, err) + assert.Check(t, err) serviceID := swarm.CreateService(t, d, swarm.ServiceWithConfig( @@ -309,8 +309,8 @@ func TestTemplatedConfig(t *testing.T) { func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) { buf := bytes.NewBuffer(nil) _, err := stdcopy.StdCopy(buf, buf, attach.Reader) - require.NoError(t, err) - assert.Contains(t, buf.String(), expect) + assert.NilError(t, err) + assert.Check(t, is.Contains(buf.String(), expect)) } func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool) { @@ -336,7 +336,7 @@ func TestConfigInspect(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -344,11 +344,11 @@ func TestConfigInspect(t *testing.T) { configID := createConfig(ctx, t, client, testName, []byte("TESTINGDATA"), nil) insp, body, err := client.ConfigInspectWithRaw(ctx, configID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Name, testName) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) var config swarmtypes.Config err = json.Unmarshal(body, &config) - require.NoError(t, err) - assert.Equal(t, config, insp) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(config, insp)) } diff --git a/components/engine/integration/container/copy_test.go b/components/engine/integration/container/copy_test.go index 43dc31f2f2..766c0a1762 100644 --- a/components/engine/integration/container/copy_test.go +++ b/components/engine/integration/container/copy_test.go @@ -9,8 +9,9 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/require" ) func TestCopyFromContainerPathDoesNotExist(t *testing.T) { @@ -21,7 +22,7 @@ func TestCopyFromContainerPathDoesNotExist(t *testing.T) { cid := container.Create(t, ctx, apiclient) _, _, err := apiclient.CopyFromContainer(ctx, cid, "/dne") - require.True(t, client.IsErrNotFound(err)) + assert.Assert(t, client.IsErrNotFound(err)) expected := fmt.Sprintf("No such container:path: %s:%s", cid, "/dne") testutil.ErrorContains(t, err, expected) } @@ -35,7 +36,7 @@ func TestCopyFromContainerPathIsNotDir(t *testing.T) { cid := container.Create(t, ctx, apiclient) _, _, err := apiclient.CopyFromContainer(ctx, cid, "/etc/passwd/") - require.Contains(t, err.Error(), "not a directory") + assert.Assert(t, is.Contains(err.Error(), "not a directory")) } func TestCopyToContainerPathDoesNotExist(t *testing.T) { @@ -47,7 +48,7 @@ func TestCopyToContainerPathDoesNotExist(t *testing.T) { cid := container.Create(t, ctx, apiclient) err := apiclient.CopyToContainer(ctx, cid, "/dne", nil, types.CopyToContainerOptions{}) - require.True(t, client.IsErrNotFound(err)) + assert.Assert(t, client.IsErrNotFound(err)) expected := fmt.Sprintf("No such container:path: %s:%s", cid, "/dne") testutil.ErrorContains(t, err, expected) } @@ -61,5 +62,5 @@ func TestCopyToContainerPathIsNotDir(t *testing.T) { cid := container.Create(t, ctx, apiclient) err := apiclient.CopyToContainer(ctx, cid, "/etc/passwd/", nil, types.CopyToContainerOptions{}) - require.Contains(t, err.Error(), "not a directory") + assert.Assert(t, is.Contains(err.Error(), "not a directory")) } diff --git a/components/engine/integration/container/daemon_linux_test.go b/components/engine/integration/container/daemon_linux_test.go index 5077770f53..c2920502e3 100644 --- a/components/engine/integration/container/daemon_linux_test.go +++ b/components/engine/integration/container/daemon_linux_test.go @@ -11,8 +11,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/integration/internal/container" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" "golang.org/x/sys/unix" ) @@ -35,7 +35,7 @@ func TestContainerStartOnDaemonRestart(t *testing.T) { defer d.Stop(t) client, err := d.NewClient() - assert.NoError(t, err, "error creating client") + assert.Check(t, err, "error creating client") ctx := context.Background() @@ -43,36 +43,36 @@ func TestContainerStartOnDaemonRestart(t *testing.T) { defer client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true}) err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{}) - assert.NoError(t, err, "error starting test container") + assert.Check(t, err, "error starting test container") inspect, err := client.ContainerInspect(ctx, cID) - assert.NoError(t, err, "error getting inspect data") + assert.Check(t, err, "error getting inspect data") ppid := getContainerdShimPid(t, inspect) err = d.Kill() - assert.NoError(t, err, "failed to kill test daemon") + assert.Check(t, err, "failed to kill test daemon") err = unix.Kill(inspect.State.Pid, unix.SIGKILL) - assert.NoError(t, err, "failed to kill container process") + assert.Check(t, err, "failed to kill container process") err = unix.Kill(ppid, unix.SIGKILL) - assert.NoError(t, err, "failed to kill containerd-shim") + assert.Check(t, err, "failed to kill containerd-shim") d.Start(t, "--iptables=false") err = client.ContainerStart(ctx, cID, types.ContainerStartOptions{}) - assert.NoError(t, err, "failed to start test container") + assert.Check(t, err, "failed to start test container") } func getContainerdShimPid(t *testing.T, c types.ContainerJSON) int { statB, err := ioutil.ReadFile(fmt.Sprintf("/proc/%d/stat", c.State.Pid)) - assert.NoError(t, err, "error looking up containerd-shim pid") + assert.Check(t, err, "error looking up containerd-shim pid") // ppid is the 4th entry in `/proc/pid/stat` ppid, err := strconv.Atoi(strings.Fields(string(statB))[3]) - assert.NoError(t, err, "error converting ppid field to int") + assert.Check(t, err, "error converting ppid field to int") - assert.NotEqual(t, ppid, 1, "got unexpected ppid") + assert.Check(t, ppid != 1, "got unexpected ppid") return ppid } diff --git a/components/engine/integration/container/diff_test.go b/components/engine/integration/container/diff_test.go index de5ff4e21a..56fb983b1d 100644 --- a/components/engine/integration/container/diff_test.go +++ b/components/engine/integration/container/diff_test.go @@ -9,9 +9,8 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/pkg/archive" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestDiff(t *testing.T) { @@ -38,6 +37,6 @@ func TestDiff(t *testing.T) { } items, err := client.ContainerDiff(ctx, cID) - require.NoError(t, err) - assert.Equal(t, expected, items) + assert.NilError(t, err) + assert.DeepEqual(t, expected, items) } diff --git a/components/engine/integration/container/exec_test.go b/components/engine/integration/container/exec_test.go index 06835678f0..1b710432d1 100644 --- a/components/engine/integration/container/exec_test.go +++ b/components/engine/integration/container/exec_test.go @@ -9,7 +9,8 @@ import ( "github.com/docker/docker/api/types/strslice" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestExec(t *testing.T) { @@ -27,7 +28,7 @@ func TestExec(t *testing.T) { Cmd: strslice.StrSlice([]string{"sh", "-c", "env"}), }, ) - require.NoError(t, err) + assert.NilError(t, err) resp, err := client.ContainerExecAttach(ctx, id.ID, types.ExecStartCheck{ @@ -35,12 +36,12 @@ func TestExec(t *testing.T) { Tty: false, }, ) - require.NoError(t, err) + assert.NilError(t, err) defer resp.Close() r, err := ioutil.ReadAll(resp.Reader) - require.NoError(t, err) + assert.NilError(t, err) out := string(r) - require.NoError(t, err) - require.Contains(t, out, "PWD=/tmp", "exec command not running in expected /tmp working directory") - require.Contains(t, out, "FOO=BAR", "exec command not running with expected environment variable FOO") + assert.NilError(t, err) + assert.Assert(t, is.Contains(out, "PWD=/tmp"), "exec command not running in expected /tmp working directory") + assert.Assert(t, is.Contains(out, "FOO=BAR"), "exec command not running with expected environment variable FOO") } diff --git a/components/engine/integration/container/export_test.go b/components/engine/integration/container/export_test.go index 8f846b5a29..f7f0295ce5 100644 --- a/components/engine/integration/container/export_test.go +++ b/components/engine/integration/container/export_test.go @@ -13,10 +13,10 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/pkg/jsonmessage" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) // export an image and try to import it into a new one @@ -32,12 +32,12 @@ func TestExportContainerAndImportImage(t *testing.T) { reference := "repo/testexp:v1" exportResp, err := client.ContainerExport(ctx, cID) - require.NoError(t, err) + assert.NilError(t, err) importResp, err := client.ImageImport(ctx, types.ImageImportSource{ Source: exportResp, SourceName: "-", }, reference, types.ImageImportOptions{}) - require.NoError(t, err) + assert.NilError(t, err) // If the import is successfully, then the message output should contain // the image ID and match with the output from `docker images`. @@ -45,13 +45,13 @@ func TestExportContainerAndImportImage(t *testing.T) { dec := json.NewDecoder(importResp) var jm jsonmessage.JSONMessage err = dec.Decode(&jm) - require.NoError(t, err) + assert.NilError(t, err) images, err := client.ImageList(ctx, types.ImageListOptions{ Filters: filters.NewArgs(filters.Arg("reference", reference)), }) - require.NoError(t, err) - assert.Equal(t, jm.Status, images[0].ID) + assert.NilError(t, err) + assert.Check(t, is.Equal(jm.Status, images[0].ID)) } // TestExportContainerAfterDaemonRestart checks that a container @@ -64,7 +64,7 @@ func TestExportContainerAfterDaemonRestart(t *testing.T) { d := daemon.New(t, "", "dockerd", daemon.Config{}) client, err := d.NewClient() - require.NoError(t, err) + assert.NilError(t, err) d.StartWithBusybox(t) defer d.Stop(t) @@ -75,10 +75,10 @@ func TestExportContainerAfterDaemonRestart(t *testing.T) { Cmd: []string{"top"}, } ctr, err := client.ContainerCreate(ctx, &cfg, nil, nil, "") - require.NoError(t, err) + assert.NilError(t, err) d.Restart(t) _, err = client.ContainerExport(ctx, ctr.ID) - assert.NoError(t, err) + assert.NilError(t, err) } diff --git a/components/engine/integration/container/inspect_test.go b/components/engine/integration/container/inspect_test.go index c7ea23b517..03b9e45319 100644 --- a/components/engine/integration/container/inspect_test.go +++ b/components/engine/integration/container/inspect_test.go @@ -9,10 +9,10 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestInspectCpusetInConfigPre120(t *testing.T) { @@ -33,16 +33,16 @@ func TestInspectCpusetInConfigPre120(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, name, "exited"), poll.WithDelay(100*time.Millisecond)) _, body, err := client.ContainerInspectWithRaw(ctx, name, false) - require.NoError(t, err) + assert.NilError(t, err) var inspectJSON map[string]interface{} err = json.Unmarshal(body, &inspectJSON) - require.NoError(t, err, "unable to unmarshal body for version 1.19: %s", err) + assert.NilError(t, err, "unable to unmarshal body for version 1.19: %s", err) config, ok := inspectJSON["Config"] - assert.Equal(t, true, ok, "Unable to find 'Config'") + assert.Check(t, is.Equal(true, ok), "Unable to find 'Config'") cfg := config.(map[string]interface{}) _, ok = cfg["Cpuset"] - assert.Equal(t, true, ok, "API version 1.19 expected to include Cpuset in 'Config'") + assert.Check(t, is.Equal(true, ok), "API version 1.19 expected to include Cpuset in 'Config'") } diff --git a/components/engine/integration/container/kill_test.go b/components/engine/integration/container/kill_test.go index 5fae912671..4df28966f0 100644 --- a/components/engine/integration/container/kill_test.go +++ b/components/engine/integration/container/kill_test.go @@ -9,10 +9,10 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestKillContainerInvalidSignal(t *testing.T) { @@ -22,11 +22,11 @@ func TestKillContainerInvalidSignal(t *testing.T) { id := container.Run(t, ctx, client) err := client.ContainerKill(ctx, id, "0") - require.EqualError(t, err, "Error response from daemon: Invalid signal: 0") + assert.Error(t, err, "Error response from daemon: Invalid signal: 0") poll.WaitOn(t, container.IsInState(ctx, client, id, "running"), poll.WithDelay(100*time.Millisecond)) err = client.ContainerKill(ctx, id, "SIG42") - require.EqualError(t, err, "Error response from daemon: Invalid signal: SIG42") + assert.Error(t, err, "Error response from daemon: Invalid signal: SIG42") poll.WaitOn(t, container.IsInState(ctx, client, id, "running"), poll.WithDelay(100*time.Millisecond)) } @@ -62,7 +62,7 @@ func TestKillContainer(t *testing.T) { ctx := context.Background() id := container.Run(t, ctx, client) err := client.ContainerKill(ctx, id, tc.signal) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, container.IsInState(ctx, client, id, tc.status), poll.WithDelay(100*time.Millisecond)) }) @@ -102,7 +102,7 @@ func TestKillWithStopSignalAndRestartPolicies(t *testing.T) { } }) err := client.ContainerKill(ctx, id, "TERM") - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, container.IsInState(ctx, client, id, tc.status), poll.WithDelay(100*time.Millisecond)) }) @@ -116,8 +116,8 @@ func TestKillStoppedContainer(t *testing.T) { client := request.NewAPIClient(t) id := container.Create(t, ctx, client) err := client.ContainerKill(ctx, id, "SIGKILL") - require.Error(t, err) - require.Contains(t, err.Error(), "is not running") + assert.Assert(t, is.ErrorContains(err, "")) + assert.Assert(t, is.Contains(err.Error(), "is not running")) } func TestKillStoppedContainerAPIPre120(t *testing.T) { @@ -127,7 +127,7 @@ func TestKillStoppedContainerAPIPre120(t *testing.T) { client := request.NewAPIClient(t, client.WithVersion("1.19")) id := container.Create(t, ctx, client) err := client.ContainerKill(ctx, id, "SIGKILL") - require.NoError(t, err) + assert.NilError(t, err) } func TestKillDifferentUserContainer(t *testing.T) { @@ -144,7 +144,7 @@ func TestKillDifferentUserContainer(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, id, "running"), poll.WithDelay(100*time.Millisecond)) err := client.ContainerKill(ctx, id, "SIGKILL") - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, container.IsInState(ctx, client, id, "exited"), poll.WithDelay(100*time.Millisecond)) } @@ -162,8 +162,8 @@ func TestInspectOomKilledTrue(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, true, inspect.State.OOMKilled) + assert.NilError(t, err) + assert.Check(t, is.Equal(true, inspect.State.OOMKilled)) } func TestInspectOomKilledFalse(t *testing.T) { @@ -178,6 +178,6 @@ func TestInspectOomKilledFalse(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, false, inspect.State.OOMKilled) + assert.NilError(t, err) + assert.Check(t, is.Equal(false, inspect.State.OOMKilled)) } diff --git a/components/engine/integration/container/links_linux_test.go b/components/engine/integration/container/links_linux_test.go index c844c4916f..ed5966bc7b 100644 --- a/components/engine/integration/container/links_linux_test.go +++ b/components/engine/integration/container/links_linux_test.go @@ -10,9 +10,9 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestLinksEtcHostsContentMatch(t *testing.T) { @@ -27,11 +27,11 @@ func TestLinksEtcHostsContentMatch(t *testing.T) { cID := container.Run(t, ctx, client, container.WithNetworkMode("host")) res, err := container.Exec(ctx, client, cID, []string{"cat", "/etc/hosts"}) - require.NoError(t, err) - require.Empty(t, res.Stderr()) - require.Equal(t, 0, res.ExitCode) + assert.NilError(t, err) + assert.Assert(t, is.Len(res.Stderr(), 0)) + assert.Equal(t, 0, res.ExitCode) - assert.Equal(t, string(hosts), res.Stdout()) + assert.Check(t, is.Equal(string(hosts), res.Stdout())) } func TestLinksContainerNames(t *testing.T) { @@ -49,7 +49,7 @@ func TestLinksContainerNames(t *testing.T) { containers, err := client.ContainerList(ctx, types.ContainerListOptions{ Filters: f, }) - require.NoError(t, err) - assert.Equal(t, 1, len(containers)) - assert.Equal(t, []string{"/first", "/second/first"}, containers[0].Names) + assert.NilError(t, err) + assert.Check(t, is.Equal(1, len(containers))) + assert.Check(t, is.DeepEqual([]string{"/first", "/second/first"}, containers[0].Names)) } diff --git a/components/engine/integration/container/logs_test.go b/components/engine/integration/container/logs_test.go index bae4315272..9f536742b9 100644 --- a/components/engine/integration/container/logs_test.go +++ b/components/engine/integration/container/logs_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/pkg/stdcopy" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" ) // Regression test for #35370 @@ -25,8 +25,8 @@ func TestLogsFollowTailEmpty(t *testing.T) { if logs != nil { defer logs.Close() } - assert.NoError(t, err) + assert.Check(t, err) _, err = stdcopy.StdCopy(ioutil.Discard, ioutil.Discard, logs) - assert.NoError(t, err) + assert.Check(t, err) } diff --git a/components/engine/integration/container/mounts_linux_test.go b/components/engine/integration/container/mounts_linux_test.go index c36dd2761c..e15786f8a6 100644 --- a/components/engine/integration/container/mounts_linux_test.go +++ b/components/engine/integration/container/mounts_linux_test.go @@ -16,10 +16,10 @@ import ( "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/system" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestContainerShmNoLeak(t *testing.T) { @@ -130,14 +130,14 @@ func TestContainerNetworkMountsNoChown(t *testing.T) { } cli, err := client.NewEnvClient() - require.NoError(t, err) + assert.NilError(t, err) defer cli.Close() ctrCreate, err := cli.ContainerCreate(ctx, &config, &hostConfig, &network.NetworkingConfig{}, "") - require.NoError(t, err) + assert.NilError(t, err) // container will exit immediately because of no tty, but we only need the start sequence to test the condition err = cli.ContainerStart(ctx, ctrCreate.ID, types.ContainerStartOptions{}) - require.NoError(t, err) + assert.NilError(t, err) // Check that host-located bind mount network file did not change ownership when the container was started // Note: If the user specifies a mountpath from the host, we should not be @@ -150,8 +150,8 @@ func TestContainerNetworkMountsNoChown(t *testing.T) { // same line--we don't chown host file content. // See GitHub PR 34224 for details. statT, err := system.Stat(tmpNWFileMount) - require.NoError(t, err) - assert.Equal(t, uint32(0), statT.UID(), "bind mounted network file should not change ownership from root") + assert.NilError(t, err) + assert.Check(t, is.Equal(uint32(0), statT.UID()), "bind mounted network file should not change ownership from root") } func TestMountDaemonRoot(t *testing.T) { diff --git a/components/engine/integration/container/nat_test.go b/components/engine/integration/container/nat_test.go index 293ba9bba6..5574db779e 100644 --- a/components/engine/integration/container/nat_test.go +++ b/components/engine/integration/container/nat_test.go @@ -15,10 +15,10 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/go-connections/nat" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestNetworkNat(t *testing.T) { @@ -31,12 +31,12 @@ func TestNetworkNat(t *testing.T) { endpoint := getExternalAddress(t) conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", endpoint.String(), 8080)) - require.NoError(t, err) + assert.NilError(t, err) defer conn.Close() data, err := ioutil.ReadAll(conn) - require.NoError(t, err) - assert.Equal(t, msg, strings.TrimSpace(string(data))) + assert.NilError(t, err) + assert.Check(t, is.Equal(msg, strings.TrimSpace(string(data)))) } func TestNetworkLocalhostTCPNat(t *testing.T) { @@ -48,12 +48,12 @@ func TestNetworkLocalhostTCPNat(t *testing.T) { startServerContainer(t, msg, 8081) conn, err := net.Dial("tcp", "localhost:8081") - require.NoError(t, err) + assert.NilError(t, err) defer conn.Close() data, err := ioutil.ReadAll(conn) - require.NoError(t, err) - assert.Equal(t, msg, strings.TrimSpace(string(data))) + assert.NilError(t, err) + assert.Check(t, is.Equal(msg, strings.TrimSpace(string(data)))) } func TestNetworkLoopbackNat(t *testing.T) { @@ -74,14 +74,14 @@ func TestNetworkLoopbackNat(t *testing.T) { body, err := client.ContainerLogs(ctx, cID, types.ContainerLogsOptions{ ShowStdout: true, }) - require.NoError(t, err) + assert.NilError(t, err) defer body.Close() var b bytes.Buffer _, err = io.Copy(&b, body) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, msg, strings.TrimSpace(b.String())) + assert.Check(t, is.Equal(msg, strings.TrimSpace(b.String()))) } func startServerContainer(t *testing.T, msg string, port int) string { @@ -108,11 +108,11 @@ func getExternalAddress(t *testing.T) net.IP { skip.If(t, err != nil, "Test not running with `make test-integration`. Interface eth0 not found: %s", err) ifaceAddrs, err := iface.Addrs() - require.NoError(t, err) - assert.NotEqual(t, 0, len(ifaceAddrs)) + assert.NilError(t, err) + assert.Check(t, 0 != len(ifaceAddrs)) ifaceIP, _, err := net.ParseCIDR(ifaceAddrs[0].String()) - require.NoError(t, err) + assert.NilError(t, err) return ifaceIP } diff --git a/components/engine/integration/container/pause_test.go b/components/engine/integration/container/pause_test.go index bf9f9c3d8f..dd8356f853 100644 --- a/components/engine/integration/container/pause_test.go +++ b/components/engine/integration/container/pause_test.go @@ -12,10 +12,10 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestPause(t *testing.T) { @@ -31,14 +31,14 @@ func TestPause(t *testing.T) { since := request.DaemonUnixTime(ctx, t, client, testEnv) err := client.ContainerPause(ctx, cID) - require.NoError(t, err) + assert.NilError(t, err) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, true, inspect.State.Paused) + assert.NilError(t, err) + assert.Check(t, is.Equal(true, inspect.State.Paused)) err = client.ContainerUnpause(ctx, cID) - require.NoError(t, err) + assert.NilError(t, err) until := request.DaemonUnixTime(ctx, t, client, testEnv) @@ -47,7 +47,7 @@ func TestPause(t *testing.T) { Until: until, Filters: filters.NewArgs(filters.Arg("container", cID)), }) - assert.Equal(t, []string{"pause", "unpause"}, getEventActions(t, messages, errs)) + assert.Check(t, is.DeepEqual([]string{"pause", "unpause"}, getEventActions(t, messages, errs))) } func TestPauseFailsOnWindowsServerContainers(t *testing.T) { @@ -75,10 +75,10 @@ func TestPauseStopPausedContainer(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) err := client.ContainerPause(ctx, cID) - require.NoError(t, err) + assert.NilError(t, err) err = client.ContainerStop(ctx, cID, nil) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, container.IsStopped(ctx, client, cID), poll.WithDelay(100*time.Millisecond)) } @@ -88,7 +88,7 @@ func getEventActions(t *testing.T, messages <-chan events.Message, errs <-chan e for { select { case err := <-errs: - assert.True(t, err == nil || err == io.EOF) + assert.Check(t, err == nil || err == io.EOF) return actions case e := <-messages: actions = append(actions, e.Status) diff --git a/components/engine/integration/container/ps_test.go b/components/engine/integration/container/ps_test.go index 358276b36a..45bcaca239 100644 --- a/components/engine/integration/container/ps_test.go +++ b/components/engine/integration/container/ps_test.go @@ -8,8 +8,8 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestPsFilter(t *testing.T) { @@ -35,8 +35,8 @@ func TestPsFilter(t *testing.T) { All: true, Filters: f1, }) - require.NoError(t, err) - assert.Contains(t, containerIDs(q1), next) + assert.NilError(t, err) + assert.Check(t, is.Contains(containerIDs(q1), next)) f2 := filters.NewArgs() f2.Add("before", "top") @@ -44,6 +44,6 @@ func TestPsFilter(t *testing.T) { All: true, Filters: f2, }) - require.NoError(t, err) - assert.Contains(t, containerIDs(q2), prev) + assert.NilError(t, err) + assert.Check(t, is.Contains(containerIDs(q2), prev)) } diff --git a/components/engine/integration/container/remove_test.go b/components/engine/integration/container/remove_test.go index 98aacdd205..bbc521b059 100644 --- a/components/engine/integration/container/remove_test.go +++ b/components/engine/integration/container/remove_test.go @@ -11,11 +11,11 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) { @@ -42,12 +42,12 @@ func TestRemoveContainerWithRemovedVolume(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) err := os.RemoveAll(tempDir.Path()) - require.NoError(t, err) + assert.NilError(t, err) err = client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ RemoveVolumes: true, }) - require.NoError(t, err) + assert.NilError(t, err) _, _, err = client.ContainerInspectWithRaw(ctx, cID, true) testutil.ErrorContains(t, err, "No such container") @@ -65,18 +65,18 @@ func TestRemoveContainerWithVolume(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) insp, _, err := client.ContainerInspectWithRaw(ctx, cID, true) - require.NoError(t, err) - assert.Equal(t, 1, len(insp.Mounts)) + assert.NilError(t, err) + assert.Check(t, is.Equal(1, len(insp.Mounts))) volName := insp.Mounts[0].Name err = client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ RemoveVolumes: true, }) - require.NoError(t, err) + assert.NilError(t, err) volumes, err := client.VolumeList(ctx, filters.NewArgs(filters.Arg("name", volName))) - require.NoError(t, err) - assert.Equal(t, 0, len(volumes.Volumes)) + assert.NilError(t, err) + assert.Check(t, is.Equal(0, len(volumes.Volumes))) } func TestRemoveContainerRunning(t *testing.T) { @@ -100,7 +100,7 @@ func TestRemoveContainerForceRemoveRunning(t *testing.T) { err := client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{ Force: true, }) - require.NoError(t, err) + assert.NilError(t, err) } func TestRemoveInvalidContainer(t *testing.T) { diff --git a/components/engine/integration/container/rename_test.go b/components/engine/integration/container/rename_test.go index 3567aee1f5..a27fd78acc 100644 --- a/components/engine/integration/container/rename_test.go +++ b/components/engine/integration/container/rename_test.go @@ -11,10 +11,10 @@ import ( "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" "github.com/docker/docker/pkg/stringid" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) // This test simulates the scenario mentioned in #31392: @@ -30,18 +30,18 @@ func TestRenameLinkedContainer(t *testing.T) { bID := container.Run(t, ctx, client, container.WithName("b0"), container.WithLinks("a0")) err := client.ContainerRename(ctx, aID, "a1") - require.NoError(t, err) + assert.NilError(t, err) container.Run(t, ctx, client, container.WithName("a0")) err = client.ContainerRemove(ctx, bID, types.ContainerRemoveOptions{Force: true}) - require.NoError(t, err) + assert.NilError(t, err) bID = container.Run(t, ctx, client, container.WithName("b0"), container.WithLinks("a0")) inspect, err := client.ContainerInspect(ctx, bID) - require.NoError(t, err) - assert.Equal(t, []string{"/a0:/b0/a0"}, inspect.HostConfig.Links) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual([]string{"/a0:/b0/a0"}, inspect.HostConfig.Links)) } func TestRenameStoppedContainer(t *testing.T) { @@ -54,16 +54,16 @@ func TestRenameStoppedContainer(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, "/"+oldName, inspect.Name) + assert.NilError(t, err) + assert.Check(t, is.Equal("/"+oldName, inspect.Name)) newName := "new_name" + stringid.GenerateNonCryptoID() err = client.ContainerRename(ctx, oldName, newName) - require.NoError(t, err) + assert.NilError(t, err) inspect, err = client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, "/"+newName, inspect.Name) + assert.NilError(t, err) + assert.Check(t, is.Equal("/"+newName, inspect.Name)) } func TestRenameRunningContainerAndReuse(t *testing.T) { @@ -77,11 +77,11 @@ func TestRenameRunningContainerAndReuse(t *testing.T) { newName := "new_name" + stringid.GenerateNonCryptoID() err := client.ContainerRename(ctx, oldName, newName) - require.NoError(t, err) + assert.NilError(t, err) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, "/"+newName, inspect.Name) + assert.NilError(t, err) + assert.Check(t, is.Equal("/"+newName, inspect.Name)) _, err = client.ContainerInspect(ctx, oldName) testutil.ErrorContains(t, err, "No such container: "+oldName) @@ -90,8 +90,8 @@ func TestRenameRunningContainerAndReuse(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) inspect, err = client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, "/"+oldName, inspect.Name) + assert.NilError(t, err) + assert.Check(t, is.Equal("/"+oldName, inspect.Name)) } func TestRenameInvalidName(t *testing.T) { @@ -107,8 +107,8 @@ func TestRenameInvalidName(t *testing.T) { testutil.ErrorContains(t, err, "Invalid container name") inspect, err := client.ContainerInspect(ctx, oldName) - require.NoError(t, err) - assert.Equal(t, cID, inspect.ID) + assert.NilError(t, err) + assert.Check(t, is.Equal(cID, inspect.ID)) } // Test case for GitHub issue 22466 @@ -124,7 +124,7 @@ func TestRenameAnonymousContainer(t *testing.T) { client := request.NewAPIClient(t) _, err := client.NetworkCreate(ctx, "network1", types.NetworkCreate{}) - require.NoError(t, err) + assert.NilError(t, err) cID := container.Run(t, ctx, client, func(c *container.TestContainerConfig) { c.NetworkingConfig.EndpointsConfig = map[string]*network.EndpointSettings{ "network1": {}, @@ -132,13 +132,13 @@ func TestRenameAnonymousContainer(t *testing.T) { c.HostConfig.NetworkMode = "network1" }) err = client.ContainerRename(ctx, cID, "container1") - require.NoError(t, err) + assert.NilError(t, err) // Stop/Start the container to get registered // FIXME(vdemeester) this is a really weird behavior as it fails otherwise err = client.ContainerStop(ctx, "container1", nil) - require.NoError(t, err) + assert.NilError(t, err) err = client.ContainerStart(ctx, "container1", types.ContainerStartOptions{}) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) @@ -155,8 +155,8 @@ func TestRenameAnonymousContainer(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond)) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, 0, inspect.State.ExitCode, "container %s exited with the wrong exitcode: %+v", cID, inspect) + assert.NilError(t, err) + assert.Check(t, is.Equal(0, inspect.State.ExitCode), "container %s exited with the wrong exitcode: %+v", cID, inspect) } // TODO: should be a unit test @@ -192,9 +192,9 @@ func TestRenameContainerWithLinkedContainer(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, app1ID, "running"), poll.WithDelay(100*time.Millisecond)) err := client.ContainerRename(ctx, "app1", "app2") - require.NoError(t, err) + assert.NilError(t, err) inspect, err := client.ContainerInspect(ctx, "app2/mysql") - require.NoError(t, err) - assert.Equal(t, db1ID, inspect.ID) + assert.NilError(t, err) + assert.Check(t, is.Equal(db1ID, inspect.ID)) } diff --git a/components/engine/integration/container/resize_test.go b/components/engine/integration/container/resize_test.go index 18438ea825..149ac3afd1 100644 --- a/components/engine/integration/container/resize_test.go +++ b/components/engine/integration/container/resize_test.go @@ -11,9 +11,9 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestResize(t *testing.T) { @@ -29,7 +29,7 @@ func TestResize(t *testing.T) { Height: 40, Width: 40, }) - require.NoError(t, err) + assert.NilError(t, err) } func TestResizeWithInvalidSize(t *testing.T) { @@ -43,8 +43,8 @@ func TestResizeWithInvalidSize(t *testing.T) { endpoint := "/containers/" + cID + "/resize?h=foo&w=bar" res, _, err := req.Post(endpoint) - require.NoError(t, err) - assert.Equal(t, http.StatusBadRequest, res.StatusCode) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(http.StatusBadRequest, res.StatusCode)) } func TestResizeWhenContainerNotStarted(t *testing.T) { diff --git a/components/engine/integration/container/stats_test.go b/components/engine/integration/container/stats_test.go index 9c0b948498..d10808f8f7 100644 --- a/components/engine/integration/container/stats_test.go +++ b/components/engine/integration/container/stats_test.go @@ -10,10 +10,10 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestStats(t *testing.T) { @@ -24,20 +24,20 @@ func TestStats(t *testing.T) { ctx := context.Background() info, err := client.Info(ctx) - require.NoError(t, err) + assert.NilError(t, err) cID := container.Run(t, ctx, client) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) resp, err := client.ContainerStats(ctx, cID, false) - require.NoError(t, err) + assert.NilError(t, err) defer resp.Body.Close() var v *types.Stats err = json.NewDecoder(resp.Body).Decode(&v) - require.NoError(t, err) - assert.Equal(t, int64(v.MemoryStats.Limit), info.MemTotal) + assert.NilError(t, err) + assert.Check(t, is.Equal(int64(v.MemoryStats.Limit), info.MemTotal)) err = json.NewDecoder(resp.Body).Decode(&v) - require.Error(t, err, io.EOF) + assert.Assert(t, is.ErrorContains(err, ""), io.EOF) } diff --git a/components/engine/integration/container/stop_test.go b/components/engine/integration/container/stop_test.go index 4ecd06dd2c..2cc9b82512 100644 --- a/components/engine/integration/container/stop_test.go +++ b/components/engine/integration/container/stop_test.go @@ -10,10 +10,10 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/icmd" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/require" ) func TestStopContainerWithRestartPolicyAlways(t *testing.T) { @@ -34,7 +34,7 @@ func TestStopContainerWithRestartPolicyAlways(t *testing.T) { for _, name := range names { err := client.ContainerStop(ctx, name, nil) - require.NoError(t, err) + assert.NilError(t, err) } for _, name := range names { @@ -54,7 +54,7 @@ func TestDeleteDevicemapper(t *testing.T) { poll.WaitOn(t, container.IsStopped(ctx, client, id), poll.WithDelay(100*time.Millisecond)) inspect, err := client.ContainerInspect(ctx, id) - require.NoError(t, err) + assert.NilError(t, err) deviceID := inspect.GraphDriver.Data["DeviceId"] @@ -67,5 +67,5 @@ func TestDeleteDevicemapper(t *testing.T) { result.Assert(t, icmd.Success) err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{}) - require.NoError(t, err) + assert.NilError(t, err) } diff --git a/components/engine/integration/container/update_linux_test.go b/components/engine/integration/container/update_linux_test.go index c898dc1d3b..a08417ea24 100644 --- a/components/engine/integration/container/update_linux_test.go +++ b/components/engine/integration/container/update_linux_test.go @@ -10,10 +10,10 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestUpdateMemory(t *testing.T) { @@ -44,26 +44,26 @@ func TestUpdateMemory(t *testing.T) { MemorySwap: setMemorySwap, }, }) - require.NoError(t, err) + assert.NilError(t, err) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, setMemory, inspect.HostConfig.Memory) - assert.Equal(t, setMemorySwap, inspect.HostConfig.MemorySwap) + assert.NilError(t, err) + assert.Check(t, is.Equal(setMemory, inspect.HostConfig.Memory)) + assert.Check(t, is.Equal(setMemorySwap, inspect.HostConfig.MemorySwap)) res, err := container.Exec(ctx, client, cID, []string{"cat", "/sys/fs/cgroup/memory/memory.limit_in_bytes"}) - require.NoError(t, err) - require.Empty(t, res.Stderr()) - require.Equal(t, 0, res.ExitCode) - assert.Equal(t, strconv.FormatInt(setMemory, 10), strings.TrimSpace(res.Stdout())) + assert.NilError(t, err) + assert.Assert(t, is.Len(res.Stderr(), 0)) + assert.Equal(t, 0, res.ExitCode) + assert.Check(t, is.Equal(strconv.FormatInt(setMemory, 10), strings.TrimSpace(res.Stdout()))) res, err = container.Exec(ctx, client, cID, []string{"cat", "/sys/fs/cgroup/memory/memory.memsw.limit_in_bytes"}) - require.NoError(t, err) - require.Empty(t, res.Stderr()) - require.Equal(t, 0, res.ExitCode) - assert.Equal(t, strconv.FormatInt(setMemorySwap, 10), strings.TrimSpace(res.Stdout())) + assert.NilError(t, err) + assert.Assert(t, is.Len(res.Stderr(), 0)) + assert.Equal(t, 0, res.ExitCode) + assert.Check(t, is.Equal(strconv.FormatInt(setMemorySwap, 10), strings.TrimSpace(res.Stdout()))) } func TestUpdateCPUQuota(t *testing.T) { @@ -93,15 +93,15 @@ func TestUpdateCPUQuota(t *testing.T) { } inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, test.update, inspect.HostConfig.CPUQuota) + assert.NilError(t, err) + assert.Check(t, is.Equal(test.update, inspect.HostConfig.CPUQuota)) res, err := container.Exec(ctx, client, cID, []string{"/bin/cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"}) - require.NoError(t, err) - require.Empty(t, res.Stderr()) - require.Equal(t, 0, res.ExitCode) + assert.NilError(t, err) + assert.Assert(t, is.Len(res.Stderr(), 0)) + assert.Equal(t, 0, res.ExitCode) - assert.Equal(t, strconv.FormatInt(test.update, 10), strings.TrimSpace(res.Stdout())) + assert.Check(t, is.Equal(strconv.FormatInt(test.update, 10), strings.TrimSpace(res.Stdout()))) } } diff --git a/components/engine/integration/container/update_test.go b/components/engine/integration/container/update_test.go index 651e84cb22..03dcc635c6 100644 --- a/components/engine/integration/container/update_test.go +++ b/components/engine/integration/container/update_test.go @@ -9,9 +9,9 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestUpdateRestartPolicy(t *testing.T) { @@ -32,7 +32,7 @@ func TestUpdateRestartPolicy(t *testing.T) { MaximumRetryCount: 5, }, }) - require.NoError(t, err) + assert.NilError(t, err) timeout := 60 * time.Second if testEnv.OSType == "windows" { @@ -42,9 +42,9 @@ func TestUpdateRestartPolicy(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "exited"), poll.WithDelay(100*time.Millisecond), poll.WithTimeout(timeout)) inspect, err := client.ContainerInspect(ctx, cID) - require.NoError(t, err) - assert.Equal(t, inspect.RestartCount, 5) - assert.Equal(t, inspect.HostConfig.RestartPolicy.MaximumRetryCount, 5) + assert.NilError(t, err) + assert.Check(t, is.Equal(inspect.RestartCount, 5)) + assert.Check(t, is.Equal(inspect.HostConfig.RestartPolicy.MaximumRetryCount, 5)) } func TestUpdateRestartWithAutoRemove(t *testing.T) { diff --git a/components/engine/integration/image/commit_test.go b/components/engine/integration/image/commit_test.go index 39fc956db1..e13719b532 100644 --- a/components/engine/integration/image/commit_test.go +++ b/components/engine/integration/image/commit_test.go @@ -7,8 +7,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestCommitInheritsEnv(t *testing.T) { @@ -22,13 +22,13 @@ func TestCommitInheritsEnv(t *testing.T) { Changes: []string{"ENV PATH=/bin"}, Reference: "test-commit-image", }) - require.NoError(t, err) + assert.NilError(t, err) image1, _, err := client.ImageInspectWithRaw(ctx, commitResp1.ID) - require.NoError(t, err) + assert.NilError(t, err) expectedEnv1 := []string{"PATH=/bin"} - assert.Equal(t, expectedEnv1, image1.Config.Env) + assert.Check(t, is.DeepEqual(expectedEnv1, image1.Config.Env)) cID2 := container.Create(t, ctx, client, container.WithImage(image1.ID)) @@ -36,10 +36,10 @@ func TestCommitInheritsEnv(t *testing.T) { Changes: []string{"ENV PATH=/usr/bin:$PATH"}, Reference: "test-commit-image", }) - require.NoError(t, err) + assert.NilError(t, err) image2, _, err := client.ImageInspectWithRaw(ctx, commitResp2.ID) - require.NoError(t, err) + assert.NilError(t, err) expectedEnv2 := []string{"PATH=/usr/bin:/bin"} - assert.Equal(t, expectedEnv2, image2.Config.Env) + assert.Check(t, is.DeepEqual(expectedEnv2, image2.Config.Env)) } diff --git a/components/engine/integration/image/remove_test.go b/components/engine/integration/image/remove_test.go index 825724bd03..c89f6f7a03 100644 --- a/components/engine/integration/image/remove_test.go +++ b/components/engine/integration/image/remove_test.go @@ -8,8 +8,8 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestRemoveImageOrphaning(t *testing.T) { @@ -25,12 +25,12 @@ func TestRemoveImageOrphaning(t *testing.T) { Changes: []string{`ENTRYPOINT ["true"]`}, Reference: img, }) - require.NoError(t, err) + assert.NilError(t, err) // verifies that reference now points to first image resp, _, err := client.ImageInspectWithRaw(ctx, img) - require.NoError(t, err) - assert.Equal(t, resp.ID, commitResp1.ID) + assert.NilError(t, err) + assert.Check(t, is.Equal(resp.ID, commitResp1.ID)) // Create a container from created image, and commit a small change with same reference name cID2 := container.Create(t, ctx, client, container.WithImage(img), container.WithCmd("")) @@ -38,21 +38,21 @@ func TestRemoveImageOrphaning(t *testing.T) { Changes: []string{`LABEL Maintainer="Integration Tests"`}, Reference: img, }) - require.NoError(t, err) + assert.NilError(t, err) // verifies that reference now points to second image resp, _, err = client.ImageInspectWithRaw(ctx, img) - require.NoError(t, err) - assert.Equal(t, resp.ID, commitResp2.ID) + assert.NilError(t, err) + assert.Check(t, is.Equal(resp.ID, commitResp2.ID)) // try to remove the image, should not error out. _, err = client.ImageRemove(ctx, img, types.ImageRemoveOptions{}) - require.NoError(t, err) + assert.NilError(t, err) // check if the first image is still there resp, _, err = client.ImageInspectWithRaw(ctx, commitResp1.ID) - require.NoError(t, err) - assert.Equal(t, resp.ID, commitResp1.ID) + assert.NilError(t, err) + assert.Check(t, is.Equal(resp.ID, commitResp1.ID)) // check if the second image has been deleted _, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID) diff --git a/components/engine/integration/internal/container/container.go b/components/engine/integration/internal/container/container.go index 8d8fe28791..0c76571769 100644 --- a/components/engine/integration/internal/container/container.go +++ b/components/engine/integration/internal/container/container.go @@ -8,7 +8,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "github.com/docker/docker/client" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) // TestContainerConfig holds container configuration struct that @@ -37,7 +37,7 @@ func Create(t *testing.T, ctx context.Context, client client.APIClient, ops ...f } c, err := client.ContainerCreate(ctx, config.Config, config.HostConfig, config.NetworkingConfig, config.Name) - require.NoError(t, err) + assert.NilError(t, err) return c.ID } @@ -48,7 +48,7 @@ func Run(t *testing.T, ctx context.Context, client client.APIClient, ops ...func id := Create(t, ctx, client, ops...) err := client.ContainerStart(ctx, id, types.ContainerStartOptions{}) - require.NoError(t, err) + assert.NilError(t, err) return id } diff --git a/components/engine/integration/internal/request/client.go b/components/engine/integration/internal/request/client.go index 34e589ec86..07dc2e33c3 100644 --- a/components/engine/integration/internal/request/client.go +++ b/components/engine/integration/internal/request/client.go @@ -9,14 +9,14 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/internal/test/environment" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) // NewAPIClient returns a docker API client configured from environment variables func NewAPIClient(t *testing.T, ops ...func(*client.Client) error) client.APIClient { ops = append([]func(*client.Client) error{client.FromEnv}, ops...) clt, err := client.NewClientWithOpts(ops...) - require.NoError(t, err) + assert.NilError(t, err) return clt } @@ -27,10 +27,10 @@ func DaemonTime(ctx context.Context, t *testing.T, client client.APIClient, test } info, err := client.Info(ctx) - require.NoError(t, err) + assert.NilError(t, err) dt, err := time.Parse(time.RFC3339Nano, info.SystemTime) - require.NoError(t, err, "invalid time format in GET /info response") + assert.NilError(t, err, "invalid time format in GET /info response") return dt } diff --git a/components/engine/integration/internal/swarm/service.go b/components/engine/integration/internal/swarm/service.go index a46b02e146..0ec4d5175e 100644 --- a/components/engine/integration/internal/swarm/service.go +++ b/components/engine/integration/internal/swarm/service.go @@ -11,7 +11,7 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/daemon" "github.com/docker/docker/internal/test/environment" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) const ( @@ -35,7 +35,7 @@ func NewSwarm(t *testing.T, testEnv *environment.Execution) *daemon.Swarm { args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} d.StartWithBusybox(t, args...) - require.NoError(t, d.Init(swarmtypes.InitRequest{})) + assert.NilError(t, d.Init(swarmtypes.InitRequest{})) return d } @@ -52,7 +52,7 @@ func CreateService(t *testing.T, d *daemon.Swarm, opts ...ServiceSpecOpt) string client := GetClient(t, d) resp, err := client.ServiceCreate(context.Background(), spec, types.ServiceCreateOptions{}) - require.NoError(t, err, "error creating service") + assert.NilError(t, err, "error creating service") return resp.ID } @@ -126,7 +126,7 @@ func GetRunningTasks(t *testing.T, d *daemon.Swarm, serviceID string) []swarmtyp Filters: filterArgs, } tasks, err := client.TaskList(context.Background(), options) - require.NoError(t, err) + assert.NilError(t, err) return tasks } @@ -136,11 +136,11 @@ func ExecTask(t *testing.T, d *daemon.Swarm, task swarmtypes.Task, config types. ctx := context.Background() resp, err := client.ContainerExecCreate(ctx, task.Status.ContainerStatus.ContainerID, config) - require.NoError(t, err, "error creating exec") + assert.NilError(t, err, "error creating exec") startCheck := types.ExecStartCheck{} attach, err := client.ContainerExecAttach(ctx, resp.ID, startCheck) - require.NoError(t, err, "error attaching to exec") + assert.NilError(t, err, "error attaching to exec") return attach } @@ -153,6 +153,6 @@ func ensureContainerSpec(spec *swarmtypes.ServiceSpec) { // GetClient creates a new client for the passed in swarm daemon. func GetClient(t *testing.T, d *daemon.Swarm) client.APIClient { client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) return client } diff --git a/components/engine/integration/network/delete_test.go b/components/engine/integration/network/delete_test.go index 0877d8bc8c..e2af49de7e 100644 --- a/components/engine/integration/network/delete_test.go +++ b/components/engine/integration/network/delete_test.go @@ -6,8 +6,8 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func containsNetwork(nws []types.NetworkResource, nw types.NetworkCreateResponse) bool { @@ -29,18 +29,18 @@ func createAmbiguousNetworks(t *testing.T) (types.NetworkCreateResponse, types.N ctx := context.Background() testNet, err := client.NetworkCreate(ctx, "testNet", types.NetworkCreate{}) - require.NoError(t, err) + assert.NilError(t, err) idPrefixNet, err := client.NetworkCreate(ctx, testNet.ID[:12], types.NetworkCreate{}) - require.NoError(t, err) + assert.NilError(t, err) fullIDNet, err := client.NetworkCreate(ctx, testNet.ID, types.NetworkCreate{}) - require.NoError(t, err) + assert.NilError(t, err) nws, err := client.NetworkList(ctx, types.NetworkListOptions{}) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, true, containsNetwork(nws, testNet), "failed to create network testNet") - assert.Equal(t, true, containsNetwork(nws, idPrefixNet), "failed to create network idPrefixNet") - assert.Equal(t, true, containsNetwork(nws, fullIDNet), "failed to create network fullIDNet") + assert.Check(t, is.Equal(true, containsNetwork(nws, testNet)), "failed to create network testNet") + assert.Check(t, is.Equal(true, containsNetwork(nws, idPrefixNet)), "failed to create network idPrefixNet") + assert.Check(t, is.Equal(true, containsNetwork(nws, fullIDNet)), "failed to create network fullIDNet") return testNet, idPrefixNet, fullIDNet } @@ -56,17 +56,17 @@ func TestDockerNetworkDeletePreferID(t *testing.T) { // Delete the network using a prefix of the first network's ID as name. // This should the network name with the id-prefix, not the original network. err := client.NetworkRemove(ctx, testNet.ID[:12]) - require.NoError(t, err) + assert.NilError(t, err) // Delete the network using networkID. This should remove the original // network, not the network with the name equal to the networkID err = client.NetworkRemove(ctx, testNet.ID) - require.NoError(t, err) + assert.NilError(t, err) // networks "testNet" and "idPrefixNet" should be removed, but "fullIDNet" should still exist nws, err := client.NetworkList(ctx, types.NetworkListOptions{}) - require.NoError(t, err) - assert.Equal(t, false, containsNetwork(nws, testNet), "Network testNet not removed") - assert.Equal(t, false, containsNetwork(nws, idPrefixNet), "Network idPrefixNet not removed") - assert.Equal(t, true, containsNetwork(nws, fullIDNet), "Network fullIDNet not found") + assert.NilError(t, err) + assert.Check(t, is.Equal(false, containsNetwork(nws, testNet)), "Network testNet not removed") + assert.Check(t, is.Equal(false, containsNetwork(nws, idPrefixNet)), "Network idPrefixNet not removed") + assert.Check(t, is.Equal(true, containsNetwork(nws, fullIDNet)), "Network fullIDNet not found") } diff --git a/components/engine/integration/network/inspect_test.go b/components/engine/integration/network/inspect_test.go index df586224a1..3afdcf1ac4 100644 --- a/components/engine/integration/network/inspect_test.go +++ b/components/engine/integration/network/inspect_test.go @@ -11,8 +11,8 @@ import ( "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/integration-cli/daemon" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -24,7 +24,7 @@ func TestInspectNetwork(t *testing.T) { d := newSwarm(t) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) overlayName := "overlay1" networkCreate := types.NetworkCreate{ @@ -33,7 +33,7 @@ func TestInspectNetwork(t *testing.T) { } netResp, err := client.NetworkCreate(context.Background(), overlayName, networkCreate) - require.NoError(t, err) + assert.NilError(t, err) overlayID := netResp.ID var instances uint64 = 4 @@ -44,7 +44,7 @@ func TestInspectNetwork(t *testing.T) { serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) pollSettings := func(config *poll.Settings) { if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { @@ -57,32 +57,32 @@ func TestInspectNetwork(t *testing.T) { poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), pollSettings) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) - require.NoError(t, err) + assert.NilError(t, err) // Test inspect verbose with full NetworkID networkVerbose, err := client.NetworkInspect(context.Background(), overlayID, types.NetworkInspectOptions{ Verbose: true, }) - require.NoError(t, err) - require.True(t, validNetworkVerbose(networkVerbose, serviceName, instances)) + assert.NilError(t, err) + assert.Assert(t, validNetworkVerbose(networkVerbose, serviceName, instances)) // Test inspect verbose with partial NetworkID networkVerbose, err = client.NetworkInspect(context.Background(), overlayID[0:11], types.NetworkInspectOptions{ Verbose: true, }) - require.NoError(t, err) - require.True(t, validNetworkVerbose(networkVerbose, serviceName, instances)) + assert.NilError(t, err) + assert.Assert(t, validNetworkVerbose(networkVerbose, serviceName, instances)) // Test inspect verbose with Network name and swarm scope networkVerbose, err = client.NetworkInspect(context.Background(), overlayName, types.NetworkInspectOptions{ Verbose: true, Scope: "swarm", }) - require.NoError(t, err) - require.True(t, validNetworkVerbose(networkVerbose, serviceName, instances)) + assert.NilError(t, err) + assert.Assert(t, validNetworkVerbose(networkVerbose, serviceName, instances)) err = client.ServiceRemove(context.Background(), serviceID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings) @@ -90,19 +90,19 @@ func TestInspectNetwork(t *testing.T) { serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) serviceID2 := serviceResp.ID poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), pollSettings) err = client.ServiceRemove(context.Background(), serviceID2) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID2), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings) err = client.NetworkRemove(context.Background(), overlayID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) } @@ -122,7 +122,7 @@ func newSwarm(t *testing.T) *daemon.Swarm { args := []string{"--iptables=false", "--swarm-default-advertise-addr=lo"} d.StartWithBusybox(t, args...) - require.NoError(t, d.Init(swarm.InitRequest{})) + assert.NilError(t, d.Init(swarm.InitRequest{})) return d } diff --git a/components/engine/integration/network/service_test.go b/components/engine/integration/network/service_test.go index f1c0950988..b8470a1e85 100644 --- a/components/engine/integration/network/service_test.go +++ b/components/engine/integration/network/service_test.go @@ -9,8 +9,8 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -19,7 +19,7 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { d := newSwarm(t) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) hostName := "host" var instances uint64 = 1 @@ -30,7 +30,7 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) pollSettings := func(config *poll.Settings) { if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { @@ -46,10 +46,10 @@ func TestServiceWithPredefinedNetwork(t *testing.T) { poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) - require.NoError(t, err) + assert.NilError(t, err) err = client.ServiceRemove(context.Background(), serviceID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings) @@ -64,7 +64,7 @@ func TestServiceWithIngressNetwork(t *testing.T) { defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) pollSettings := func(config *poll.Settings) { if runtime.GOARCH == "arm64" || runtime.GOARCH == "arm" { @@ -95,16 +95,16 @@ func TestServiceWithIngressNetwork(t *testing.T) { serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) serviceID := serviceResp.ID poll.WaitOn(t, serviceRunningCount(client, serviceID, instances), pollSettings) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) - require.NoError(t, err) + assert.NilError(t, err) err = client.ServiceRemove(context.Background(), serviceID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings) @@ -115,11 +115,11 @@ func TestServiceWithIngressNetwork(t *testing.T) { Verbose: true, Scope: "swarm", }) - require.NoError(t, err, "Ingress network was removed after removing service!") - require.NotZero(t, len(netInfo.Containers), "No load balancing endpoints in ingress network") - require.NotZero(t, len(netInfo.Peers), "No peers (including self) in ingress network") + assert.NilError(t, err, "Ingress network was removed after removing service!") + assert.Assert(t, len(netInfo.Containers) != 0, "No load balancing endpoints in ingress network") + assert.Assert(t, len(netInfo.Peers) != 0, "No peers (including self) in ingress network") _, ok := netInfo.Containers["ingress-sbox"] - require.True(t, ok, "ingress-sbox not present in ingress network") + assert.Assert(t, ok, "ingress-sbox not present in ingress network") } func serviceRunningCount(client client.ServiceAPIClient, serviceID string, instances uint64) func(log poll.LogT) poll.Result { diff --git a/components/engine/integration/plugin/authz/authz_plugin_test.go b/components/engine/integration/plugin/authz/authz_plugin_test.go index 667fc3d3cc..5bca6c138d 100644 --- a/components/engine/integration/plugin/authz/authz_plugin_test.go +++ b/components/engine/integration/plugin/authz/authz_plugin_test.go @@ -24,8 +24,8 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/environment" "github.com/docker/docker/pkg/authorization" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/require" ) const ( @@ -55,15 +55,15 @@ func setupTestV1(t *testing.T) func() { teardown := setupTest(t) err := os.MkdirAll("/etc/docker/plugins", 0755) - require.Nil(t, err) + assert.NilError(t, err) fileName := fmt.Sprintf("/etc/docker/plugins/%s.spec", testAuthZPlugin) err = ioutil.WriteFile(fileName, []byte(server.URL), 0644) - require.Nil(t, err) + assert.NilError(t, err) return func() { err := os.RemoveAll("/etc/docker/plugins") - require.Nil(t, err) + assert.NilError(t, err) teardown() ctrl = nil @@ -87,7 +87,7 @@ func TestAuthZPluginAllowRequest(t *testing.T) { d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin) client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -98,9 +98,9 @@ func TestAuthZPluginAllowRequest(t *testing.T) { assertURIRecorded(t, ctrl.requestsURIs, fmt.Sprintf("/containers/%s/start", cID)) _, err = client.ServerVersion(ctx) - require.Nil(t, err) - require.Equal(t, 1, ctrl.versionReqCount) - require.Equal(t, 1, ctrl.versionResCount) + assert.NilError(t, err) + assert.Equal(t, 1, ctrl.versionReqCount) + assert.Equal(t, 1, ctrl.versionResCount) } func TestAuthZPluginTLS(t *testing.T) { @@ -126,13 +126,13 @@ func TestAuthZPluginTLS(t *testing.T) { ctrl.resRes.Allow = true client, err := newTLSAPIClient(testDaemonHTTPSAddr, cacertPath, clientCertPath, clientKeyPath) - require.Nil(t, err) + assert.NilError(t, err) _, err = client.ServerVersion(context.Background()) - require.Nil(t, err) + assert.NilError(t, err) - require.Equal(t, "client", ctrl.reqUser) - require.Equal(t, "client", ctrl.resUser) + assert.Equal(t, "client", ctrl.reqUser) + assert.Equal(t, "client", ctrl.resUser) } func newTLSAPIClient(host, cacertPath, certPath, keyPath string) (client.APIClient, error) { @@ -153,16 +153,16 @@ func TestAuthZPluginDenyRequest(t *testing.T) { ctrl.reqRes.Msg = unauthorizedMessage client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Ensure command is blocked _, err = client.ServerVersion(context.Background()) - require.NotNil(t, err) - require.Equal(t, 1, ctrl.versionReqCount) - require.Equal(t, 0, ctrl.versionResCount) + assert.Assert(t, err != nil) + assert.Equal(t, 1, ctrl.versionReqCount) + assert.Equal(t, 0, ctrl.versionResCount) // Ensure unauthorized message appears in response - require.Equal(t, fmt.Sprintf("Error response from daemon: authorization denied by plugin %s: %s", testAuthZPlugin, unauthorizedMessage), err.Error()) + assert.Equal(t, fmt.Sprintf("Error response from daemon: authorization denied by plugin %s: %s", testAuthZPlugin, unauthorizedMessage), err.Error()) } // TestAuthZPluginAPIDenyResponse validates that when authorization @@ -174,17 +174,17 @@ func TestAuthZPluginAPIDenyResponse(t *testing.T) { ctrl.resRes.Msg = unauthorizedMessage daemonURL, err := url.Parse(d.Sock()) - require.Nil(t, err) + assert.NilError(t, err) conn, err := net.DialTimeout(daemonURL.Scheme, daemonURL.Path, time.Second*10) - require.Nil(t, err) + assert.NilError(t, err) client := httputil.NewClientConn(conn, nil) req, err := http.NewRequest("GET", "/version", nil) - require.Nil(t, err) + assert.NilError(t, err) resp, err := client.Do(req) - require.Nil(t, err) - require.Equal(t, http.StatusForbidden, resp.StatusCode) + assert.NilError(t, err) + assert.DeepEqual(t, http.StatusForbidden, resp.StatusCode) } func TestAuthZPluginDenyResponse(t *testing.T) { @@ -195,16 +195,16 @@ func TestAuthZPluginDenyResponse(t *testing.T) { ctrl.resRes.Msg = unauthorizedMessage client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Ensure command is blocked _, err = client.ServerVersion(context.Background()) - require.NotNil(t, err) - require.Equal(t, 1, ctrl.versionReqCount) - require.Equal(t, 1, ctrl.versionResCount) + assert.Assert(t, err != nil) + assert.Equal(t, 1, ctrl.versionReqCount) + assert.Equal(t, 1, ctrl.versionResCount) // Ensure unauthorized message appears in response - require.Equal(t, fmt.Sprintf("Error response from daemon: authorization denied by plugin %s: %s", testAuthZPlugin, unauthorizedMessage), err.Error()) + assert.Equal(t, fmt.Sprintf("Error response from daemon: authorization denied by plugin %s: %s", testAuthZPlugin, unauthorizedMessage), err.Error()) } // TestAuthZPluginAllowEventStream verifies event stream propagates @@ -218,7 +218,7 @@ func TestAuthZPluginAllowEventStream(t *testing.T) { d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin) client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -231,7 +231,7 @@ func TestAuthZPluginAllowEventStream(t *testing.T) { for i := 0; i < 100; i++ { c, err := client.ContainerInspect(ctx, cID) - require.Nil(t, err) + assert.NilError(t, err) if c.State.Running { break } @@ -258,7 +258,7 @@ func TestAuthZPluginAllowEventStream(t *testing.T) { if err == io.EOF { t.Fatal("premature end of event stream") } - require.Nil(t, err) + assert.NilError(t, err) case <-time.After(30 * time.Second): // Fail the test t.Fatal("event stream timeout") @@ -279,10 +279,10 @@ func systemTime(t *testing.T, client client.APIClient, testEnv *environment.Exec ctx := context.Background() info, err := client.Info(ctx) - require.Nil(t, err) + assert.NilError(t, err) dt, err := time.Parse(time.RFC3339Nano, info.SystemTime) - require.Nil(t, err, "invalid time format in GET /info response") + assert.NilError(t, err, "invalid time format in GET /info response") return dt } @@ -303,12 +303,12 @@ func TestAuthZPluginErrorResponse(t *testing.T) { ctrl.resRes.Err = errorMessage client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Ensure command is blocked _, err = client.ServerVersion(context.Background()) - require.NotNil(t, err) - require.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiResponse, errorMessage), err.Error()) + assert.Assert(t, err != nil) + assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiResponse, errorMessage), err.Error()) } func TestAuthZPluginErrorRequest(t *testing.T) { @@ -317,12 +317,12 @@ func TestAuthZPluginErrorRequest(t *testing.T) { ctrl.reqRes.Err = errorMessage client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Ensure command is blocked _, err = client.ServerVersion(context.Background()) - require.NotNil(t, err) - require.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiRequest, errorMessage), err.Error()) + assert.Assert(t, err != nil) + assert.Equal(t, fmt.Sprintf("Error response from daemon: plugin %s failed with error: %s: %s", testAuthZPlugin, authorization.AuthZApiRequest, errorMessage), err.Error()) } func TestAuthZPluginEnsureNoDuplicatePluginRegistration(t *testing.T) { @@ -333,14 +333,14 @@ func TestAuthZPluginEnsureNoDuplicatePluginRegistration(t *testing.T) { ctrl.resRes.Allow = true client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) _, err = client.ServerVersion(context.Background()) - require.Nil(t, err) + assert.NilError(t, err) // assert plugin is only called once.. - require.Equal(t, 1, ctrl.versionReqCount) - require.Equal(t, 1, ctrl.versionResCount) + assert.Equal(t, 1, ctrl.versionReqCount) + assert.Equal(t, 1, ctrl.versionResCount) } func TestAuthZPluginEnsureLoadImportWorking(t *testing.T) { @@ -350,36 +350,36 @@ func TestAuthZPluginEnsureLoadImportWorking(t *testing.T) { d.StartWithBusybox(t, "--authorization-plugin="+testAuthZPlugin, "--authorization-plugin="+testAuthZPlugin) client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) ctx := context.Background() tmp, err := ioutil.TempDir("", "test-authz-load-import") - require.Nil(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmp) savedImagePath := filepath.Join(tmp, "save.tar") err = imageSave(client, savedImagePath, "busybox") - require.Nil(t, err) + assert.NilError(t, err) err = imageLoad(client, savedImagePath) - require.Nil(t, err) + assert.NilError(t, err) exportedImagePath := filepath.Join(tmp, "export.tar") cID := container.Run(t, ctx, client) responseReader, err := client.ContainerExport(context.Background(), cID) - require.Nil(t, err) + assert.NilError(t, err) defer responseReader.Close() file, err := os.Create(exportedImagePath) - require.Nil(t, err) + assert.NilError(t, err) defer file.Close() _, err = io.Copy(file, responseReader) - require.Nil(t, err) + assert.NilError(t, err) err = imageImport(client, exportedImagePath) - require.Nil(t, err) + assert.NilError(t, err) } func imageSave(client client.APIClient, path, image string) error { @@ -442,16 +442,16 @@ func TestAuthZPluginHeader(t *testing.T) { d.StartWithBusybox(t, "--debug", "--authorization-plugin="+testAuthZPlugin) daemonURL, err := url.Parse(d.Sock()) - require.Nil(t, err) + assert.NilError(t, err) conn, err := net.DialTimeout(daemonURL.Scheme, daemonURL.Path, time.Second*10) - require.Nil(t, err) + assert.NilError(t, err) client := httputil.NewClientConn(conn, nil) req, err := http.NewRequest("GET", "/version", nil) - require.Nil(t, err) + assert.NilError(t, err) resp, err := client.Do(req) - require.Nil(t, err) - require.Equal(t, "application/json", resp.Header["Content-Type"][0]) + assert.NilError(t, err) + assert.Equal(t, "application/json", resp.Header["Content-Type"][0]) } // assertURIRecorded verifies that the given URI was sent and recorded diff --git a/components/engine/integration/plugin/authz/authz_plugin_v2_test.go b/components/engine/integration/plugin/authz/authz_plugin_v2_test.go index 5efa421e88..fa3d37dc8c 100644 --- a/components/engine/integration/plugin/authz/authz_plugin_v2_test.go +++ b/components/engine/integration/plugin/authz/authz_plugin_v2_test.go @@ -16,8 +16,8 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/requirement" + "github.com/gotestyourself/gotestyourself/assert" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/require" ) var ( @@ -44,13 +44,13 @@ func TestAuthZPluginV2AllowNonVolumeRequest(t *testing.T) { defer setupTestV2(t)() client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) ctx := context.Background() // Install authz plugin err = pluginInstallGrantAllPermissions(client, authzPluginNameWithTag) - require.Nil(t, err) + assert.NilError(t, err) // start the daemon with the plugin and load busybox, --net=none build fails otherwise // because it needs to pull busybox d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag) @@ -60,7 +60,7 @@ func TestAuthZPluginV2AllowNonVolumeRequest(t *testing.T) { cID := container.Run(t, ctx, client) _, err = client.ContainerInspect(ctx, cID) - require.Nil(t, err) + assert.NilError(t, err) } func TestAuthZPluginV2Disable(t *testing.T) { @@ -68,26 +68,26 @@ func TestAuthZPluginV2Disable(t *testing.T) { defer setupTestV2(t)() client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Install authz plugin err = pluginInstallGrantAllPermissions(client, authzPluginNameWithTag) - require.Nil(t, err) + assert.NilError(t, err) d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag) d.LoadBusybox(t) _, err = client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{Driver: "local"}) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) + assert.Assert(t, err != nil) + assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) // disable the plugin err = client.PluginDisable(context.Background(), authzPluginNameWithTag, types.PluginDisableOptions{}) - require.Nil(t, err) + assert.NilError(t, err) // now test to see if the docker api works. _, err = client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{Driver: "local"}) - require.Nil(t, err) + assert.NilError(t, err) } func TestAuthZPluginV2RejectVolumeRequests(t *testing.T) { @@ -95,35 +95,35 @@ func TestAuthZPluginV2RejectVolumeRequests(t *testing.T) { defer setupTestV2(t)() client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Install authz plugin err = pluginInstallGrantAllPermissions(client, authzPluginNameWithTag) - require.Nil(t, err) + assert.NilError(t, err) // restart the daemon with the plugin d.Restart(t, "--authorization-plugin="+authzPluginNameWithTag) _, err = client.VolumeCreate(context.Background(), volumetypes.VolumesCreateBody{Driver: "local"}) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) + assert.Assert(t, err != nil) + assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) _, err = client.VolumeList(context.Background(), filters.Args{}) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) + assert.Assert(t, err != nil) + assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) // The plugin will block the command before it can determine the volume does not exist err = client.VolumeRemove(context.Background(), "test", false) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) + assert.Assert(t, err != nil) + assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) _, err = client.VolumeInspect(context.Background(), "test") - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) + assert.Assert(t, err != nil) + assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) _, err = client.VolumesPrune(context.Background(), filters.Args{}) - require.NotNil(t, err) - require.True(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) + assert.Assert(t, err != nil) + assert.Assert(t, strings.Contains(err.Error(), fmt.Sprintf("Error response from daemon: plugin %s failed with error:", authzPluginNameWithTag))) } func TestAuthZPluginV2BadManifestFailsDaemonStart(t *testing.T) { @@ -131,15 +131,15 @@ func TestAuthZPluginV2BadManifestFailsDaemonStart(t *testing.T) { defer setupTestV2(t)() client, err := d.NewClient() - require.Nil(t, err) + assert.NilError(t, err) // Install authz plugin with bad manifest err = pluginInstallGrantAllPermissions(client, authzPluginBadManifestName) - require.Nil(t, err) + assert.NilError(t, err) // start the daemon with the plugin, it will error err = d.RestartWithError("--authorization-plugin=" + authzPluginBadManifestName) - require.NotNil(t, err) + assert.Assert(t, err != nil) // restarting the daemon without requiring the plugin will succeed d.Start(t) @@ -150,7 +150,7 @@ func TestAuthZPluginV2NonexistentFailsDaemonStart(t *testing.T) { // start the daemon with a non-existent authz plugin, it will error err := d.RestartWithError("--authorization-plugin=" + nonexistentAuthzPluginName) - require.NotNil(t, err) + assert.Assert(t, err != nil) // restarting the daemon without requiring the plugin will succeed d.Start(t) diff --git a/components/engine/integration/plugin/logging/validation_test.go b/components/engine/integration/plugin/logging/validation_test.go index 6607321613..eb3fe7a029 100644 --- a/components/engine/integration/plugin/logging/validation_test.go +++ b/components/engine/integration/plugin/logging/validation_test.go @@ -6,7 +6,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration-cli/daemon" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" ) // Regression test for #35553 @@ -20,12 +20,12 @@ func TestDaemonStartWithLogOpt(t *testing.T) { defer d.Stop(t) client, err := d.NewClient() - assert.NoError(t, err) + assert.Check(t, err) ctx := context.Background() createPlugin(t, client, "test", "dummy", asLogDriver) err = client.PluginEnable(ctx, "test", types.PluginEnableOptions{Timeout: 30}) - assert.NoError(t, err) + assert.Check(t, err) defer client.PluginRemove(ctx, "test", types.PluginRemoveOptions{Force: true}) d.Stop(t) diff --git a/components/engine/integration/secret/secret_test.go b/components/engine/integration/secret/secret_test.go index 27c8fd3d0e..4a1e1b3dc7 100644 --- a/components/engine/integration/secret/secret_test.go +++ b/components/engine/integration/secret/secret_test.go @@ -13,9 +13,9 @@ import ( "github.com/docker/docker/integration/internal/swarm" "github.com/docker/docker/internal/testutil" "github.com/docker/docker/pkg/stdcopy" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -26,7 +26,7 @@ func TestSecretInspect(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -34,12 +34,12 @@ func TestSecretInspect(t *testing.T) { secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) secret, _, err := client.SecretInspectWithRaw(context.Background(), secretID) - require.NoError(t, err) - assert.Equal(t, secret.Spec.Name, testName) + assert.NilError(t, err) + assert.Check(t, is.Equal(secret.Spec.Name, testName)) secret, _, err = client.SecretInspectWithRaw(context.Background(), testName) - require.NoError(t, err) - assert.Equal(t, secretID, secretID) + assert.NilError(t, err) + assert.Check(t, is.Equal(secretID, secretID)) } func TestSecretList(t *testing.T) { @@ -49,7 +49,7 @@ func TestSecretList(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -75,8 +75,8 @@ func TestSecretList(t *testing.T) { // test by `secret ls` entries, err := client.SecretList(ctx, types.SecretListOptions{}) - require.NoError(t, err) - assert.Equal(t, names(entries), testNames) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(names(entries), testNames)) testCases := []struct { filters filters.Args @@ -110,8 +110,8 @@ func TestSecretList(t *testing.T) { entries, err = client.SecretList(ctx, types.SecretListOptions{ Filters: tc.filters, }) - require.NoError(t, err) - assert.Equal(t, names(entries), tc.expected) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(names(entries), tc.expected)) } } @@ -124,8 +124,8 @@ func createSecret(ctx context.Context, t *testing.T, client client.APIClient, na }, Data: data, }) - require.NoError(t, err) - assert.NotEqual(t, secret.ID, "") + assert.NilError(t, err) + assert.Check(t, secret.ID != "") return secret.ID } @@ -136,7 +136,7 @@ func TestSecretsCreateAndDelete(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() @@ -154,7 +154,7 @@ func TestSecretsCreateAndDelete(t *testing.T) { // Ported from original TestSecretsDelete err = client.SecretRemove(ctx, secretID) - require.NoError(t, err) + assert.NilError(t, err) _, _, err = client.SecretInspectWithRaw(ctx, secretID) testutil.ErrorContains(t, err, "No such secret") @@ -170,11 +170,11 @@ func TestSecretsCreateAndDelete(t *testing.T) { }) insp, _, err := client.SecretInspectWithRaw(ctx, secretID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Name, testName) - assert.Equal(t, len(insp.Spec.Labels), 2) - assert.Equal(t, insp.Spec.Labels["key1"], "value1") - assert.Equal(t, insp.Spec.Labels["key2"], "value2") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Name, testName)) + assert.Check(t, is.Equal(len(insp.Spec.Labels), 2)) + assert.Check(t, is.Equal(insp.Spec.Labels["key1"], "value1")) + assert.Check(t, is.Equal(insp.Spec.Labels["key2"], "value2")) } func TestSecretsUpdate(t *testing.T) { @@ -184,44 +184,44 @@ func TestSecretsUpdate(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() testName := "test_secret" secretID := createSecret(ctx, t, client, testName, []byte("TESTINGDATA"), nil) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err := client.SecretInspectWithRaw(ctx, secretID) - require.NoError(t, err) - assert.Equal(t, insp.ID, secretID) + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.ID, secretID)) // test UpdateSecret with full ID insp.Spec.Labels = map[string]string{"test": "test1"} err = client.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.SecretInspectWithRaw(ctx, secretID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Labels["test"], "test1") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test1")) // test UpdateSecret with full name insp.Spec.Labels = map[string]string{"test": "test2"} err = client.SecretUpdate(ctx, testName, insp.Version, insp.Spec) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.SecretInspectWithRaw(ctx, secretID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Labels["test"], "test2") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test2")) // test UpdateSecret with prefix ID insp.Spec.Labels = map[string]string{"test": "test3"} err = client.SecretUpdate(ctx, secretID[:1], insp.Version, insp.Spec) - require.NoError(t, err) + assert.NilError(t, err) insp, _, err = client.SecretInspectWithRaw(ctx, secretID) - require.NoError(t, err) - assert.Equal(t, insp.Spec.Labels["test"], "test3") + assert.NilError(t, err) + assert.Check(t, is.Equal(insp.Spec.Labels["test"], "test3")) // test UpdateSecret in updating Data which is not supported in daemon // this test will produce an error in func UpdateSecret @@ -244,7 +244,7 @@ func TestTemplatedSecret(t *testing.T) { Data: []byte("this is a secret"), } referencedSecret, err := client.SecretCreate(ctx, referencedSecretSpec) - assert.NoError(t, err) + assert.Check(t, err) referencedConfigSpec := swarmtypes.ConfigSpec{ Annotations: swarmtypes.Annotations{ @@ -253,7 +253,7 @@ func TestTemplatedSecret(t *testing.T) { Data: []byte("this is a config"), } referencedConfig, err := client.ConfigCreate(ctx, referencedConfigSpec) - assert.NoError(t, err) + assert.Check(t, err) secretSpec := swarmtypes.SecretSpec{ Annotations: swarmtypes.Annotations{ @@ -268,7 +268,7 @@ func TestTemplatedSecret(t *testing.T) { } templatedSecret, err := client.SecretCreate(ctx, secretSpec) - assert.NoError(t, err) + assert.Check(t, err) serviceID := swarm.CreateService(t, d, swarm.ServiceWithSecret( @@ -346,8 +346,8 @@ func TestTemplatedSecret(t *testing.T) { func assertAttachedStream(t *testing.T, attach types.HijackedResponse, expect string) { buf := bytes.NewBuffer(nil) _, err := stdcopy.StdCopy(buf, buf, attach.Reader) - require.NoError(t, err) - assert.Contains(t, buf.String(), expect) + assert.NilError(t, err) + assert.Check(t, is.Contains(buf.String(), expect)) } func waitAndAssert(t *testing.T, timeout time.Duration, f func(*testing.T) bool) { diff --git a/components/engine/integration/service/create_test.go b/components/engine/integration/service/create_test.go index eb66cfc2f1..7170bda492 100644 --- a/components/engine/integration/service/create_test.go +++ b/components/engine/integration/service/create_test.go @@ -11,9 +11,9 @@ import ( swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/swarm" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -22,7 +22,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) overlayName := "overlay1" networkCreate := types.NetworkCreate{ @@ -31,7 +31,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) { } netResp, err := client.NetworkCreate(context.Background(), overlayName, networkCreate) - require.NoError(t, err) + assert.NilError(t, err) overlayID := netResp.ID var instances uint64 = 4 @@ -41,7 +41,7 @@ func TestCreateServiceMultipleTimes(t *testing.T) { serviceResp, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) pollSettings := func(config *poll.Settings) { // It takes about ~25s to finish the multi services creation in this case per the pratical observation on arm64/arm platform @@ -55,10 +55,10 @@ func TestCreateServiceMultipleTimes(t *testing.T) { poll.WaitOn(t, serviceRunningTasksCount(client, serviceID, instances), pollSettings) _, _, err = client.ServiceInspectWithRaw(context.Background(), serviceID, types.ServiceInspectOptions{}) - require.NoError(t, err) + assert.NilError(t, err) err = client.ServiceRemove(context.Background(), serviceID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings) @@ -66,19 +66,19 @@ func TestCreateServiceMultipleTimes(t *testing.T) { serviceResp, err = client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) serviceID2 := serviceResp.ID poll.WaitOn(t, serviceRunningTasksCount(client, serviceID2, instances), pollSettings) err = client.ServiceRemove(context.Background(), serviceID2) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceID2), pollSettings) poll.WaitOn(t, noTasks(client), pollSettings) err = client.NetworkRemove(context.Background(), overlayID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, networkIsRemoved(client, overlayID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) } @@ -88,7 +88,7 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) name := "foo" networkCreate := types.NetworkCreate{ @@ -97,15 +97,15 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { } n1, err := client.NetworkCreate(context.Background(), name, networkCreate) - require.NoError(t, err) + assert.NilError(t, err) n2, err := client.NetworkCreate(context.Background(), name, networkCreate) - require.NoError(t, err) + assert.NilError(t, err) // Dupliates with name but with different driver networkCreate.Driver = "overlay" n3, err := client.NetworkCreate(context.Background(), name, networkCreate) - require.NoError(t, err) + assert.NilError(t, err) // Create Service with the same name var instances uint64 = 1 @@ -114,30 +114,30 @@ func TestCreateWithDuplicateNetworkNames(t *testing.T) { serviceSpec.TaskTemplate.Networks = append(serviceSpec.TaskTemplate.Networks, swarmtypes.NetworkAttachmentConfig{Target: name}) service, err := client.ServiceCreate(context.Background(), serviceSpec, types.ServiceCreateOptions{}) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceRunningTasksCount(client, service.ID, instances)) resp, _, err := client.ServiceInspectWithRaw(context.Background(), service.ID, types.ServiceInspectOptions{}) - require.NoError(t, err) - assert.Equal(t, n3.ID, resp.Spec.TaskTemplate.Networks[0].Target) + assert.NilError(t, err) + assert.Check(t, is.Equal(n3.ID, resp.Spec.TaskTemplate.Networks[0].Target)) // Remove Service err = client.ServiceRemove(context.Background(), service.ID) - require.NoError(t, err) + assert.NilError(t, err) // Make sure task has been destroyed. poll.WaitOn(t, serviceIsRemoved(client, service.ID)) // Remove networks err = client.NetworkRemove(context.Background(), n3.ID) - require.NoError(t, err) + assert.NilError(t, err) err = client.NetworkRemove(context.Background(), n2.ID) - require.NoError(t, err) + assert.NilError(t, err) err = client.NetworkRemove(context.Background(), n1.ID) - require.NoError(t, err) + assert.NilError(t, err) // Make sure networks have been destroyed. poll.WaitOn(t, networkIsRemoved(client, n3.ID), poll.WithTimeout(1*time.Minute), poll.WithDelay(10*time.Second)) @@ -150,7 +150,7 @@ func TestCreateServiceSecretFileMode(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() secretResp, err := client.SecretCreate(ctx, swarmtypes.SecretSpec{ @@ -159,7 +159,7 @@ func TestCreateServiceSecretFileMode(t *testing.T) { }, Data: []byte("TESTSECRET"), }) - require.NoError(t, err) + assert.NilError(t, err) var instances uint64 = 1 serviceSpec := swarmtypes.ServiceSpec{ @@ -194,7 +194,7 @@ func TestCreateServiceSecretFileMode(t *testing.T) { serviceResp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances)) @@ -203,27 +203,27 @@ func TestCreateServiceSecretFileMode(t *testing.T) { tasks, err := client.TaskList(ctx, types.TaskListOptions{ Filters: filter, }) - require.NoError(t, err) - assert.Equal(t, len(tasks), 1) + assert.NilError(t, err) + assert.Check(t, is.Equal(len(tasks), 1)) body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{ ShowStdout: true, }) - require.NoError(t, err) + assert.NilError(t, err) defer body.Close() content, err := ioutil.ReadAll(body) - require.NoError(t, err) - assert.Contains(t, string(content), "-rwxrwxrwx") + assert.NilError(t, err) + assert.Check(t, is.Contains(string(content), "-rwxrwxrwx")) err = client.ServiceRemove(ctx, serviceResp.ID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID)) poll.WaitOn(t, noTasks(client)) err = client.SecretRemove(ctx, "TestSecret") - require.NoError(t, err) + assert.NilError(t, err) } func TestCreateServiceConfigFileMode(t *testing.T) { @@ -231,7 +231,7 @@ func TestCreateServiceConfigFileMode(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() configResp, err := client.ConfigCreate(ctx, swarmtypes.ConfigSpec{ @@ -240,7 +240,7 @@ func TestCreateServiceConfigFileMode(t *testing.T) { }, Data: []byte("TESTCONFIG"), }) - require.NoError(t, err) + assert.NilError(t, err) var instances uint64 = 1 serviceSpec := swarmtypes.ServiceSpec{ @@ -275,7 +275,7 @@ func TestCreateServiceConfigFileMode(t *testing.T) { serviceResp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceRunningTasksCount(client, serviceResp.ID, instances)) @@ -284,27 +284,27 @@ func TestCreateServiceConfigFileMode(t *testing.T) { tasks, err := client.TaskList(ctx, types.TaskListOptions{ Filters: filter, }) - require.NoError(t, err) - assert.Equal(t, len(tasks), 1) + assert.NilError(t, err) + assert.Check(t, is.Equal(len(tasks), 1)) body, err := client.ContainerLogs(ctx, tasks[0].Status.ContainerStatus.ContainerID, types.ContainerLogsOptions{ ShowStdout: true, }) - require.NoError(t, err) + assert.NilError(t, err) defer body.Close() content, err := ioutil.ReadAll(body) - require.NoError(t, err) - assert.Contains(t, string(content), "-rwxrwxrwx") + assert.NilError(t, err) + assert.Check(t, is.Contains(string(content), "-rwxrwxrwx")) err = client.ServiceRemove(ctx, serviceResp.ID) - require.NoError(t, err) + assert.NilError(t, err) poll.WaitOn(t, serviceIsRemoved(client, serviceResp.ID)) poll.WaitOn(t, noTasks(client)) err = client.ConfigRemove(ctx, "TestConfig") - require.NoError(t, err) + assert.NilError(t, err) } func swarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec { diff --git a/components/engine/integration/service/inspect_test.go b/components/engine/integration/service/inspect_test.go index 8cd24bc31b..d4d342e643 100644 --- a/components/engine/integration/service/inspect_test.go +++ b/components/engine/integration/service/inspect_test.go @@ -10,22 +10,23 @@ import ( swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/swarm" + "github.com/google/go-cmp/cmp" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/net/context" ) func TestInspect(t *testing.T) { - skip.IfCondition(t, testEnv.IsRemoteDaemon()) + skip.If(t, testEnv.IsRemoteDaemon()) defer setupTest(t)() d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) - var before = time.Now() + var now = time.Now() var instances uint64 = 2 serviceSpec := fullSwarmServiceSpec("test-service-inspect", instances) @@ -33,18 +34,43 @@ func TestInspect(t *testing.T) { resp, err := client.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{ QueryRegistry: false, }) - require.NoError(t, err) + assert.NilError(t, err) id := resp.ID poll.WaitOn(t, serviceContainerCount(client, id, instances)) service, _, err := client.ServiceInspectWithRaw(ctx, id, types.ServiceInspectOptions{}) - require.NoError(t, err) - assert.Equal(t, serviceSpec, service.Spec) - assert.Equal(t, uint64(11), service.Meta.Version.Index) - assert.Equal(t, id, service.ID) - assert.WithinDuration(t, before, service.CreatedAt, 30*time.Second) - assert.WithinDuration(t, before, service.UpdatedAt, 30*time.Second) + assert.NilError(t, err) + + expected := swarmtypes.Service{ + ID: id, + Spec: serviceSpec, + Meta: swarmtypes.Meta{ + Version: swarmtypes.Version{Index: uint64(11)}, + CreatedAt: now, + UpdatedAt: now, + }, + } + assert.Check(t, is.DeepEqual(service, expected, cmpServiceOpts())) +} + +// TODO: use helpers from gotestyourself/assert/opt when available +func cmpServiceOpts() cmp.Option { + const threshold = 20 * time.Second + + metaTimeFields := func(path cmp.Path) bool { + switch path.String() { + case "Meta.CreatedAt", "Meta.UpdatedAt": + return true + } + return false + } + withinThreshold := cmp.Comparer(func(x, y time.Time) bool { + delta := x.Sub(y) + return delta < threshold && delta > -threshold + }) + + return cmp.FilterPath(metaTimeFields, withinThreshold) } func fullSwarmServiceSpec(name string, replicas uint64) swarmtypes.ServiceSpec { diff --git a/components/engine/integration/service/network_test.go b/components/engine/integration/service/network_test.go index 09b0a1f12b..6b8c891cd8 100644 --- a/components/engine/integration/service/network_test.go +++ b/components/engine/integration/service/network_test.go @@ -9,8 +9,8 @@ import ( "github.com/docker/docker/client" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/swarm" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestDockerNetworkConnectAlias(t *testing.T) { @@ -18,7 +18,7 @@ func TestDockerNetworkConnectAlias(t *testing.T) { d := swarm.NewSwarm(t, testEnv) defer d.Stop(t) client, err := client.NewClientWithOpts(client.WithHost((d.Sock()))) - require.NoError(t, err) + assert.NilError(t, err) ctx := context.Background() name := "test-alias" @@ -26,7 +26,7 @@ func TestDockerNetworkConnectAlias(t *testing.T) { Driver: "overlay", Attachable: true, }) - require.NoError(t, err) + assert.NilError(t, err) container.Create(t, ctx, client, container.WithName("ng1"), func(c *container.TestContainerConfig) { c.NetworkingConfig = &network.NetworkingConfig{ @@ -41,15 +41,15 @@ func TestDockerNetworkConnectAlias(t *testing.T) { "aaa", }, }) - require.NoError(t, err) + assert.NilError(t, err) err = client.ContainerStart(ctx, "ng1", types.ContainerStartOptions{}) - require.NoError(t, err) + assert.NilError(t, err) ng1, err := client.ContainerInspect(ctx, "ng1") - require.NoError(t, err) - assert.Equal(t, len(ng1.NetworkSettings.Networks[name].Aliases), 2) - assert.Equal(t, ng1.NetworkSettings.Networks[name].Aliases[0], "aaa") + assert.NilError(t, err) + assert.Check(t, is.Equal(len(ng1.NetworkSettings.Networks[name].Aliases), 2)) + assert.Check(t, is.Equal(ng1.NetworkSettings.Networks[name].Aliases[0], "aaa")) container.Create(t, ctx, client, container.WithName("ng2"), func(c *container.TestContainerConfig) { c.NetworkingConfig = &network.NetworkingConfig{ @@ -64,13 +64,13 @@ func TestDockerNetworkConnectAlias(t *testing.T) { "bbb", }, }) - require.NoError(t, err) + assert.NilError(t, err) err = client.ContainerStart(ctx, "ng2", types.ContainerStartOptions{}) - require.NoError(t, err) + assert.NilError(t, err) ng2, err := client.ContainerInspect(ctx, "ng2") - require.NoError(t, err) - assert.Equal(t, len(ng2.NetworkSettings.Networks[name].Aliases), 2) - assert.Equal(t, ng2.NetworkSettings.Networks[name].Aliases[0], "bbb") + assert.NilError(t, err) + assert.Check(t, is.Equal(len(ng2.NetworkSettings.Networks[name].Aliases), 2)) + assert.Check(t, is.Equal(ng2.NetworkSettings.Networks[name].Aliases[0], "bbb")) } diff --git a/components/engine/integration/session/session_test.go b/components/engine/integration/session/session_test.go index 310f544554..de9319436e 100644 --- a/components/engine/integration/session/session_test.go +++ b/components/engine/integration/session/session_test.go @@ -5,9 +5,9 @@ import ( "testing" req "github.com/docker/docker/integration-cli/request" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) func TestSessionCreate(t *testing.T) { @@ -20,29 +20,29 @@ func TestSessionCreate(t *testing.T) { r.Header.Set("Upgrade", "h2c") return nil }) - require.NoError(t, err) - require.NoError(t, body.Close()) - assert.Equal(t, res.StatusCode, http.StatusSwitchingProtocols) - assert.Equal(t, res.Header.Get("Upgrade"), "h2c") + assert.NilError(t, err) + assert.NilError(t, body.Close()) + assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusSwitchingProtocols)) + assert.Check(t, is.Equal(res.Header.Get("Upgrade"), "h2c")) } func TestSessionCreateWithBadUpgrade(t *testing.T) { skip.If(t, !testEnv.DaemonInfo.ExperimentalBuild) res, body, err := req.Post("/session") - require.NoError(t, err) - assert.Equal(t, res.StatusCode, http.StatusBadRequest) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest)) buf, err := req.ReadBody(body) - require.NoError(t, err) - assert.Contains(t, string(buf), "no upgrade") + assert.NilError(t, err) + assert.Check(t, is.Contains(string(buf), "no upgrade")) res, body, err = req.Post("/session", func(r *http.Request) error { r.Header.Set("Upgrade", "foo") return nil }) - require.NoError(t, err) - assert.Equal(t, res.StatusCode, http.StatusBadRequest) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusBadRequest)) buf, err = req.ReadBody(body) - require.NoError(t, err) - assert.Contains(t, string(buf), "not supported") + assert.NilError(t, err) + assert.Check(t, is.Contains(string(buf), "not supported")) } diff --git a/components/engine/integration/system/event_test.go b/components/engine/integration/system/event_test.go index 688d7c27de..b270ffcb91 100644 --- a/components/engine/integration/system/event_test.go +++ b/components/engine/integration/system/event_test.go @@ -17,8 +17,8 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/pkg/jsonmessage" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestEvents(t *testing.T) { @@ -33,7 +33,7 @@ func TestEvents(t *testing.T) { Cmd: strslice.StrSlice([]string{"echo", "hello"}), }, ) - require.NoError(t, err) + assert.NilError(t, err) filters := filters.NewArgs( filters.Arg("container", cID), @@ -49,15 +49,15 @@ func TestEvents(t *testing.T) { Tty: false, }, ) - require.NoError(t, err) + assert.NilError(t, err) select { case m := <-msg: - require.Equal(t, m.Type, "container") - require.Equal(t, m.Actor.ID, cID) - require.Equal(t, m.Action, "exec_die") - require.Equal(t, m.Actor.Attributes["execID"], id.ID) - require.Equal(t, m.Actor.Attributes["exitCode"], "0") + assert.Equal(t, m.Type, "container") + assert.Equal(t, m.Actor.ID, cID) + assert.Equal(t, m.Action, "exec_die") + assert.Equal(t, m.Actor.Attributes["execID"], id.ID) + assert.Equal(t, m.Actor.Attributes["exitCode"], "0") case err = <-errors: t.Fatal(err) case <-time.After(time.Second * 3): @@ -84,16 +84,16 @@ func TestEventsBackwardsCompatible(t *testing.T) { // The test here makes sure the response time is less than 3 sec. expectedTime := time.Now().Add(3 * time.Second) emptyResp, emptyBody, err := req.Get("/events") - require.NoError(t, err) + assert.NilError(t, err) defer emptyBody.Close() - assert.Equal(t, http.StatusOK, emptyResp.StatusCode) - assert.True(t, time.Now().Before(expectedTime), "timeout waiting for events api to respond, should have responded immediately") + assert.Check(t, is.DeepEqual(http.StatusOK, emptyResp.StatusCode)) + assert.Check(t, time.Now().Before(expectedTime), "timeout waiting for events api to respond, should have responded immediately") // We also test to make sure the `events.Message` is compatible with `JSONMessage` q := url.Values{} q.Set("since", ts) _, body, err := req.Get("/events?" + q.Encode()) - require.NoError(t, err) + assert.NilError(t, err) defer body.Close() dec := json.NewDecoder(body) @@ -112,8 +112,8 @@ func TestEventsBackwardsCompatible(t *testing.T) { } } - assert.NotNil(t, containerCreateEvent) - assert.Equal(t, "create", containerCreateEvent.Status) - assert.Equal(t, cID, containerCreateEvent.ID) - assert.Equal(t, "busybox", containerCreateEvent.From) + assert.Check(t, containerCreateEvent != nil) + assert.Check(t, is.Equal("create", containerCreateEvent.Status)) + assert.Check(t, is.Equal(cID, containerCreateEvent.ID)) + assert.Check(t, is.Equal("busybox", containerCreateEvent.From)) } diff --git a/components/engine/integration/system/info_linux_test.go b/components/engine/integration/system/info_linux_test.go index 8f0271e7a6..e8bf70f9b8 100644 --- a/components/engine/integration/system/info_linux_test.go +++ b/components/engine/integration/system/info_linux_test.go @@ -8,8 +8,8 @@ import ( req "github.com/docker/docker/integration-cli/request" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -17,35 +17,32 @@ func TestInfoBinaryCommits(t *testing.T) { client := request.NewAPIClient(t) info, err := client.Info(context.Background()) - require.NoError(t, err) + assert.NilError(t, err) - assert.NotNil(t, info.ContainerdCommit) - assert.NotEqual(t, "N/A", info.ContainerdCommit.ID) - assert.Equal(t, testEnv.DaemonInfo.ContainerdCommit.Expected, info.ContainerdCommit.Expected) - assert.Equal(t, info.ContainerdCommit.Expected, info.ContainerdCommit.ID) + assert.Check(t, "N/A" != info.ContainerdCommit.ID) + assert.Check(t, is.Equal(testEnv.DaemonInfo.ContainerdCommit.Expected, info.ContainerdCommit.Expected)) + assert.Check(t, is.Equal(info.ContainerdCommit.Expected, info.ContainerdCommit.ID)) - assert.NotNil(t, info.InitCommit) - assert.NotEqual(t, "N/A", info.InitCommit.ID) - assert.Equal(t, testEnv.DaemonInfo.InitCommit.Expected, info.InitCommit.Expected) - assert.Equal(t, info.InitCommit.Expected, info.InitCommit.ID) + assert.Check(t, "N/A" != info.InitCommit.ID) + assert.Check(t, is.Equal(testEnv.DaemonInfo.InitCommit.Expected, info.InitCommit.Expected)) + assert.Check(t, is.Equal(info.InitCommit.Expected, info.InitCommit.ID)) - assert.NotNil(t, info.RuncCommit) - assert.NotEqual(t, "N/A", info.RuncCommit.ID) - assert.Equal(t, testEnv.DaemonInfo.RuncCommit.Expected, info.RuncCommit.Expected) - assert.Equal(t, info.RuncCommit.Expected, info.RuncCommit.ID) + assert.Check(t, "N/A" != info.RuncCommit.ID) + assert.Check(t, is.Equal(testEnv.DaemonInfo.RuncCommit.Expected, info.RuncCommit.Expected)) + assert.Check(t, is.Equal(info.RuncCommit.Expected, info.RuncCommit.ID)) } func TestInfoAPIVersioned(t *testing.T) { // Windows only supports 1.25 or later res, body, err := req.Get("/v1.20/info") - require.NoError(t, err) - assert.Equal(t, res.StatusCode, http.StatusOK) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual(res.StatusCode, http.StatusOK)) b, err := req.ReadBody(body) - require.NoError(t, err) + assert.NilError(t, err) out := string(b) - assert.Contains(t, out, "ExecutionDriver") - assert.Contains(t, out, "not supported") + assert.Check(t, is.Contains(out, "ExecutionDriver")) + assert.Check(t, is.Contains(out, "not supported")) } diff --git a/components/engine/integration/system/info_test.go b/components/engine/integration/system/info_test.go index d04fdcdc84..e19ba9ba3d 100644 --- a/components/engine/integration/system/info_test.go +++ b/components/engine/integration/system/info_test.go @@ -5,8 +5,8 @@ import ( "testing" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -14,7 +14,7 @@ func TestInfoAPI(t *testing.T) { client := request.NewAPIClient(t) info, err := client.Info(context.Background()) - require.NoError(t, err) + assert.NilError(t, err) // always shown fields stringsToCheck := []string{ @@ -37,6 +37,6 @@ func TestInfoAPI(t *testing.T) { out := fmt.Sprintf("%+v", info) for _, linePrefix := range stringsToCheck { - assert.Contains(t, out, linePrefix) + assert.Check(t, is.Contains(out, linePrefix)) } } diff --git a/components/engine/integration/system/login_test.go b/components/engine/integration/system/login_test.go index c075109d2b..e8ef10c30c 100644 --- a/components/engine/integration/system/login_test.go +++ b/components/engine/integration/system/login_test.go @@ -6,8 +6,9 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/integration/internal/requirement" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -23,5 +24,5 @@ func TestLoginFailsWithBadCredentials(t *testing.T) { } _, err := client.RegistryLogin(context.Background(), config) expected := "Error response from daemon: Get https://registry-1.docker.io/v2/: unauthorized: incorrect username or password" - assert.EqualError(t, err, expected) + assert.Check(t, is.Error(err, expected)) } diff --git a/components/engine/integration/system/version_test.go b/components/engine/integration/system/version_test.go index 04888a604a..38784e3ee9 100644 --- a/components/engine/integration/system/version_test.go +++ b/components/engine/integration/system/version_test.go @@ -4,8 +4,8 @@ import ( "testing" "github.com/docker/docker/integration/internal/request" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -13,11 +13,11 @@ func TestVersion(t *testing.T) { client := request.NewAPIClient(t) version, err := client.ServerVersion(context.Background()) - require.NoError(t, err) + assert.NilError(t, err) - assert.NotNil(t, version.APIVersion) - assert.NotNil(t, version.Version) - assert.NotNil(t, version.MinAPIVersion) - assert.Equal(t, testEnv.DaemonInfo.ExperimentalBuild, version.Experimental) - assert.Equal(t, testEnv.OSType, version.Os) + assert.Check(t, version.APIVersion != "") + assert.Check(t, version.Version != "") + assert.Check(t, version.MinAPIVersion != "") + assert.Check(t, is.Equal(testEnv.DaemonInfo.ExperimentalBuild, version.Experimental)) + assert.Check(t, is.Equal(testEnv.OSType, version.Os)) } diff --git a/components/engine/integration/volume/volume_test.go b/components/engine/integration/volume/volume_test.go index 20dcfef9a6..2fe35cf5ed 100644 --- a/components/engine/integration/volume/volume_test.go +++ b/components/engine/integration/volume/volume_test.go @@ -13,8 +13,8 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/integration/internal/request" "github.com/docker/docker/internal/testutil" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestVolumesCreateAndList(t *testing.T) { @@ -26,7 +26,7 @@ func TestVolumesCreateAndList(t *testing.T) { vol, err := client.VolumeCreate(ctx, volumetypes.VolumesCreateBody{ Name: name, }) - require.NoError(t, err) + assert.NilError(t, err) expected := types.Volume{ // Ignore timestamp of CreatedAt @@ -36,14 +36,14 @@ func TestVolumesCreateAndList(t *testing.T) { Name: name, Mountpoint: fmt.Sprintf("%s/volumes/%s/_data", testEnv.DaemonInfo.DockerRootDir, name), } - assert.Equal(t, vol, expected) + assert.Check(t, is.DeepEqual(vol, expected)) volumes, err := client.VolumeList(ctx, filters.Args{}) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, len(volumes.Volumes), 1) - assert.NotNil(t, volumes.Volumes[0]) - assert.Equal(t, *volumes.Volumes[0], expected) + assert.Check(t, is.Equal(len(volumes.Volumes), 1)) + assert.Check(t, volumes.Volumes[0] != nil) + assert.Check(t, is.DeepEqual(*volumes.Volumes[0], expected)) } func TestVolumesRemove(t *testing.T) { @@ -56,7 +56,7 @@ func TestVolumesRemove(t *testing.T) { id := container.Create(t, ctx, client, container.WithVolume(prefix+"foo")) c, err := client.ContainerInspect(ctx, id) - require.NoError(t, err) + assert.NilError(t, err) vname := c.Mounts[0].Name err = client.VolumeRemove(ctx, vname, false) @@ -65,10 +65,10 @@ func TestVolumesRemove(t *testing.T) { err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{ Force: true, }) - require.NoError(t, err) + assert.NilError(t, err) err = client.VolumeRemove(ctx, vname, false) - require.NoError(t, err) + assert.NilError(t, err) } func TestVolumesInspect(t *testing.T) { @@ -83,10 +83,10 @@ func TestVolumesInspect(t *testing.T) { _, err := client.VolumeCreate(ctx, volumetypes.VolumesCreateBody{ Name: name, }) - require.NoError(t, err) + assert.NilError(t, err) vol, err := client.VolumeInspect(ctx, name) - require.NoError(t, err) + assert.NilError(t, err) expected := types.Volume{ // Ignore timestamp of CreatedAt @@ -96,13 +96,13 @@ func TestVolumesInspect(t *testing.T) { Name: name, Mountpoint: fmt.Sprintf("%s/volumes/%s/_data", testEnv.DaemonInfo.DockerRootDir, name), } - assert.Equal(t, vol, expected) + assert.Check(t, is.DeepEqual(vol, expected)) // comparing CreatedAt field time for the new volume to now. Removing a minute from both to avoid false positive testCreatedAt, err := time.Parse(time.RFC3339, strings.TrimSpace(vol.CreatedAt)) - require.NoError(t, err) + assert.NilError(t, err) testCreatedAt = testCreatedAt.Truncate(time.Minute) - assert.Equal(t, testCreatedAt.Equal(now), true, "Time Volume is CreatedAt not equal to current time") + assert.Check(t, is.Equal(testCreatedAt.Equal(now), true), "Time Volume is CreatedAt not equal to current time") } func getPrefixAndSlashFromDaemonPlatform() (prefix, slash string) { diff --git a/components/engine/internal/test/environment/clean.go b/components/engine/internal/test/environment/clean.go index 065b46bee8..d83175c845 100644 --- a/components/engine/internal/test/environment/clean.go +++ b/components/engine/internal/test/environment/clean.go @@ -7,13 +7,12 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/client" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" "golang.org/x/net/context" ) type testingT interface { - require.TestingT + assert.TestingT logT Fatalf(string, ...interface{}) } @@ -47,7 +46,7 @@ func unpauseAllContainers(t assert.TestingT, client client.ContainerAPIClient) { if len(containers) > 0 { for _, container := range containers { err := client.ContainerUnpause(ctx, container.ID) - assert.NoError(t, err, "failed to unpause container %s", container.ID) + assert.Check(t, err, "failed to unpause container %s", container.ID) } } } @@ -60,7 +59,7 @@ func getPausedContainers(ctx context.Context, t assert.TestingT, client client.C Quiet: true, All: true, }) - assert.NoError(t, err, "failed to list containers") + assert.Check(t, err, "failed to list containers") return containers } @@ -84,7 +83,7 @@ func deleteAllContainers(t assert.TestingT, apiclient client.ContainerAPIClient, if err == nil || client.IsErrNotFound(err) || alreadyExists.MatchString(err.Error()) || isErrNotFoundSwarmClassic(err) { continue } - assert.NoError(t, err, "failed to remove %s", container.ID) + assert.Check(t, err, "failed to remove %s", container.ID) } } @@ -93,13 +92,13 @@ func getAllContainers(ctx context.Context, t assert.TestingT, client client.Cont Quiet: true, All: true, }) - assert.NoError(t, err, "failed to list containers") + assert.Check(t, err, "failed to list containers") return containers } func deleteAllImages(t testingT, apiclient client.ImageAPIClient, protectedImages map[string]struct{}) { images, err := apiclient.ImageList(context.Background(), types.ImageListOptions{}) - assert.NoError(t, err, "failed to list images") + assert.Check(t, err, "failed to list images") ctx := context.Background() for _, image := range images { @@ -126,12 +125,12 @@ func removeImage(ctx context.Context, t assert.TestingT, apiclient client.ImageA if client.IsErrNotFound(err) { return } - assert.NoError(t, err, "failed to remove image %s", ref) + assert.Check(t, err, "failed to remove image %s", ref) } func deleteAllVolumes(t assert.TestingT, c client.VolumeAPIClient, protectedVolumes map[string]struct{}) { volumes, err := c.VolumeList(context.Background(), filters.Args{}) - assert.NoError(t, err, "failed to list volumes") + assert.Check(t, err, "failed to list volumes") for _, v := range volumes.Volumes { if _, ok := protectedVolumes[v.Name]; ok { @@ -142,13 +141,13 @@ func deleteAllVolumes(t assert.TestingT, c client.VolumeAPIClient, protectedVolu if isErrNotFoundSwarmClassic(err) { continue } - assert.NoError(t, err, "failed to remove volume %s", v.Name) + assert.Check(t, err, "failed to remove volume %s", v.Name) } } func deleteAllNetworks(t assert.TestingT, c client.NetworkAPIClient, daemonPlatform string, protectedNetworks map[string]struct{}) { networks, err := c.NetworkList(context.Background(), types.NetworkListOptions{}) - assert.NoError(t, err, "failed to list networks") + assert.Check(t, err, "failed to list networks") for _, n := range networks { if n.Name == "bridge" || n.Name == "none" || n.Name == "host" { @@ -162,7 +161,7 @@ func deleteAllNetworks(t assert.TestingT, c client.NetworkAPIClient, daemonPlatf continue } err := c.NetworkRemove(context.Background(), n.ID) - assert.NoError(t, err, "failed to remove network %s", n.ID) + assert.Check(t, err, "failed to remove network %s", n.ID) } } @@ -172,14 +171,14 @@ func deleteAllPlugins(t assert.TestingT, c client.PluginAPIClient, protectedPlug if client.IsErrNotImplemented(err) { return } - assert.NoError(t, err, "failed to list plugins") + assert.Check(t, err, "failed to list plugins") for _, p := range plugins { if _, ok := protectedPlugins[p.Name]; ok { continue } err := c.PluginRemove(context.Background(), p.Name, types.PluginRemoveOptions{Force: true}) - assert.NoError(t, err, "failed to remove plugin %s", p.ID) + assert.Check(t, err, "failed to remove plugin %s", p.ID) } } diff --git a/components/engine/internal/test/environment/protect.go b/components/engine/internal/test/environment/protect.go index ffbf985b73..3dfe606cea 100644 --- a/components/engine/internal/test/environment/protect.go +++ b/components/engine/internal/test/environment/protect.go @@ -6,7 +6,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" dclient "github.com/docker/docker/client" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) var frozenImages = []string{"busybox:latest", "busybox:glibc", "hello-world:frozen", "debian:jessie"} @@ -57,12 +57,12 @@ func ProtectContainers(t testingT, testEnv *Execution) { testEnv.ProtectContainer(t, containers...) } -func getExistingContainers(t require.TestingT, testEnv *Execution) []string { +func getExistingContainers(t assert.TestingT, testEnv *Execution) []string { client := testEnv.APIClient() containerList, err := client.ContainerList(context.Background(), types.ContainerListOptions{ All: true, }) - require.NoError(t, err, "failed to list containers") + assert.NilError(t, err, "failed to list containers") containers := []string{} for _, container := range containerList { @@ -89,7 +89,7 @@ func ProtectImages(t testingT, testEnv *Execution) { testEnv.ProtectImage(t, images...) } -func getExistingImages(t require.TestingT, testEnv *Execution) []string { +func getExistingImages(t assert.TestingT, testEnv *Execution) []string { client := testEnv.APIClient() filter := filters.NewArgs() filter.Add("dangling", "false") @@ -97,7 +97,7 @@ func getExistingImages(t require.TestingT, testEnv *Execution) []string { All: true, Filters: filter, }) - require.NoError(t, err, "failed to list images") + assert.NilError(t, err, "failed to list images") images := []string{} for _, image := range imageList { @@ -136,10 +136,10 @@ func ProtectNetworks(t testingT, testEnv *Execution) { testEnv.ProtectNetwork(t, networks...) } -func getExistingNetworks(t require.TestingT, testEnv *Execution) []string { +func getExistingNetworks(t assert.TestingT, testEnv *Execution) []string { client := testEnv.APIClient() networkList, err := client.NetworkList(context.Background(), types.NetworkListOptions{}) - require.NoError(t, err, "failed to list networks") + assert.NilError(t, err, "failed to list networks") networks := []string{} for _, network := range networkList { @@ -162,14 +162,14 @@ func ProtectPlugins(t testingT, testEnv *Execution) { testEnv.ProtectPlugin(t, plugins...) } -func getExistingPlugins(t require.TestingT, testEnv *Execution) []string { +func getExistingPlugins(t assert.TestingT, testEnv *Execution) []string { client := testEnv.APIClient() pluginList, err := client.PluginList(context.Background(), filters.Args{}) // Docker EE does not allow cluster-wide plugin management. if dclient.IsErrNotImplemented(err) { return []string{} } - require.NoError(t, err, "failed to list plugins") + assert.NilError(t, err, "failed to list plugins") plugins := []string{} for _, plugin := range pluginList { @@ -192,10 +192,10 @@ func ProtectVolumes(t testingT, testEnv *Execution) { testEnv.ProtectVolume(t, volumes...) } -func getExistingVolumes(t require.TestingT, testEnv *Execution) []string { +func getExistingVolumes(t assert.TestingT, testEnv *Execution) []string { client := testEnv.APIClient() volumeList, err := client.VolumeList(context.Background(), filters.Args{}) - require.NoError(t, err, "failed to list volumes") + assert.NilError(t, err, "failed to list volumes") volumes := []string{} for _, volume := range volumeList.Volumes { diff --git a/components/engine/internal/testutil/helpers.go b/components/engine/internal/testutil/helpers.go index 77224a0071..89cb552fea 100644 --- a/components/engine/internal/testutil/helpers.go +++ b/components/engine/internal/testutil/helpers.go @@ -3,15 +3,21 @@ package testutil // import "github.com/docker/docker/internal/testutil" import ( "io" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) +type helperT interface { + Helper() +} + // ErrorContains checks that the error is not nil, and contains the expected // substring. -func ErrorContains(t require.TestingT, err error, expectedError string, msgAndArgs ...interface{}) { - require.Error(t, err, msgAndArgs...) - assert.Contains(t, err.Error(), expectedError, msgAndArgs...) +// Deprecated: use assert.Assert(t, cmp.ErrorContains(err, expected)) +func ErrorContains(t assert.TestingT, err error, expectedError string, msgAndArgs ...interface{}) { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + assert.ErrorContains(t, err, expectedError, msgAndArgs...) } // DevZero acts like /dev/zero but in an OS-independent fashion. diff --git a/components/engine/internal/testutil/stringutils_test.go b/components/engine/internal/testutil/stringutils_test.go index a0f95755c7..1dd09af95f 100644 --- a/components/engine/internal/testutil/stringutils_test.go +++ b/components/engine/internal/testutil/stringutils_test.go @@ -3,13 +3,14 @@ package testutil // import "github.com/docker/docker/internal/testutil" import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func testLengthHelper(generator func(int) string, t *testing.T) { expectedLength := 20 s := generator(expectedLength) - assert.Equal(t, expectedLength, len(s)) + assert.Check(t, is.Equal(expectedLength, len(s))) } func testUniquenessHelper(generator func(int) string, t *testing.T) { @@ -17,9 +18,9 @@ func testUniquenessHelper(generator func(int) string, t *testing.T) { set := make(map[string]struct{}, repeats) for i := 0; i < repeats; i = i + 1 { str := generator(64) - assert.Equal(t, 64, len(str)) + assert.Check(t, is.Equal(64, len(str))) _, ok := set[str] - assert.False(t, ok, "Random number is repeated") + assert.Check(t, !ok, "Random number is repeated") set[str] = struct{}{} } } diff --git a/components/engine/libcontainerd/queue_test.go b/components/engine/libcontainerd/queue_test.go index 92ee22a9f3..df5332c128 100644 --- a/components/engine/libcontainerd/queue_test.go +++ b/components/engine/libcontainerd/queue_test.go @@ -4,7 +4,7 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestSerialization(t *testing.T) { @@ -16,15 +16,15 @@ func TestSerialization(t *testing.T) { q.append("aaa", func() { //simulate a long time task time.Sleep(10 * time.Millisecond) - require.EqualValues(t, serialization, 1) + assert.Equal(t, serialization, 1) serialization = 2 }) q.append("aaa", func() { - require.EqualValues(t, serialization, 2) + assert.Equal(t, serialization, 2) serialization = 3 }) q.append("aaa", func() { - require.EqualValues(t, serialization, 3) + assert.Equal(t, serialization, 3) serialization = 4 }) time.Sleep(20 * time.Millisecond) diff --git a/components/engine/opts/quotedstring_test.go b/components/engine/opts/quotedstring_test.go index e24257a5d4..21e6e4c85a 100644 --- a/components/engine/opts/quotedstring_test.go +++ b/components/engine/opts/quotedstring_test.go @@ -3,27 +3,28 @@ package opts // import "github.com/docker/docker/opts" import ( "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestQuotedStringSetWithQuotes(t *testing.T) { value := "" qs := NewQuotedString(&value) - assert.NoError(t, qs.Set(`"something"`)) - assert.Equal(t, "something", qs.String()) - assert.Equal(t, "something", value) + assert.Check(t, qs.Set(`"something"`)) + assert.Check(t, is.Equal("something", qs.String())) + assert.Check(t, is.Equal("something", value)) } func TestQuotedStringSetWithMismatchedQuotes(t *testing.T) { value := "" qs := NewQuotedString(&value) - assert.NoError(t, qs.Set(`"something'`)) - assert.Equal(t, `"something'`, qs.String()) + assert.Check(t, qs.Set(`"something'`)) + assert.Check(t, is.Equal(`"something'`, qs.String())) } func TestQuotedStringSetWithNoQuotes(t *testing.T) { value := "" qs := NewQuotedString(&value) - assert.NoError(t, qs.Set("something")) - assert.Equal(t, "something", qs.String()) + assert.Check(t, qs.Set("something")) + assert.Check(t, is.Equal("something", qs.String())) } diff --git a/components/engine/pkg/archive/archive_linux_test.go b/components/engine/pkg/archive/archive_linux_test.go index e48ef1aa11..b397c8abfa 100644 --- a/components/engine/pkg/archive/archive_linux_test.go +++ b/components/engine/pkg/archive/archive_linux_test.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/docker/docker/pkg/system" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" "golang.org/x/sys/unix" ) @@ -24,35 +24,35 @@ import ( func setupOverlayTestDir(t *testing.T, src string) { // Create opaque directory containing single file and permission 0700 err := os.Mkdir(filepath.Join(src, "d1"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = system.Lsetxattr(filepath.Join(src, "d1"), "trusted.overlay.opaque", []byte("y"), 0) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(src, "d1", "f1"), []byte{}, 0600) - require.NoError(t, err) + assert.NilError(t, err) // Create another opaque directory containing single file but with permission 0750 err = os.Mkdir(filepath.Join(src, "d2"), 0750) - require.NoError(t, err) + assert.NilError(t, err) err = system.Lsetxattr(filepath.Join(src, "d2"), "trusted.overlay.opaque", []byte("y"), 0) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(src, "d2", "f1"), []byte{}, 0660) - require.NoError(t, err) + assert.NilError(t, err) // Create regular directory with deleted file err = os.Mkdir(filepath.Join(src, "d3"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = system.Mknod(filepath.Join(src, "d3", "f1"), unix.S_IFCHR, 0) - require.NoError(t, err) + assert.NilError(t, err) } func checkOpaqueness(t *testing.T, path string, opaque string) { xattrOpaque, err := system.Lgetxattr(path, "trusted.overlay.opaque") - require.NoError(t, err) + assert.NilError(t, err) if string(xattrOpaque) != opaque { t.Fatalf("Unexpected opaque value: %q, expected %q", string(xattrOpaque), opaque) @@ -62,7 +62,7 @@ func checkOpaqueness(t *testing.T, path string, opaque string) { func checkOverlayWhiteout(t *testing.T, path string) { stat, err := os.Stat(path) - require.NoError(t, err) + assert.NilError(t, err) statT, ok := stat.Sys().(*syscall.Stat_t) if !ok { @@ -75,7 +75,7 @@ func checkOverlayWhiteout(t *testing.T, path string) { func checkFileMode(t *testing.T, path string, perm os.FileMode) { stat, err := os.Stat(path) - require.NoError(t, err) + assert.NilError(t, err) if stat.Mode() != perm { t.Fatalf("Unexpected file mode for %s: %o, expected %o", path, stat.Mode(), perm) @@ -84,17 +84,17 @@ func checkFileMode(t *testing.T, path string, perm os.FileMode) { func TestOverlayTarUntar(t *testing.T) { oldmask, err := system.Umask(0) - require.NoError(t, err) + assert.NilError(t, err) defer system.Umask(oldmask) src, err := ioutil.TempDir("", "docker-test-overlay-tar-src") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(src) setupOverlayTestDir(t, src) dst, err := ioutil.TempDir("", "docker-test-overlay-tar-dst") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dst) options := &TarOptions{ @@ -102,11 +102,11 @@ func TestOverlayTarUntar(t *testing.T) { WhiteoutFormat: OverlayWhiteoutFormat, } archive, err := TarWithOptions(src, options) - require.NoError(t, err) + assert.NilError(t, err) defer archive.Close() err = Untar(archive, dst, options) - require.NoError(t, err) + assert.NilError(t, err) checkFileMode(t, filepath.Join(dst, "d1"), 0700|os.ModeDir) checkFileMode(t, filepath.Join(dst, "d2"), 0750|os.ModeDir) @@ -123,31 +123,31 @@ func TestOverlayTarUntar(t *testing.T) { func TestOverlayTarAUFSUntar(t *testing.T) { oldmask, err := system.Umask(0) - require.NoError(t, err) + assert.NilError(t, err) defer system.Umask(oldmask) src, err := ioutil.TempDir("", "docker-test-overlay-tar-src") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(src) setupOverlayTestDir(t, src) dst, err := ioutil.TempDir("", "docker-test-overlay-tar-dst") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dst) archive, err := TarWithOptions(src, &TarOptions{ Compression: Uncompressed, WhiteoutFormat: OverlayWhiteoutFormat, }) - require.NoError(t, err) + assert.NilError(t, err) defer archive.Close() err = Untar(archive, dst, &TarOptions{ Compression: Uncompressed, WhiteoutFormat: AUFSWhiteoutFormat, }) - require.NoError(t, err) + assert.NilError(t, err) checkFileMode(t, filepath.Join(dst, "d1"), 0700|os.ModeDir) checkFileMode(t, filepath.Join(dst, "d1", WhiteoutOpaqueDir), 0700) diff --git a/components/engine/pkg/archive/archive_test.go b/components/engine/pkg/archive/archive_test.go index 70db8d4a1b..e8d12dd72f 100644 --- a/components/engine/pkg/archive/archive_test.go +++ b/components/engine/pkg/archive/archive_test.go @@ -10,6 +10,7 @@ import ( "os" "os/exec" "path/filepath" + "reflect" "runtime" "strings" "testing" @@ -17,8 +18,8 @@ import ( "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/ioutils" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) var tmp string @@ -263,7 +264,7 @@ func TestCmdStreamGood(t *testing.T) { func TestUntarPathWithInvalidDest(t *testing.T) { tempFolder, err := ioutil.TempDir("", "docker-archive-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tempFolder) invalidDestFolder := filepath.Join(tempFolder, "invalidDest") // Create a src file @@ -282,7 +283,7 @@ func TestUntarPathWithInvalidDest(t *testing.T) { cmd := exec.Command("sh", "-c", "tar cf "+tarFileU+" "+srcFileU) _, err = cmd.CombinedOutput() - require.NoError(t, err) + assert.NilError(t, err) err = defaultUntarPath(tarFile, invalidDestFolder) if err == nil { @@ -304,7 +305,7 @@ func TestUntarPathWithInvalidSrc(t *testing.T) { func TestUntarPath(t *testing.T) { tmpFolder, err := ioutil.TempDir("", "docker-archive-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpFolder) srcFile := filepath.Join(tmpFolder, "src") tarFile := filepath.Join(tmpFolder, "src.tar") @@ -325,7 +326,7 @@ func TestUntarPath(t *testing.T) { } cmd := exec.Command("sh", "-c", "tar cf "+tarFileU+" "+srcFileU) _, err = cmd.CombinedOutput() - require.NoError(t, err) + assert.NilError(t, err) err = defaultUntarPath(tarFile, destFolder) if err != nil { @@ -726,12 +727,12 @@ func TestTarUntar(t *testing.T) { func TestTarWithOptionsChownOptsAlwaysOverridesIdPair(t *testing.T) { origin, err := ioutil.TempDir("", "docker-test-tar-chown-opt") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(origin) filePath := filepath.Join(origin, "1") err = ioutil.WriteFile(filePath, []byte("hello world"), 0700) - require.NoError(t, err) + assert.NilError(t, err) idMaps := []idtools.IDMap{ 0: { @@ -759,7 +760,7 @@ func TestTarWithOptionsChownOptsAlwaysOverridesIdPair(t *testing.T) { } for _, testCase := range cases { reader, err := TarWithOptions(filePath, testCase.opts) - require.NoError(t, err) + assert.NilError(t, err) tr := tar.NewReader(reader) defer reader.Close() for { @@ -768,9 +769,9 @@ func TestTarWithOptionsChownOptsAlwaysOverridesIdPair(t *testing.T) { // end of tar archive break } - require.NoError(t, err) - assert.Equal(t, hdr.Uid, testCase.expectedUID, "Uid equals expected value") - assert.Equal(t, hdr.Gid, testCase.expectedGID, "Gid equals expected value") + assert.NilError(t, err) + assert.Check(t, is.Equal(hdr.Uid, testCase.expectedUID), "Uid equals expected value") + assert.Check(t, is.Equal(hdr.Gid, testCase.expectedGID), "Gid equals expected value") } } } @@ -1182,10 +1183,10 @@ func TestUntarInvalidSymlink(t *testing.T) { func TestTempArchiveCloseMultipleTimes(t *testing.T) { reader := ioutil.NopCloser(strings.NewReader("hello")) tempArchive, err := NewTempArchive(reader, "") - require.NoError(t, err) + assert.NilError(t, err) buf := make([]byte, 10) n, err := tempArchive.Read(buf) - require.NoError(t, err) + assert.NilError(t, err) if n != 5 { t.Fatalf("Expected to read 5 bytes. Read %d instead", n) } @@ -1244,7 +1245,7 @@ func TestReplaceFileTarWrapper(t *testing.T) { map[string]TarModifierFunc{testcase.filename: testcase.modifier}) actual := readFileFromArchive(t, resultArchive, testcase.filename, testcase.fileCount, testcase.doc) - assert.Equal(t, testcase.expected, actual, testcase.doc) + assert.Check(t, is.Equal(testcase.expected, actual), testcase.doc) } } @@ -1255,27 +1256,27 @@ func TestPrefixHeaderReadable(t *testing.T) { 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") tmpDir, err := ioutil.TempDir("", "prefix-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) err = Untar(bytes.NewReader(testFile), tmpDir, nil) - require.NoError(t, err) + assert.NilError(t, err) baseName := "foo" pth := strings.Repeat("a", 100-len(baseName)) + "/" + baseName _, err = os.Lstat(filepath.Join(tmpDir, pth)) - require.NoError(t, err) + assert.NilError(t, err) } func buildSourceArchive(t *testing.T, numberOfFiles int) (io.ReadCloser, func()) { srcDir, err := ioutil.TempDir("", "docker-test-srcDir") - require.NoError(t, err) + assert.NilError(t, err) _, err = prepareUntarSourceDirectory(numberOfFiles, srcDir, false) - require.NoError(t, err) + assert.NilError(t, err) sourceArchive, err := TarWithOptions(srcDir, &TarOptions{}) - require.NoError(t, err) + assert.NilError(t, err) return sourceArchive, func() { os.RemoveAll(srcDir) sourceArchive.Close() @@ -1291,7 +1292,7 @@ func createOrReplaceModifier(path string, header *tar.Header, content io.Reader) func createModifier(t *testing.T) TarModifierFunc { return func(path string, header *tar.Header, content io.Reader) (*tar.Header, []byte, error) { - assert.Nil(t, content) + assert.Check(t, is.Nil(content)) return createOrReplaceModifier(path, header, content) } } @@ -1309,17 +1310,17 @@ 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 { destDir, err := ioutil.TempDir("", "docker-test-destDir") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(destDir) err = Untar(archive, destDir, nil) - require.NoError(t, err) + assert.NilError(t, err) files, _ := ioutil.ReadDir(destDir) - assert.Len(t, files, expectedCount, doc) + assert.Check(t, is.Len(files, expectedCount), doc) content, err := ioutil.ReadFile(filepath.Join(destDir, name)) - assert.NoError(t, err) + assert.Check(t, err) return string(content) } @@ -1338,7 +1339,7 @@ func TestDisablePigz(t *testing.T) { // For the context canceller contextReaderCloserWrapper := outsideReaderCloserWrapper.Reader.(*ioutils.ReadCloserWrapper) - assert.IsType(t, &gzip.Reader{}, contextReaderCloserWrapper.Reader) + assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&gzip.Reader{})) } func TestPigz(t *testing.T) { @@ -1351,9 +1352,9 @@ func TestPigz(t *testing.T) { _, err := exec.LookPath("unpigz") if err == nil { t.Log("Tested whether Pigz is used, as it installed") - assert.IsType(t, &io.PipeReader{}, contextReaderCloserWrapper.Reader) + assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&io.PipeReader{})) } else { t.Log("Tested whether Pigz is not used, as it not installed") - assert.IsType(t, &gzip.Reader{}, contextReaderCloserWrapper.Reader) + assert.Equal(t, reflect.TypeOf(contextReaderCloserWrapper.Reader), reflect.TypeOf(&gzip.Reader{})) } } diff --git a/components/engine/pkg/archive/archive_unix_test.go b/components/engine/pkg/archive/archive_unix_test.go index 17de96e94d..5d13c3542b 100644 --- a/components/engine/pkg/archive/archive_unix_test.go +++ b/components/engine/pkg/archive/archive_unix_test.go @@ -13,8 +13,8 @@ import ( "testing" "github.com/docker/docker/pkg/system" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/sys/unix" ) @@ -72,18 +72,18 @@ func TestChmodTarEntry(t *testing.T) { func TestTarWithHardLink(t *testing.T) { origin, err := ioutil.TempDir("", "docker-test-tar-hardlink") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(origin) err = ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = os.Link(filepath.Join(origin, "1"), filepath.Join(origin, "2")) - require.NoError(t, err) + assert.NilError(t, err) var i1, i2 uint64 i1, err = getNlink(filepath.Join(origin, "1")) - require.NoError(t, err) + assert.NilError(t, err) // sanity check that we can hardlink if i1 != 2 { @@ -91,48 +91,48 @@ func TestTarWithHardLink(t *testing.T) { } dest, err := ioutil.TempDir("", "docker-test-tar-hardlink-dest") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dest) // we'll do this in two steps to separate failure fh, err := Tar(origin, Uncompressed) - require.NoError(t, err) + assert.NilError(t, err) // ensure we can read the whole thing with no error, before writing back out buf, err := ioutil.ReadAll(fh) - require.NoError(t, err) + assert.NilError(t, err) bRdr := bytes.NewReader(buf) err = Untar(bRdr, dest, &TarOptions{Compression: Uncompressed}) - require.NoError(t, err) + assert.NilError(t, err) i1, err = getInode(filepath.Join(dest, "1")) - require.NoError(t, err) + assert.NilError(t, err) i2, err = getInode(filepath.Join(dest, "2")) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, i1, i2) + assert.Check(t, is.Equal(i1, i2)) } func TestTarWithHardLinkAndRebase(t *testing.T) { tmpDir, err := ioutil.TempDir("", "docker-test-tar-hardlink-rebase") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) origin := filepath.Join(tmpDir, "origin") err = os.Mkdir(origin, 0700) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = os.Link(filepath.Join(origin, "1"), filepath.Join(origin, "2")) - require.NoError(t, err) + assert.NilError(t, err) var i1, i2 uint64 i1, err = getNlink(filepath.Join(origin, "1")) - require.NoError(t, err) + assert.NilError(t, err) // sanity check that we can hardlink if i1 != 2 { @@ -141,20 +141,20 @@ func TestTarWithHardLinkAndRebase(t *testing.T) { dest := filepath.Join(tmpDir, "dest") bRdr, err := TarResourceRebase(origin, "origin") - require.NoError(t, err) + assert.NilError(t, err) dstDir, srcBase := SplitPathDirEntry(origin) _, dstBase := SplitPathDirEntry(dest) content := RebaseArchiveEntries(bRdr, srcBase, dstBase) err = Untar(content, dstDir, &TarOptions{Compression: Uncompressed, NoLchown: true, NoOverwriteDirNonDir: true}) - require.NoError(t, err) + assert.NilError(t, err) i1, err = getInode(filepath.Join(dest, "1")) - require.NoError(t, err) + assert.NilError(t, err) i2, err = getInode(filepath.Join(dest, "2")) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, i1, i2) + assert.Check(t, is.Equal(i1, i2)) } func getNlink(path string) (uint64, error) { @@ -184,37 +184,37 @@ func getInode(path string) (uint64, error) { func TestTarWithBlockCharFifo(t *testing.T) { origin, err := ioutil.TempDir("", "docker-test-tar-hardlink") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(origin) err = ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = system.Mknod(filepath.Join(origin, "2"), unix.S_IFBLK, int(system.Mkdev(int64(12), int64(5)))) - require.NoError(t, err) + assert.NilError(t, err) err = system.Mknod(filepath.Join(origin, "3"), unix.S_IFCHR, int(system.Mkdev(int64(12), int64(5)))) - require.NoError(t, err) + assert.NilError(t, err) err = system.Mknod(filepath.Join(origin, "4"), unix.S_IFIFO, int(system.Mkdev(int64(12), int64(5)))) - require.NoError(t, err) + assert.NilError(t, err) dest, err := ioutil.TempDir("", "docker-test-tar-hardlink-dest") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dest) // we'll do this in two steps to separate failure fh, err := Tar(origin, Uncompressed) - require.NoError(t, err) + assert.NilError(t, err) // ensure we can read the whole thing with no error, before writing back out buf, err := ioutil.ReadAll(fh) - require.NoError(t, err) + assert.NilError(t, err) bRdr := bytes.NewReader(buf) err = Untar(bRdr, dest, &TarOptions{Compression: Uncompressed}) - require.NoError(t, err) + assert.NilError(t, err) changes, err := ChangesDirs(origin, dest) - require.NoError(t, err) + assert.NilError(t, err) if len(changes) > 0 { t.Fatalf("Tar with special device (block, char, fifo) should keep them (recreate them when untar) : %v", changes) @@ -224,17 +224,17 @@ func TestTarWithBlockCharFifo(t *testing.T) { // TestTarUntarWithXattr is Unix as Lsetxattr is not supported on Windows func TestTarUntarWithXattr(t *testing.T) { origin, err := ioutil.TempDir("", "docker-test-untar-origin") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(origin) err = ioutil.WriteFile(filepath.Join(origin, "1"), []byte("hello world"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(origin, "2"), []byte("welcome!"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(filepath.Join(origin, "3"), []byte("will be ignored"), 0700) - require.NoError(t, err) + assert.NilError(t, err) err = system.Lsetxattr(filepath.Join(origin, "2"), "security.capability", []byte{0x00}, 0) - require.NoError(t, err) + assert.NilError(t, err) for _, c := range []Compression{ Uncompressed, @@ -309,7 +309,7 @@ func TestCopyInfoDestinationPathSymlink(t *testing.T) { for _, info := range testData { p := filepath.Join(tmpDir, info.resource.path, info.file) ci, err := CopyInfoDestinationPath(p) - assert.NoError(t, err) - assert.Equal(t, info.expected, ci) + assert.Check(t, err) + assert.Check(t, is.DeepEqual(info.expected, ci)) } } diff --git a/components/engine/pkg/archive/changes_test.go b/components/engine/pkg/archive/changes_test.go index f316cd3203..2d316e77be 100644 --- a/components/engine/pkg/archive/changes_test.go +++ b/components/engine/pkg/archive/changes_test.go @@ -11,7 +11,7 @@ import ( "time" "github.com/docker/docker/pkg/system" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func max(x, y int) int { @@ -76,19 +76,19 @@ func provisionSampleDir(t *testing.T, root string, files []FileData) { p := path.Join(root, info.path) if info.filetype == Dir { err := os.MkdirAll(p, info.permissions) - require.NoError(t, err) + assert.NilError(t, err) } else if info.filetype == Regular { err := ioutil.WriteFile(p, []byte(info.contents), info.permissions) - require.NoError(t, err) + assert.NilError(t, err) } else if info.filetype == Symlink { err := os.Symlink(info.contents, p) - require.NoError(t, err) + assert.NilError(t, err) } if info.filetype != Symlink { // Set a consistent ctime, atime for all files and dirs err := system.Chtimes(p, now, now) - require.NoError(t, err) + assert.NilError(t, err) } } } @@ -118,14 +118,14 @@ func TestChangesWithNoChanges(t *testing.T) { t.Skip("symlinks on Windows") } rwLayer, err := ioutil.TempDir("", "docker-changes-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(rwLayer) layer, err := ioutil.TempDir("", "docker-changes-test-layer") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(layer) createSampleDir(t, layer) changes, err := Changes([]string{layer}, rwLayer) - require.NoError(t, err) + assert.NilError(t, err) if len(changes) != 0 { t.Fatalf("Changes with no difference should have detect no changes, but detected %d", len(changes)) } @@ -139,14 +139,14 @@ func TestChangesWithChanges(t *testing.T) { } // Mock the readonly layer layer, err := ioutil.TempDir("", "docker-changes-test-layer") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(layer) createSampleDir(t, layer) os.MkdirAll(path.Join(layer, "dir1/subfolder"), 0740) // Mock the RW layer rwLayer, err := ioutil.TempDir("", "docker-changes-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(rwLayer) // Create a folder in RW layer @@ -163,7 +163,7 @@ func TestChangesWithChanges(t *testing.T) { ioutil.WriteFile(newFile, []byte{}, 0740) changes, err := Changes([]string{layer}, rwLayer) - require.NoError(t, err) + assert.NilError(t, err) expectedChanges := []Change{ {"/dir1", ChangeModify}, @@ -183,7 +183,7 @@ func TestChangesWithChangesGH13590(t *testing.T) { t.Skip("symlinks on Windows") } baseLayer, err := ioutil.TempDir("", "docker-changes-test.") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(baseLayer) dir3 := path.Join(baseLayer, "dir1/dir2/dir3") @@ -193,7 +193,7 @@ func TestChangesWithChangesGH13590(t *testing.T) { ioutil.WriteFile(file, []byte("hello"), 0666) layer, err := ioutil.TempDir("", "docker-changes-test2.") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(layer) // Test creating a new file @@ -206,7 +206,7 @@ func TestChangesWithChangesGH13590(t *testing.T) { ioutil.WriteFile(file, []byte("bye"), 0666) changes, err := Changes([]string{baseLayer}, layer) - require.NoError(t, err) + assert.NilError(t, err) expectedChanges := []Change{ {"/dir1/dir2/dir3", ChangeModify}, @@ -216,7 +216,7 @@ func TestChangesWithChangesGH13590(t *testing.T) { // Now test changing a file layer, err = ioutil.TempDir("", "docker-changes-test3.") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(layer) if err := copyDir(baseLayer+"/dir1", layer+"/"); err != nil { @@ -227,7 +227,7 @@ func TestChangesWithChangesGH13590(t *testing.T) { ioutil.WriteFile(file, []byte("bye"), 0666) changes, err = Changes([]string{baseLayer}, layer) - require.NoError(t, err) + assert.NilError(t, err) expectedChanges = []Change{ {"/dir1/dir2/dir3/file.txt", ChangeModify}, @@ -243,15 +243,15 @@ func TestChangesDirsEmpty(t *testing.T) { t.Skip("symlinks on Windows") } src, err := ioutil.TempDir("", "docker-changes-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(src) createSampleDir(t, src) dst := src + "-copy" err = copyDir(src, dst) - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dst) changes, err := ChangesDirs(dst, src) - require.NoError(t, err) + assert.NilError(t, err) if len(changes) != 0 { t.Fatalf("Reported changes for identical dirs: %v", changes) @@ -263,64 +263,64 @@ func TestChangesDirsEmpty(t *testing.T) { func mutateSampleDir(t *testing.T, root string) { // Remove a regular file err := os.RemoveAll(path.Join(root, "file1")) - require.NoError(t, err) + assert.NilError(t, err) // Remove a directory err = os.RemoveAll(path.Join(root, "dir1")) - require.NoError(t, err) + assert.NilError(t, err) // Remove a symlink err = os.RemoveAll(path.Join(root, "symlink1")) - require.NoError(t, err) + assert.NilError(t, err) // Rewrite a file err = ioutil.WriteFile(path.Join(root, "file2"), []byte("fileNN\n"), 0777) - require.NoError(t, err) + assert.NilError(t, err) // Replace a file err = os.RemoveAll(path.Join(root, "file3")) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(path.Join(root, "file3"), []byte("fileMM\n"), 0404) - require.NoError(t, err) + assert.NilError(t, err) // Touch file err = system.Chtimes(path.Join(root, "file4"), time.Now().Add(time.Second), time.Now().Add(time.Second)) - require.NoError(t, err) + assert.NilError(t, err) // Replace file with dir err = os.RemoveAll(path.Join(root, "file5")) - require.NoError(t, err) + assert.NilError(t, err) err = os.MkdirAll(path.Join(root, "file5"), 0666) - require.NoError(t, err) + assert.NilError(t, err) // Create new file err = ioutil.WriteFile(path.Join(root, "filenew"), []byte("filenew\n"), 0777) - require.NoError(t, err) + assert.NilError(t, err) // Create new dir err = os.MkdirAll(path.Join(root, "dirnew"), 0766) - require.NoError(t, err) + assert.NilError(t, err) // Create a new symlink err = os.Symlink("targetnew", path.Join(root, "symlinknew")) - require.NoError(t, err) + assert.NilError(t, err) // Change a symlink err = os.RemoveAll(path.Join(root, "symlink2")) - require.NoError(t, err) + assert.NilError(t, err) err = os.Symlink("target2change", path.Join(root, "symlink2")) - require.NoError(t, err) + assert.NilError(t, err) // Replace dir with file err = os.RemoveAll(path.Join(root, "dir2")) - require.NoError(t, err) + assert.NilError(t, err) err = ioutil.WriteFile(path.Join(root, "dir2"), []byte("dir2\n"), 0777) - require.NoError(t, err) + assert.NilError(t, err) // Touch dir err = system.Chtimes(path.Join(root, "dir3"), time.Now().Add(time.Second), time.Now().Add(time.Second)) - require.NoError(t, err) + assert.NilError(t, err) } func TestChangesDirsMutated(t *testing.T) { @@ -330,18 +330,18 @@ func TestChangesDirsMutated(t *testing.T) { t.Skip("symlinks on Windows") } src, err := ioutil.TempDir("", "docker-changes-test") - require.NoError(t, err) + assert.NilError(t, err) createSampleDir(t, src) dst := src + "-copy" err = copyDir(src, dst) - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(src) defer os.RemoveAll(dst) mutateSampleDir(t, dst) changes, err := ChangesDirs(dst, src) - require.NoError(t, err) + assert.NilError(t, err) sort.Sort(changesByPath(changes)) @@ -386,29 +386,29 @@ func TestApplyLayer(t *testing.T) { t.Skip("symlinks on Windows") } src, err := ioutil.TempDir("", "docker-changes-test") - require.NoError(t, err) + assert.NilError(t, err) createSampleDir(t, src) defer os.RemoveAll(src) dst := src + "-copy" err = copyDir(src, dst) - require.NoError(t, err) + assert.NilError(t, err) mutateSampleDir(t, dst) defer os.RemoveAll(dst) changes, err := ChangesDirs(dst, src) - require.NoError(t, err) + assert.NilError(t, err) layer, err := ExportChanges(dst, changes, nil, nil) - require.NoError(t, err) + assert.NilError(t, err) layerCopy, err := NewTempArchive(layer, "") - require.NoError(t, err) + assert.NilError(t, err) _, err = ApplyLayer(src, layerCopy) - require.NoError(t, err) + assert.NilError(t, err) changes2, err := ChangesDirs(src, dst) - require.NoError(t, err) + assert.NilError(t, err) if len(changes2) != 0 { t.Fatalf("Unexpected differences after reapplying mutation: %v", changes2) @@ -422,18 +422,18 @@ func TestChangesSizeWithHardlinks(t *testing.T) { t.Skip("hardlinks on Windows") } srcDir, err := ioutil.TempDir("", "docker-test-srcDir") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(srcDir) destDir, err := ioutil.TempDir("", "docker-test-destDir") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(destDir) creationSize, err := prepareUntarSourceDirectory(100, destDir, true) - require.NoError(t, err) + assert.NilError(t, err) changes, err := ChangesDirs(destDir, srcDir) - require.NoError(t, err) + assert.NilError(t, err) got := ChangesSize(destDir, changes) if got != int64(creationSize) { @@ -460,14 +460,14 @@ func TestChangesSizeWithOnlyDeleteChanges(t *testing.T) { func TestChangesSize(t *testing.T) { parentPath, err := ioutil.TempDir("", "docker-changes-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(parentPath) addition := path.Join(parentPath, "addition") err = ioutil.WriteFile(addition, []byte{0x01, 0x01, 0x01}, 0744) - require.NoError(t, err) + assert.NilError(t, err) modification := path.Join(parentPath, "modification") err = ioutil.WriteFile(modification, []byte{0x01, 0x01, 0x01}, 0744) - require.NoError(t, err) + assert.NilError(t, err) changes := []Change{ {Path: "addition", Kind: ChangeAdd}, diff --git a/components/engine/pkg/archive/copy_unix_test.go b/components/engine/pkg/archive/copy_unix_test.go index 3126d8b51e..08b1702cf1 100644 --- a/components/engine/pkg/archive/copy_unix_test.go +++ b/components/engine/pkg/archive/copy_unix_test.go @@ -16,7 +16,7 @@ import ( "strings" "testing" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func removeAllPaths(paths ...string) { @@ -29,10 +29,10 @@ func getTestTempDirs(t *testing.T) (tmpDirA, tmpDirB string) { var err error tmpDirA, err = ioutil.TempDir("", "archive-copy-test") - require.NoError(t, err) + assert.NilError(t, err) tmpDirB, err = ioutil.TempDir("", "archive-copy-test") - require.NoError(t, err) + assert.NilError(t, err) return } @@ -119,7 +119,7 @@ func logDirContents(t *testing.T, dirPath string) { t.Logf("logging directory contents: %q", dirPath) err := filepath.Walk(dirPath, logWalkedPaths) - require.NoError(t, err) + assert.NilError(t, err) } func testCopyHelper(t *testing.T, srcPath, dstPath string) (err error) { @@ -293,7 +293,7 @@ func TestCopyCaseA(t *testing.T) { } err = fileContentsEqual(t, srcPath, dstPath) - require.NoError(t, err) + assert.NilError(t, err) os.Remove(dstPath) symlinkPath := filepath.Join(tmpDirA, "symlink3") @@ -305,14 +305,14 @@ func TestCopyCaseA(t *testing.T) { } err = fileContentsEqual(t, linkTarget, dstPath) - require.NoError(t, err) + assert.NilError(t, err) os.Remove(dstPath) if err = testCopyHelperFSym(t, symlinkPath1, dstPath); err != nil { t.Fatalf("unexpected error %T: %s", err, err) } err = fileContentsEqual(t, linkTarget, dstPath) - require.NoError(t, err) + assert.NilError(t, err) } // B. SRC specifies a file and DST (with trailing path separator) doesn't @@ -374,7 +374,7 @@ func TestCopyCaseC(t *testing.T) { } err = fileContentsEqual(t, srcPath, dstPath) - require.NoError(t, err) + assert.NilError(t, err) } // C. Symbol link following version: @@ -411,7 +411,7 @@ func TestCopyCaseCFSym(t *testing.T) { } err = fileContentsEqual(t, linkTarget, dstPath) - require.NoError(t, err) + assert.NilError(t, err) } // D. SRC specifies a file and DST exists as a directory. This should place @@ -441,7 +441,7 @@ func TestCopyCaseD(t *testing.T) { } err = fileContentsEqual(t, srcPath, dstPath) - require.NoError(t, err) + assert.NilError(t, err) // Now try again but using a trailing path separator for dstDir. @@ -460,7 +460,7 @@ func TestCopyCaseD(t *testing.T) { } err = fileContentsEqual(t, srcPath, dstPath) - require.NoError(t, err) + assert.NilError(t, err) } // D. Symbol link following version: @@ -492,7 +492,7 @@ func TestCopyCaseDFSym(t *testing.T) { } err = fileContentsEqual(t, linkTarget, dstPath) - require.NoError(t, err) + assert.NilError(t, err) // Now try again but using a trailing path separator for dstDir. @@ -511,7 +511,7 @@ func TestCopyCaseDFSym(t *testing.T) { } err = fileContentsEqual(t, linkTarget, dstPath) - require.NoError(t, err) + assert.NilError(t, err) } // E. SRC specifies a directory and DST does not exist. This should create a @@ -554,7 +554,7 @@ func TestCopyCaseE(t *testing.T) { } err = dirContentsEqual(t, dstDir, srcDir) - require.NoError(t, err) + assert.NilError(t, err) } // E. Symbol link following version: @@ -599,7 +599,7 @@ func TestCopyCaseEFSym(t *testing.T) { } err = dirContentsEqual(t, dstDir, linkTarget) - require.NoError(t, err) + assert.NilError(t, err) } // F. SRC specifies a directory and DST exists as a file. This should cause an @@ -658,7 +658,7 @@ func TestCopyCaseG(t *testing.T) { } err = dirContentsEqual(t, resultDir, srcDir) - require.NoError(t, err) + assert.NilError(t, err) // Now try again but using a trailing path separator for dstDir. @@ -677,7 +677,7 @@ func TestCopyCaseG(t *testing.T) { } err = dirContentsEqual(t, resultDir, srcDir) - require.NoError(t, err) + assert.NilError(t, err) } // G. Symbol link version: @@ -704,7 +704,7 @@ func TestCopyCaseGFSym(t *testing.T) { } err = dirContentsEqual(t, resultDir, linkTarget) - require.NoError(t, err) + assert.NilError(t, err) // Now try again but using a trailing path separator for dstDir. @@ -723,7 +723,7 @@ func TestCopyCaseGFSym(t *testing.T) { } err = dirContentsEqual(t, resultDir, linkTarget) - require.NoError(t, err) + assert.NilError(t, err) } // H. SRC specifies a directory's contents only and DST does not exist. This @@ -884,7 +884,7 @@ func TestCopyCaseJ(t *testing.T) { } err = dirContentsEqual(t, dstDir, srcDir) - require.NoError(t, err) + assert.NilError(t, err) // Now try again but using a trailing path separator for dstDir. @@ -903,7 +903,7 @@ func TestCopyCaseJ(t *testing.T) { } err = dirContentsEqual(t, dstDir, srcDir) - require.NoError(t, err) + assert.NilError(t, err) } // J. Symbol link following version: @@ -935,7 +935,7 @@ func TestCopyCaseJFSym(t *testing.T) { } err = dirContentsEqual(t, dstDir, linkTarget) - require.NoError(t, err) + assert.NilError(t, err) // Now try again but using a trailing path separator for dstDir. @@ -954,5 +954,5 @@ func TestCopyCaseJFSym(t *testing.T) { } err = dirContentsEqual(t, dstDir, linkTarget) - require.NoError(t, err) + assert.NilError(t, err) } diff --git a/components/engine/pkg/archive/wrap_test.go b/components/engine/pkg/archive/wrap_test.go index 6decf8fccb..979536777f 100644 --- a/components/engine/pkg/archive/wrap_test.go +++ b/components/engine/pkg/archive/wrap_test.go @@ -6,12 +6,12 @@ import ( "io" "testing" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestGenerateEmptyFile(t *testing.T) { archive, err := Generate("emptyFile") - require.NoError(t, err) + assert.NilError(t, err) if archive == nil { t.Fatal("The generated archive should not be nil.") } @@ -28,7 +28,7 @@ func TestGenerateEmptyFile(t *testing.T) { if err == io.EOF { break } - require.NoError(t, err) + assert.NilError(t, err) buf := new(bytes.Buffer) buf.ReadFrom(tr) content := buf.String() @@ -52,7 +52,7 @@ func TestGenerateEmptyFile(t *testing.T) { func TestGenerateWithContent(t *testing.T) { archive, err := Generate("file", "content") - require.NoError(t, err) + assert.NilError(t, err) if archive == nil { t.Fatal("The generated archive should not be nil.") } @@ -69,7 +69,7 @@ func TestGenerateWithContent(t *testing.T) { if err == io.EOF { break } - require.NoError(t, err) + assert.NilError(t, err) buf := new(bytes.Buffer) buf.ReadFrom(tr) content := buf.String() diff --git a/components/engine/pkg/authorization/api_test.go b/components/engine/pkg/authorization/api_test.go index 90a984276d..84964d2c5e 100644 --- a/components/engine/pkg/authorization/api_test.go +++ b/components/engine/pkg/authorization/api_test.go @@ -11,7 +11,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestPeerCertificateMarshalJSON(t *testing.T) { @@ -32,21 +33,21 @@ func TestPeerCertificateMarshalJSON(t *testing.T) { } // generate private key privatekey, err := rsa.GenerateKey(rand.Reader, 2048) - require.NoError(t, err) + assert.NilError(t, err) publickey := &privatekey.PublicKey // create a self-signed certificate. template = parent var parent = template raw, err := x509.CreateCertificate(rand.Reader, template, parent, publickey, privatekey) - require.NoError(t, err) + assert.NilError(t, err) cert, err := x509.ParseCertificate(raw) - require.NoError(t, err) + assert.NilError(t, err) var certs = []*x509.Certificate{cert} addr := "www.authz.com/auth" req, err := http.NewRequest("GET", addr, nil) - require.NoError(t, err) + assert.NilError(t, err) req.RequestURI = addr req.TLS = &tls.ConnectionState{} @@ -58,15 +59,15 @@ func TestPeerCertificateMarshalJSON(t *testing.T) { t.Run("Marshalling :", func(t *testing.T) { raw, err = pcObj.MarshalJSON() - require.NotNil(t, raw) - require.Nil(t, err) + assert.Assert(t, raw != nil) + assert.NilError(t, err) }) t.Run("UnMarshalling :", func(t *testing.T) { err := pcObj.UnmarshalJSON(raw) - require.Nil(t, err) - require.Equal(t, "Earth", pcObj.Subject.Country[0]) - require.Equal(t, true, pcObj.IsCA) + assert.Assert(t, is.Nil(err)) + assert.Equal(t, "Earth", pcObj.Subject.Country[0]) + assert.Equal(t, true, pcObj.IsCA) }) diff --git a/components/engine/pkg/authorization/middleware_test.go b/components/engine/pkg/authorization/middleware_test.go index 3812d804e3..e32e4bf427 100644 --- a/components/engine/pkg/authorization/middleware_test.go +++ b/components/engine/pkg/authorization/middleware_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/docker/docker/pkg/plugingetter" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestMiddleware(t *testing.T) { @@ -15,9 +15,9 @@ func TestMiddleware(t *testing.T) { var pluginGetter plugingetter.PluginGetter m := NewMiddleware(pluginNames, pluginGetter) authPlugins := m.getAuthzPlugins() - require.Equal(t, 2, len(authPlugins)) - require.EqualValues(t, pluginNames[0], authPlugins[0].Name()) - require.EqualValues(t, pluginNames[1], authPlugins[1].Name()) + assert.Equal(t, 2, len(authPlugins)) + assert.Equal(t, pluginNames[0], authPlugins[0].Name()) + assert.Equal(t, pluginNames[1], authPlugins[1].Name()) } func TestNewResponseModifier(t *testing.T) { @@ -25,17 +25,17 @@ func TestNewResponseModifier(t *testing.T) { modifier := NewResponseModifier(recorder) modifier.Header().Set("H1", "V1") modifier.Write([]byte("body")) - require.False(t, modifier.Hijacked()) + assert.Assert(t, !modifier.Hijacked()) modifier.WriteHeader(http.StatusInternalServerError) - require.NotNil(t, modifier.RawBody()) + assert.Assert(t, modifier.RawBody() != nil) raw, err := modifier.RawHeaders() - require.NotNil(t, raw) - require.Nil(t, err) + assert.Assert(t, raw != nil) + assert.NilError(t, err) headerData := strings.Split(strings.TrimSpace(string(raw)), ":") - require.EqualValues(t, "H1", strings.TrimSpace(headerData[0])) - require.EqualValues(t, "V1", strings.TrimSpace(headerData[1])) + assert.Equal(t, "H1", strings.TrimSpace(headerData[0])) + assert.Equal(t, "V1", strings.TrimSpace(headerData[1])) modifier.Flush() modifier.FlushAll() diff --git a/components/engine/pkg/authorization/middleware_unix_test.go b/components/engine/pkg/authorization/middleware_unix_test.go index 257832b338..ddfe9d958f 100644 --- a/components/engine/pkg/authorization/middleware_unix_test.go +++ b/components/engine/pkg/authorization/middleware_unix_test.go @@ -8,7 +8,8 @@ import ( "testing" "github.com/docker/docker/pkg/plugingetter" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -30,7 +31,7 @@ func TestMiddlewareWrapHandler(t *testing.T) { middleWare.SetPlugins([]string{"My Test Plugin"}) setAuthzPlugins(middleWare, authList) mdHandler := middleWare.WrapHandler(handler) - require.NotNil(t, mdHandler) + assert.Assert(t, mdHandler != nil) addr := "www.example.com/auth" req, _ := http.NewRequest("GET", addr, nil) @@ -46,7 +47,7 @@ func TestMiddlewareWrapHandler(t *testing.T) { Msg: "Server Auth Not Allowed", } if err := mdHandler(ctx, resp, req, map[string]string{}); err == nil { - require.Error(t, err) + assert.Assert(t, is.ErrorContains(err, "")) } }) @@ -57,7 +58,7 @@ func TestMiddlewareWrapHandler(t *testing.T) { Msg: "Server Auth Allowed", } if err := mdHandler(ctx, resp, req, map[string]string{}); err != nil { - require.NoError(t, err) + assert.NilError(t, err) } }) diff --git a/components/engine/pkg/fileutils/fileutils_test.go b/components/engine/pkg/fileutils/fileutils_test.go index 0a648d1466..b167538d5a 100644 --- a/components/engine/pkg/fileutils/fileutils_test.go +++ b/components/engine/pkg/fileutils/fileutils_test.go @@ -10,8 +10,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) // CopyFile with invalid src @@ -384,9 +384,9 @@ func TestMatches(t *testing.T) { for _, test := range tests { desc := fmt.Sprintf("pattern=%q text=%q", test.pattern, test.text) pm, err := NewPatternMatcher([]string{test.pattern}) - require.NoError(t, err, desc) + assert.NilError(t, err, desc) res, _ := pm.Matches(test.text) - assert.Equal(t, test.pass, res, desc) + assert.Check(t, is.Equal(test.pass, res), desc) } } diff --git a/components/engine/pkg/idtools/idtools_unix_test.go b/components/engine/pkg/idtools/idtools_unix_test.go index 931e332bb9..e493b9e8d5 100644 --- a/components/engine/pkg/idtools/idtools_unix_test.go +++ b/components/engine/pkg/idtools/idtools_unix_test.go @@ -10,9 +10,9 @@ import ( "path/filepath" "testing" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" "golang.org/x/sys/unix" ) @@ -89,7 +89,7 @@ func TestMkdirAllAndChown(t *testing.T) { func TestMkdirAllAndChownNew(t *testing.T) { RequiresRoot(t) dirName, err := ioutil.TempDir("", "mkdirnew") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dirName) testTree := map[string]node{ @@ -99,32 +99,32 @@ func TestMkdirAllAndChownNew(t *testing.T) { "lib/x86_64": {45, 45}, "lib/x86_64/share": {1, 1}, } - require.NoError(t, buildTree(dirName, testTree)) + assert.NilError(t, buildTree(dirName, testTree)) // test adding a directory to a pre-existing dir; only the new dir is owned by the uid/gid err = MkdirAllAndChownNew(filepath.Join(dirName, "usr", "share"), 0755, IDPair{UID: 99, GID: 99}) - require.NoError(t, err) + assert.NilError(t, err) testTree["usr/share"] = node{99, 99} verifyTree, err := readTree(dirName, "") - require.NoError(t, err) - require.NoError(t, compareTrees(testTree, verifyTree)) + assert.NilError(t, err) + assert.NilError(t, compareTrees(testTree, verifyTree)) // test 2-deep new directories--both should be owned by the uid/gid pair err = MkdirAllAndChownNew(filepath.Join(dirName, "lib", "some", "other"), 0755, IDPair{UID: 101, GID: 101}) - require.NoError(t, err) + assert.NilError(t, err) testTree["lib/some"] = node{101, 101} testTree["lib/some/other"] = node{101, 101} verifyTree, err = readTree(dirName, "") - require.NoError(t, err) - require.NoError(t, compareTrees(testTree, verifyTree)) + assert.NilError(t, err) + assert.NilError(t, compareTrees(testTree, verifyTree)) // test a directory that already exists; should NOT be chowned err = MkdirAllAndChownNew(filepath.Join(dirName, "usr"), 0755, IDPair{UID: 102, GID: 102}) - require.NoError(t, err) + assert.NilError(t, err) verifyTree, err = readTree(dirName, "") - require.NoError(t, err) - require.NoError(t, compareTrees(testTree, verifyTree)) + assert.NilError(t, err) + assert.NilError(t, compareTrees(testTree, verifyTree)) } func TestMkdirAndChown(t *testing.T) { @@ -235,7 +235,7 @@ func compareTrees(left, right map[string]node) error { func delUser(t *testing.T, name string) { _, err := execCmd("userdel", name) - assert.NoError(t, err) + assert.Check(t, err) } func TestParseSubidFileWithNewlinesAndComments(t *testing.T) { @@ -283,9 +283,9 @@ func TestGetRootUIDGID(t *testing.T) { } uid, gid, err := GetRootUIDGID(uidMap, gidMap) - assert.NoError(t, err) - assert.Equal(t, os.Getegid(), uid) - assert.Equal(t, os.Getegid(), gid) + assert.Check(t, err) + assert.Check(t, is.Equal(os.Getegid(), uid)) + assert.Check(t, is.Equal(os.Getegid(), gid)) uidMapError := []IDMap{ { @@ -295,7 +295,7 @@ func TestGetRootUIDGID(t *testing.T) { }, } _, _, err = GetRootUIDGID(uidMapError, gidMap) - assert.EqualError(t, err, "Container ID 0 cannot be mapped to a host ID") + assert.Check(t, is.Error(err, "Container ID 0 cannot be mapped to a host ID")) } func TestToContainer(t *testing.T) { @@ -308,74 +308,74 @@ func TestToContainer(t *testing.T) { } containerID, err := toContainer(2, uidMap) - assert.NoError(t, err) - assert.Equal(t, uidMap[0].ContainerID, containerID) + assert.Check(t, err) + assert.Check(t, is.Equal(uidMap[0].ContainerID, containerID)) } func TestNewIDMappings(t *testing.T) { RequiresRoot(t) _, _, err := AddNamespaceRangesUser(tempUser) - assert.NoError(t, err) + assert.Check(t, err) defer delUser(t, tempUser) tempUser, err := user.Lookup(tempUser) - assert.NoError(t, err) + assert.Check(t, err) gids, err := tempUser.GroupIds() - assert.NoError(t, err) + assert.Check(t, err) group, err := user.LookupGroupId(string(gids[0])) - assert.NoError(t, err) + assert.Check(t, err) idMappings, err := NewIDMappings(tempUser.Username, group.Name) - assert.NoError(t, err) + assert.Check(t, err) rootUID, rootGID, err := GetRootUIDGID(idMappings.UIDs(), idMappings.GIDs()) - assert.NoError(t, err) + assert.Check(t, err) dirName, err := ioutil.TempDir("", "mkdirall") - assert.NoError(t, err, "Couldn't create temp directory") + assert.Check(t, err, "Couldn't create temp directory") defer os.RemoveAll(dirName) err = MkdirAllAndChown(dirName, 0700, IDPair{UID: rootUID, GID: rootGID}) - assert.NoError(t, err, "Couldn't change ownership of file path. Got error") - assert.True(t, CanAccess(dirName, idMappings.RootPair()), fmt.Sprintf("Unable to access %s directory with user UID:%d and GID:%d", dirName, rootUID, rootGID)) + assert.Check(t, err, "Couldn't change ownership of file path. Got error") + assert.Check(t, CanAccess(dirName, idMappings.RootPair()), fmt.Sprintf("Unable to access %s directory with user UID:%d and GID:%d", dirName, rootUID, rootGID)) } func TestLookupUserAndGroup(t *testing.T) { RequiresRoot(t) uid, gid, err := AddNamespaceRangesUser(tempUser) - assert.NoError(t, err) + assert.Check(t, err) defer delUser(t, tempUser) fetchedUser, err := LookupUser(tempUser) - assert.NoError(t, err) + assert.Check(t, err) fetchedUserByID, err := LookupUID(uid) - assert.NoError(t, err) - assert.Equal(t, fetchedUserByID, fetchedUser) + assert.Check(t, err) + assert.Check(t, is.DeepEqual(fetchedUserByID, fetchedUser)) fetchedGroup, err := LookupGroup(tempUser) - assert.NoError(t, err) + assert.Check(t, err) fetchedGroupByID, err := LookupGID(gid) - assert.NoError(t, err) - assert.Equal(t, fetchedGroupByID, fetchedGroup) + assert.Check(t, err) + assert.Check(t, is.DeepEqual(fetchedGroupByID, fetchedGroup)) } func TestLookupUserAndGroupThatDoesNotExist(t *testing.T) { fakeUser := "fakeuser" _, err := LookupUser(fakeUser) - assert.EqualError(t, err, "getent unable to find entry \""+fakeUser+"\" in passwd database") + assert.Check(t, is.Error(err, "getent unable to find entry \""+fakeUser+"\" in passwd database")) _, err = LookupUID(-1) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) fakeGroup := "fakegroup" _, err = LookupGroup(fakeGroup) - assert.EqualError(t, err, "getent unable to find entry \""+fakeGroup+"\" in group database") + assert.Check(t, is.Error(err, "getent unable to find entry \""+fakeGroup+"\" in group database")) _, err = LookupGID(-1) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) } // TestMkdirIsNotDir checks that mkdirAs() function (used by MkdirAll...) @@ -389,7 +389,7 @@ func TestMkdirIsNotDir(t *testing.T) { defer os.Remove(file.Name()) err = mkdirAs(file.Name(), 0755, 0, 0, false, false) - assert.EqualError(t, err, "mkdir "+file.Name()+": not a directory") + assert.Check(t, is.Error(err, "mkdir "+file.Name()+": not a directory")) } func RequiresRoot(t *testing.T) { diff --git a/components/engine/pkg/ioutils/readers_test.go b/components/engine/pkg/ioutils/readers_test.go index e322fdf840..e009ab26f6 100644 --- a/components/engine/pkg/ioutils/readers_test.go +++ b/components/engine/pkg/ioutils/readers_test.go @@ -7,7 +7,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "golang.org/x/net/context" ) @@ -36,7 +37,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) { called = true }) _, err := wrapper.Read([]byte{}) - assert.EqualError(t, err, "error reader always fail") + assert.Check(t, is.Error(err, "error reader always fail")) if !called { t.Fatalf("readErrWrapper should have call the anonymous function on failure") } diff --git a/components/engine/pkg/jsonmessage/jsonmessage.go b/components/engine/pkg/jsonmessage/jsonmessage.go index 368f128949..b9f40d3ef1 100644 --- a/components/engine/pkg/jsonmessage/jsonmessage.go +++ b/components/engine/pkg/jsonmessage/jsonmessage.go @@ -40,21 +40,17 @@ type JSONProgress struct { // If true, don't show xB/yB HideCounts bool `json:"hidecounts,omitempty"` Units string `json:"units,omitempty"` + nowFunc func() time.Time + winSize int } func (p *JSONProgress) String() string { var ( - width = 200 + width = p.width() pbBox string numbersBox string timeLeftBox string ) - - ws, err := term.GetWinsize(p.terminalFd) - if err == nil { - width = int(ws.Width) - } - if p.Current <= 0 && p.Total <= 0 { return "" } @@ -103,7 +99,7 @@ func (p *JSONProgress) String() string { } if p.Current > 0 && p.Start > 0 && percentage < 50 { - fromStart := time.Now().UTC().Sub(time.Unix(p.Start, 0)) + fromStart := p.now().Sub(time.Unix(p.Start, 0)) perEntry := fromStart / time.Duration(p.Current) left := time.Duration(p.Total-p.Current) * perEntry left = (left / time.Second) * time.Second @@ -115,6 +111,28 @@ func (p *JSONProgress) String() string { return pbBox + numbersBox + timeLeftBox } +// shim for testing +func (p *JSONProgress) now() time.Time { + if p.nowFunc == nil { + p.nowFunc = func() time.Time { + return time.Now().UTC() + } + } + return p.nowFunc() +} + +// shim for testing +func (p *JSONProgress) width() int { + if p.winSize != 0 { + return p.winSize + } + ws, err := term.GetWinsize(p.terminalFd) + if err == nil { + return int(ws.Width) + } + return 200 +} + // JSONMessage defines a message struct. It describes // the created time, where it from, status, ID of the // message. It's used for docker events. diff --git a/components/engine/pkg/jsonmessage/jsonmessage_test.go b/components/engine/pkg/jsonmessage/jsonmessage_test.go index 2bad8a2025..f9ead207ca 100644 --- a/components/engine/pkg/jsonmessage/jsonmessage_test.go +++ b/components/engine/pkg/jsonmessage/jsonmessage_test.go @@ -9,89 +9,108 @@ import ( "time" "github.com/docker/docker/pkg/term" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestError(t *testing.T) { je := JSONError{404, "Not found"} - if je.Error() != "Not found" { - t.Fatalf("Expected 'Not found' got '%s'", je.Error()) - } + assert.Assert(t, is.Error(&je, "Not found")) } -func TestProgress(t *testing.T) { - termsz, err := term.GetWinsize(0) - if err != nil { - // we can safely ignore the err here - termsz = nil - } - jp := JSONProgress{} - if jp.String() != "" { - t.Fatalf("Expected empty string, got '%s'", jp.String()) +func TestProgressString(t *testing.T) { + type expected struct { + short string + long string } - expected := " 1B" - jp2 := JSONProgress{Current: 1} - if jp2.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp2.String()) + shortAndLong := func(short, long string) expected { + return expected{short: short, long: long} } - expectedStart := "[==========> ] 20B/100B" - if termsz != nil && termsz.Width <= 110 { - expectedStart = " 20B/100B" - } - jp3 := JSONProgress{Current: 20, Total: 100, Start: time.Now().Unix()} - // Just look at the start of the string - // (the remaining time is really hard to test -_-) - if jp3.String()[:len(expectedStart)] != expectedStart { - t.Fatalf("Expected to start with %q, got %q", expectedStart, jp3.String()) + start := time.Date(2017, 12, 3, 15, 10, 1, 0, time.UTC) + timeAfter := func(delta time.Duration) func() time.Time { + return func() time.Time { + return start.Add(delta) + } } - expected = "[=========================> ] 50B/100B" - if termsz != nil && termsz.Width <= 110 { - expected = " 50B/100B" - } - jp4 := JSONProgress{Current: 50, Total: 100} - if jp4.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp4.String()) + var testcases = []struct { + name string + progress JSONProgress + expected expected + }{ + { + name: "no progress", + }, + { + name: "progress 1", + progress: JSONProgress{Current: 1}, + expected: shortAndLong(" 1B", " 1B"), + }, + { + name: "some progress with a start time", + progress: JSONProgress{ + Current: 20, + Total: 100, + Start: start.Unix(), + nowFunc: timeAfter(time.Second), + }, + expected: shortAndLong( + " 20B/100B 4s", + "[==========> ] 20B/100B 4s", + ), + }, + { + name: "some progress without a start time", + progress: JSONProgress{Current: 50, Total: 100}, + expected: shortAndLong( + " 50B/100B", + "[=========================> ] 50B/100B", + ), + }, + { + name: "current more than total is not negative gh#7136", + progress: JSONProgress{Current: 50, Total: 40}, + expected: shortAndLong( + " 50B", + "[==================================================>] 50B", + ), + }, + { + name: "with units", + progress: JSONProgress{Current: 50, Total: 100, Units: "units"}, + expected: shortAndLong( + "50/100 units", + "[=========================> ] 50/100 units", + ), + }, + { + name: "current more than total with units is not negative ", + progress: JSONProgress{Current: 50, Total: 40, Units: "units"}, + expected: shortAndLong( + "50 units", + "[==================================================>] 50 units", + ), + }, + { + name: "hide counts", + progress: JSONProgress{Current: 50, Total: 100, HideCounts: true}, + expected: shortAndLong( + "", + "[=========================> ] ", + ), + }, } - // this number can't be negative gh#7136 - expected = "[==================================================>] 50B" - if termsz != nil && termsz.Width <= 110 { - expected = " 50B" - } - jp5 := JSONProgress{Current: 50, Total: 40} - if jp5.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp5.String()) - } + for _, testcase := range testcases { + t.Run(testcase.name, func(t *testing.T) { + testcase.progress.winSize = 100 + assert.Equal(t, testcase.progress.String(), testcase.expected.short) - expected = "[=========================> ] 50/100 units" - if termsz != nil && termsz.Width <= 110 { - expected = " 50/100 units" - } - jp6 := JSONProgress{Current: 50, Total: 100, Units: "units"} - if jp6.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp6.String()) - } - - // this number can't be negative - expected = "[==================================================>] 50 units" - if termsz != nil && termsz.Width <= 110 { - expected = " 50 units" - } - jp7 := JSONProgress{Current: 50, Total: 40, Units: "units"} - if jp7.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp7.String()) - } - - expected = "[=========================> ] " - if termsz != nil && termsz.Width <= 110 { - expected = "" - } - jp8 := JSONProgress{Current: 50, Total: 100, HideCounts: true} - if jp8.String() != expected { - t.Fatalf("Expected %q, got %q", expected, jp8.String()) + testcase.progress.winSize = 200 + assert.Equal(t, testcase.progress.String(), testcase.expected.long) + }) } } @@ -198,7 +217,7 @@ func TestJSONMessageDisplayWithJSONError(t *testing.T) { jsonMessage = JSONMessage{Error: &JSONError{401, "Anything"}} err = jsonMessage.Display(data, &noTermInfo{}) - assert.EqualError(t, err, "authentication is required") + assert.Check(t, is.Error(err, "authentication is required")) } func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) { diff --git a/components/engine/pkg/parsers/kernel/kernel_windows.go b/components/engine/pkg/parsers/kernel/kernel_windows.go index d54f032cb0..b7b15a1fd2 100644 --- a/components/engine/pkg/parsers/kernel/kernel_windows.go +++ b/components/engine/pkg/parsers/kernel/kernel_windows.go @@ -2,9 +2,9 @@ package kernel // import "github.com/docker/docker/pkg/parsers/kernel" import ( "fmt" - "unsafe" "golang.org/x/sys/windows" + "golang.org/x/sys/windows/registry" ) // VersionInfo holds information about the kernel. @@ -22,41 +22,24 @@ func (k *VersionInfo) String() string { // GetKernelVersion gets the current kernel version. func GetKernelVersion() (*VersionInfo, error) { - var ( - h windows.Handle - dwVersion uint32 - err error - ) - KVI := &VersionInfo{"Unknown", 0, 0, 0} - if err = windows.RegOpenKeyEx(windows.HKEY_LOCAL_MACHINE, - windows.StringToUTF16Ptr(`SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\`), - 0, - windows.KEY_READ, - &h); err != nil { + k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) + if err != nil { return KVI, err } - defer windows.RegCloseKey(h) + defer k.Close() - var buf [1 << 10]uint16 - var typ uint32 - n := uint32(len(buf) * 2) // api expects array of bytes, not uint16 - - if err = windows.RegQueryValueEx(h, - windows.StringToUTF16Ptr("BuildLabEx"), - nil, - &typ, - (*byte)(unsafe.Pointer(&buf[0])), - &n); err != nil { + blex, _, err := k.GetStringValue("BuildLabEx") + if err != nil { return KVI, err } - - KVI.kvi = windows.UTF16ToString(buf[:]) + KVI.kvi = blex // Important - docker.exe MUST be manifested for this API to return // the correct information. - if dwVersion, err = windows.GetVersion(); err != nil { + dwVersion, err := windows.GetVersion() + if err != nil { return KVI, err } diff --git a/components/engine/pkg/parsers/operatingsystem/operatingsystem_windows.go b/components/engine/pkg/parsers/operatingsystem/operatingsystem_windows.go index aec4cce72d..372de51469 100644 --- a/components/engine/pkg/parsers/operatingsystem/operatingsystem_windows.go +++ b/components/engine/pkg/parsers/operatingsystem/operatingsystem_windows.go @@ -12,7 +12,7 @@ func GetOperatingSystem() (string, error) { // Default return value ret := "Unknown Operating System" - k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\WIndows NT\CurrentVersion`, registry.QUERY_VALUE) + k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.QUERY_VALUE) if err != nil { return ret, err } diff --git a/components/engine/pkg/plugins/client_test.go b/components/engine/pkg/plugins/client_test.go index 10c8d8fd56..d420010f1a 100644 --- a/components/engine/pkg/plugins/client_test.go +++ b/components/engine/pkg/plugins/client_test.go @@ -14,9 +14,9 @@ import ( "github.com/docker/docker/pkg/plugins/transport" "github.com/docker/go-connections/tlsconfig" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ( @@ -88,7 +88,7 @@ func TestEchoInputOutput(t *testing.T) { t.Fatal(err) } - assert.Equal(t, m, output) + assert.Check(t, is.DeepEqual(m, output)) err = c.Call("Test.Echo", nil, nil) if err != nil { t.Fatal(err) @@ -205,7 +205,7 @@ func TestClientStream(t *testing.T) { if err := json.NewDecoder(body).Decode(&output); err != nil { t.Fatalf("Test.Echo: error reading plugin resp: %v", err) } - assert.Equal(t, m, output) + assert.Check(t, is.DeepEqual(m, output)) } func TestClientSendFile(t *testing.T) { @@ -233,7 +233,7 @@ func TestClientSendFile(t *testing.T) { if err := c.SendFile("Test.Echo", &buf, &output); err != nil { t.Fatal(err) } - assert.Equal(t, m, output) + assert.Check(t, is.DeepEqual(m, output)) } func TestClientWithRequestTimeout(t *testing.T) { @@ -248,7 +248,7 @@ func TestClientWithRequestTimeout(t *testing.T) { client := &Client{http: srv.Client(), requestFactory: &testRequestWrapper{srv}} _, err := client.callWithRetry("/Plugin.Hello", nil, false, WithRequestTimeout(timeout)) - require.Error(t, err, "expected error") + assert.Assert(t, is.ErrorContains(err, ""), "expected error") err = errors.Cause(err) @@ -256,7 +256,7 @@ func TestClientWithRequestTimeout(t *testing.T) { case *url.Error: err = e.Err } - require.Equal(t, context.DeadlineExceeded, err) + assert.DeepEqual(t, context.DeadlineExceeded, err) } type testRequestWrapper struct { diff --git a/components/engine/pkg/plugins/discovery_unix_test.go b/components/engine/pkg/plugins/discovery_unix_test.go index 9212946b2e..2c718d8bee 100644 --- a/components/engine/pkg/plugins/discovery_unix_test.go +++ b/components/engine/pkg/plugins/discovery_unix_test.go @@ -11,7 +11,7 @@ import ( "reflect" "testing" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestLocalSocket(t *testing.T) { @@ -91,7 +91,7 @@ func TestScan(t *testing.T) { r := newLocalRegistry() p, err := r.Plugin(name) - require.NoError(t, err) + assert.NilError(t, err) pluginNamesNotEmpty, err := Scan() if err != nil { diff --git a/components/engine/pkg/plugins/plugin_test.go b/components/engine/pkg/plugins/plugin_test.go index 1540a19a64..ca8d598400 100644 --- a/components/engine/pkg/plugins/plugin_test.go +++ b/components/engine/pkg/plugins/plugin_test.go @@ -14,8 +14,8 @@ import ( "github.com/docker/docker/pkg/plugins/transport" "github.com/docker/go-connections/tlsconfig" + "github.com/gotestyourself/gotestyourself/assert" "github.com/pkg/errors" - "github.com/stretchr/testify/assert" ) const ( @@ -54,7 +54,6 @@ func testActive(t *testing.T, p *Plugin) { t.Fatalf("%s:%d: deadlock in waitActive", filepath.Base(f), l) case <-done: } - } func TestGet(t *testing.T) { @@ -83,7 +82,6 @@ func TestGet(t *testing.T) { // check negative case where plugin vegetable doesn't exist _, err = Get("vegetable", "potato") assert.Equal(t, errors.Cause(err), ErrNotFound) - } func TestPluginWithNoManifest(t *testing.T) { diff --git a/components/engine/pkg/plugins/transport/http_test.go b/components/engine/pkg/plugins/transport/http_test.go index 2e48b0fe0a..081f60424d 100644 --- a/components/engine/pkg/plugins/transport/http_test.go +++ b/components/engine/pkg/plugins/transport/http_test.go @@ -5,7 +5,8 @@ import ( "net/http" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestHTTPTransport(t *testing.T) { @@ -16,5 +17,5 @@ func TestHTTPTransport(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, "POST", request.Method) + assert.Check(t, is.Equal("POST", request.Method)) } diff --git a/components/engine/pkg/pools/pools_test.go b/components/engine/pkg/pools/pools_test.go index 2dbea36ae0..76015169d4 100644 --- a/components/engine/pkg/pools/pools_test.go +++ b/components/engine/pkg/pools/pools_test.go @@ -7,8 +7,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestBufioReaderPoolGetWithNoReaderShouldCreateOne(t *testing.T) { @@ -95,16 +95,16 @@ func TestBufioWriterPoolPutAndGet(t *testing.T) { buf := new(bytes.Buffer) bw := bufio.NewWriter(buf) writer := BufioWriter32KPool.Get(bw) - require.NotNil(t, writer) + assert.Assert(t, writer != nil) written, err := writer.Write([]byte("foobar")) - require.NoError(t, err) - assert.Equal(t, 6, written) + assert.NilError(t, err) + assert.Check(t, is.Equal(6, written)) // Make sure we Flush all the way ? writer.Flush() bw.Flush() - assert.Len(t, buf.Bytes(), 6) + assert.Check(t, is.Len(buf.Bytes(), 6)) // Reset the buffer buf.Reset() BufioWriter32KPool.Put(writer) diff --git a/components/engine/pkg/reexec/reexec_test.go b/components/engine/pkg/reexec/reexec_test.go index e6bbe9f9a0..90aa01a390 100644 --- a/components/engine/pkg/reexec/reexec_test.go +++ b/components/engine/pkg/reexec/reexec_test.go @@ -5,8 +5,7 @@ import ( "os/exec" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func init() { @@ -19,7 +18,7 @@ func init() { func TestRegister(t *testing.T) { defer func() { if r := recover(); r != nil { - require.Equal(t, `reexec func already registered under name "reexec"`, r) + assert.Equal(t, `reexec func already registered under name "reexec"`, r) } }() Register("reexec", func() {}) @@ -28,13 +27,13 @@ func TestRegister(t *testing.T) { func TestCommand(t *testing.T) { cmd := Command("reexec") w, err := cmd.StdinPipe() - require.NoError(t, err, "Error on pipe creation: %v", err) + assert.NilError(t, err, "Error on pipe creation: %v", err) defer w.Close() err = cmd.Start() - require.NoError(t, err, "Error on re-exec cmd: %v", err) + assert.NilError(t, err, "Error on re-exec cmd: %v", err) err = cmd.Wait() - require.EqualError(t, err, "exit status 2") + assert.Error(t, err, "exit status 2") } func TestNaiveSelf(t *testing.T) { @@ -44,10 +43,10 @@ func TestNaiveSelf(t *testing.T) { cmd := exec.Command(naiveSelf(), "-test.run=TestNaiveSelf") cmd.Env = append(os.Environ(), "TEST_CHECK=1") err := cmd.Start() - require.NoError(t, err, "Unable to start command") + assert.NilError(t, err, "Unable to start command") err = cmd.Wait() - require.EqualError(t, err, "exit status 2") + assert.Error(t, err, "exit status 2") os.Args[0] = "mkdir" - assert.NotEqual(t, naiveSelf(), os.Args[0]) + assert.Check(t, naiveSelf() != os.Args[0]) } diff --git a/components/engine/pkg/signal/signal_linux_test.go b/components/engine/pkg/signal/signal_linux_test.go index d7e8da2523..71c577ed64 100644 --- a/components/engine/pkg/signal/signal_linux_test.go +++ b/components/engine/pkg/signal/signal_linux_test.go @@ -8,7 +8,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestCatchAll(t *testing.T) { @@ -34,7 +35,7 @@ func TestCatchAll(t *testing.T) { }() s := <-sigs - assert.EqualValues(t, s.String(), signal.String()) + assert.Check(t, is.Equal(s.String(), signal.String())) } } @@ -50,9 +51,9 @@ func TestStopCatch(t *testing.T) { syscall.Kill(syscall.Getpid(), signal) }() signalString := <-channel - assert.EqualValues(t, signalString.String(), signal.String()) + assert.Check(t, is.Equal(signalString.String(), signal.String())) StopCatch(channel) _, ok := <-channel - assert.EqualValues(t, ok, false) + assert.Check(t, is.Equal(ok, false)) } diff --git a/components/engine/pkg/signal/signal_test.go b/components/engine/pkg/signal/signal_test.go index 1add526d16..bbf3736fc8 100644 --- a/components/engine/pkg/signal/signal_test.go +++ b/components/engine/pkg/signal/signal_test.go @@ -4,30 +4,31 @@ import ( "syscall" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestParseSignal(t *testing.T) { _, checkAtoiError := ParseSignal("0") - assert.EqualError(t, checkAtoiError, "Invalid signal: 0") + assert.Check(t, is.Error(checkAtoiError, "Invalid signal: 0")) _, error := ParseSignal("SIG") - assert.EqualError(t, error, "Invalid signal: SIG") + assert.Check(t, is.Error(error, "Invalid signal: SIG")) for sigStr := range SignalMap { responseSignal, error := ParseSignal(sigStr) - assert.NoError(t, error) + assert.Check(t, error) signal := SignalMap[sigStr] - assert.EqualValues(t, signal, responseSignal) + assert.Check(t, is.DeepEqual(signal, responseSignal)) } } func TestValidSignalForPlatform(t *testing.T) { isValidSignal := ValidSignalForPlatform(syscall.Signal(0)) - assert.EqualValues(t, false, isValidSignal) + assert.Check(t, is.Equal(false, isValidSignal)) for _, sigN := range SignalMap { isValidSignal = ValidSignalForPlatform(syscall.Signal(sigN)) - assert.EqualValues(t, true, isValidSignal) + assert.Check(t, is.Equal(true, isValidSignal)) } } diff --git a/components/engine/pkg/signal/trap_linux_test.go b/components/engine/pkg/signal/trap_linux_test.go index d32a4366f4..a3afe7a7b6 100644 --- a/components/engine/pkg/signal/trap_linux_test.go +++ b/components/engine/pkg/signal/trap_linux_test.go @@ -10,19 +10,19 @@ import ( "syscall" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func buildTestBinary(t *testing.T, tmpdir string, prefix string) (string, string) { tmpDir, err := ioutil.TempDir(tmpdir, prefix) - require.NoError(t, err) + assert.NilError(t, err) exePath := tmpDir + "/" + prefix wd, _ := os.Getwd() testHelperCode := wd + "/testfiles/main.go" cmd := exec.Command("go", "build", "-o", exePath, testHelperCode) err = cmd.Run() - require.NoError(t, err) + assert.NilError(t, err) return exePath, tmpDir } @@ -48,14 +48,14 @@ func TestTrap(t *testing.T) { cmd.Env = append(cmd.Env, "IF_MULTIPLE=1") } err := cmd.Start() - require.NoError(t, err) + assert.NilError(t, err) err = cmd.Wait() if e, ok := err.(*exec.ExitError); ok { code := e.Sys().(syscall.WaitStatus).ExitStatus() if v.multiple { - assert.Equal(t, 128+int(v.signal.(syscall.Signal)), code) + assert.Check(t, is.DeepEqual(128+int(v.signal.(syscall.Signal)), code)) } else { - assert.Equal(t, 99, code) + assert.Check(t, is.Equal(99, code)) } continue } @@ -66,17 +66,17 @@ func TestTrap(t *testing.T) { func TestDumpStacks(t *testing.T) { directory, err := ioutil.TempDir("", "test-dump-tasks") - assert.NoError(t, err) + assert.Check(t, err) defer os.RemoveAll(directory) dumpPath, err := DumpStacks(directory) - assert.NoError(t, err) + assert.Check(t, err) readFile, _ := ioutil.ReadFile(dumpPath) fileData := string(readFile) - assert.Contains(t, fileData, "goroutine") + assert.Check(t, is.Contains(fileData, "goroutine")) } func TestDumpStacksWithEmptyInput(t *testing.T) { path, err := DumpStacks("") - assert.NoError(t, err) - assert.Equal(t, os.Stderr.Name(), path) + assert.Check(t, err) + assert.Check(t, is.Equal(os.Stderr.Name(), path)) } diff --git a/components/engine/pkg/streamformatter/streamformatter_test.go b/components/engine/pkg/streamformatter/streamformatter_test.go index 7259c54df8..172d568bda 100644 --- a/components/engine/pkg/streamformatter/streamformatter_test.go +++ b/components/engine/pkg/streamformatter/streamformatter_test.go @@ -8,14 +8,16 @@ import ( "testing" "github.com/docker/docker/pkg/jsonmessage" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestRawProgressFormatterFormatStatus(t *testing.T) { sf := rawProgressFormatter{} res := sf.formatStatus("ID", "%s%d", "a", 1) - assert.Equal(t, "a1\r\n", string(res)) + assert.Check(t, is.Equal("a1\r\n", string(res))) } func TestRawProgressFormatterFormatProgress(t *testing.T) { @@ -27,28 +29,28 @@ func TestRawProgressFormatterFormatProgress(t *testing.T) { } res := sf.formatProgress("id", "action", jsonProgress, nil) out := string(res) - assert.True(t, strings.HasPrefix(out, "action [====")) - assert.Contains(t, out, "15B/30B") - assert.True(t, strings.HasSuffix(out, "\r")) + assert.Check(t, strings.HasPrefix(out, "action [====")) + assert.Check(t, is.Contains(out, "15B/30B")) + assert.Check(t, strings.HasSuffix(out, "\r")) } func TestFormatStatus(t *testing.T) { res := FormatStatus("ID", "%s%d", "a", 1) expected := `{"status":"a1","id":"ID"}` + streamNewline - assert.Equal(t, expected, string(res)) + assert.Check(t, is.Equal(expected, string(res))) } func TestFormatError(t *testing.T) { res := FormatError(errors.New("Error for formatter")) expected := `{"errorDetail":{"message":"Error for formatter"},"error":"Error for formatter"}` + "\r\n" - assert.Equal(t, expected, string(res)) + assert.Check(t, is.Equal(expected, string(res))) } func TestFormatJSONError(t *testing.T) { err := &jsonmessage.JSONError{Code: 50, Message: "Json error"} res := FormatError(err) expected := `{"errorDetail":{"code":50,"message":"Json error"},"error":"Json error"}` + streamNewline - assert.Equal(t, expected, string(res)) + assert.Check(t, is.Equal(expected, string(res))) } func TestJsonProgressFormatterFormatProgress(t *testing.T) { @@ -58,43 +60,44 @@ func TestJsonProgressFormatterFormatProgress(t *testing.T) { Total: 30, Start: 1, } - res := sf.formatProgress("id", "action", jsonProgress, &AuxFormatter{Writer: &bytes.Buffer{}}) + aux := "aux message" + res := sf.formatProgress("id", "action", jsonProgress, aux) msg := &jsonmessage.JSONMessage{} - require.NoError(t, json.Unmarshal(res, msg)) - assert.Equal(t, "id", msg.ID) - assert.Equal(t, "action", msg.Status) + assert.NilError(t, json.Unmarshal(res, msg)) - // jsonProgress will always be in the format of: - // [=========================> ] 15B/30B 412910h51m30s - // The last entry '404933h7m11s' is the timeLeftBox. - // However, the timeLeftBox field may change as jsonProgress.String() depends on time.Now(). - // Therefore, we have to strip the timeLeftBox from the strings to do the comparison. - - // Compare the jsonProgress strings before the timeLeftBox - expectedProgress := "[=========================> ] 15B/30B" - // if terminal column is <= 110, expectedProgressShort is expected. - expectedProgressShort := " 15B/30B" - if !(strings.HasPrefix(msg.ProgressMessage, expectedProgress) || - strings.HasPrefix(msg.ProgressMessage, expectedProgressShort)) { - t.Fatalf("ProgressMessage without the timeLeftBox must be %s or %s, got: %s", - expectedProgress, expectedProgressShort, msg.ProgressMessage) + rawAux := json.RawMessage(`"` + aux + `"`) + expected := &jsonmessage.JSONMessage{ + ID: "id", + Status: "action", + Aux: &rawAux, + Progress: jsonProgress, } + assert.DeepEqual(t, msg, expected, cmpJSONMessageOpt()) +} - assert.Equal(t, jsonProgress, msg.Progress) +func cmpJSONMessageOpt() cmp.Option { + progressMessagePath := func(path cmp.Path) bool { + return path.String() == "ProgressMessage" + } + return cmp.Options{ + cmpopts.IgnoreUnexported(jsonmessage.JSONProgress{}), + // Ignore deprecated property that is a derivative of Progress + cmp.FilterPath(progressMessagePath, cmp.Ignore()), + } } func TestJsonProgressFormatterFormatStatus(t *testing.T) { sf := jsonProgressFormatter{} res := sf.formatStatus("ID", "%s%d", "a", 1) - assert.Equal(t, `{"status":"a1","id":"ID"}`+streamNewline, string(res)) + assert.Check(t, is.Equal(`{"status":"a1","id":"ID"}`+streamNewline, string(res))) } func TestNewJSONProgressOutput(t *testing.T) { b := bytes.Buffer{} b.Write(FormatStatus("id", "Downloading")) _ = NewJSONProgressOutput(&b, false) - assert.Equal(t, `{"status":"Downloading","id":"id"}`+streamNewline, b.String()) + assert.Check(t, is.Equal(`{"status":"Downloading","id":"id"}`+streamNewline, b.String())) } func TestAuxFormatterEmit(t *testing.T) { @@ -104,6 +107,6 @@ func TestAuxFormatterEmit(t *testing.T) { Data string }{"Additional data"} err := aux.Emit(sampleAux) - require.NoError(t, err) - assert.Equal(t, `{"aux":{"Data":"Additional data"}}`+streamNewline, b.String()) + assert.NilError(t, err) + assert.Check(t, is.Equal(`{"aux":{"Data":"Additional data"}}`+streamNewline, b.String())) } diff --git a/components/engine/pkg/streamformatter/streamwriter_test.go b/components/engine/pkg/streamformatter/streamwriter_test.go index 332d66414f..b74d6fb2d3 100644 --- a/components/engine/pkg/streamformatter/streamwriter_test.go +++ b/components/engine/pkg/streamformatter/streamwriter_test.go @@ -4,8 +4,8 @@ import ( "bytes" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestStreamWriterStdout(t *testing.T) { @@ -14,11 +14,11 @@ func TestStreamWriterStdout(t *testing.T) { sw := NewStdoutWriter(buffer) size, err := sw.Write([]byte(content)) - require.NoError(t, err) - assert.Equal(t, len(content), size) + assert.NilError(t, err) + assert.Check(t, is.Equal(len(content), size)) expected := `{"stream":"content"}` + streamNewline - assert.Equal(t, expected, buffer.String()) + assert.Check(t, is.Equal(expected, buffer.String())) } func TestStreamWriterStderr(t *testing.T) { @@ -27,9 +27,9 @@ func TestStreamWriterStderr(t *testing.T) { sw := NewStderrWriter(buffer) size, err := sw.Write([]byte(content)) - require.NoError(t, err) - assert.Equal(t, len(content), size) + assert.NilError(t, err) + assert.Check(t, is.Equal(len(content), size)) expected := `{"stream":"\u001b[91mcontent\u001b[0m"}` + streamNewline - assert.Equal(t, expected, buffer.String()) + assert.Check(t, is.Equal(expected, buffer.String())) } diff --git a/components/engine/pkg/sysinfo/sysinfo_linux_test.go b/components/engine/pkg/sysinfo/sysinfo_linux_test.go index a798bf6e85..e8a12a35c9 100644 --- a/components/engine/pkg/sysinfo/sysinfo_linux_test.go +++ b/components/engine/pkg/sysinfo/sysinfo_linux_test.go @@ -7,18 +7,18 @@ import ( "path/filepath" "testing" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" "golang.org/x/sys/unix" ) func TestReadProcBool(t *testing.T) { tmpDir, err := ioutil.TempDir("", "test-sysinfo-proc") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) procFile := filepath.Join(tmpDir, "read-proc-bool") err = ioutil.WriteFile(procFile, []byte("1"), 0644) - require.NoError(t, err) + assert.NilError(t, err) if !readProcBool(procFile) { t.Fatal("expected proc bool to be true, got false") @@ -39,7 +39,7 @@ func TestReadProcBool(t *testing.T) { func TestCgroupEnabled(t *testing.T) { cgroupDir, err := ioutil.TempDir("", "cgroup-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(cgroupDir) if cgroupEnabled(cgroupDir, "test") { @@ -47,7 +47,7 @@ func TestCgroupEnabled(t *testing.T) { } err = ioutil.WriteFile(path.Join(cgroupDir, "test"), []byte{}, 0644) - require.NoError(t, err) + assert.NilError(t, err) if !cgroupEnabled(cgroupDir, "test") { t.Fatal("cgroupEnabled should be true") @@ -56,11 +56,11 @@ func TestCgroupEnabled(t *testing.T) { func TestNew(t *testing.T) { sysInfo := New(false) - require.NotNil(t, sysInfo) + assert.Assert(t, sysInfo != nil) checkSysInfo(t, sysInfo) sysInfo = New(true) - require.NotNil(t, sysInfo) + assert.Assert(t, sysInfo != nil) checkSysInfo(t, sysInfo) } @@ -69,10 +69,10 @@ func checkSysInfo(t *testing.T, sysInfo *SysInfo) { if err := unix.Prctl(unix.PR_GET_SECCOMP, 0, 0, 0, 0); err != unix.EINVAL { // Make sure the kernel has CONFIG_SECCOMP_FILTER. if err := unix.Prctl(unix.PR_SET_SECCOMP, unix.SECCOMP_MODE_FILTER, 0, 0, 0); err != unix.EINVAL { - require.True(t, sysInfo.Seccomp) + assert.Assert(t, sysInfo.Seccomp) } } else { - require.False(t, sysInfo.Seccomp) + assert.Assert(t, !sysInfo.Seccomp) } } @@ -83,7 +83,7 @@ func TestNewAppArmorEnabled(t *testing.T) { } sysInfo := New(true) - require.True(t, sysInfo.AppArmor) + assert.Assert(t, sysInfo.AppArmor) } func TestNewAppArmorDisabled(t *testing.T) { @@ -93,7 +93,7 @@ func TestNewAppArmorDisabled(t *testing.T) { } sysInfo := New(true) - require.False(t, sysInfo.AppArmor) + assert.Assert(t, !sysInfo.AppArmor) } func TestNumCPU(t *testing.T) { diff --git a/components/engine/pkg/system/stat_unix_test.go b/components/engine/pkg/system/stat_unix_test.go index 12687b33c1..fd68a96656 100644 --- a/components/engine/pkg/system/stat_unix_test.go +++ b/components/engine/pkg/system/stat_unix_test.go @@ -7,7 +7,7 @@ import ( "syscall" "testing" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) // TestFromStatT tests fromStatT for a tempfile @@ -17,10 +17,10 @@ func TestFromStatT(t *testing.T) { stat := &syscall.Stat_t{} err := syscall.Lstat(file, stat) - require.NoError(t, err) + assert.NilError(t, err) s, err := fromStatT(stat) - require.NoError(t, err) + assert.NilError(t, err) if stat.Mode != s.Mode() { t.Fatal("got invalid mode") diff --git a/components/engine/pkg/tarsum/tarsum_test.go b/components/engine/pkg/tarsum/tarsum_test.go index 466eda0aec..35f08ebce9 100644 --- a/components/engine/pkg/tarsum/tarsum_test.go +++ b/components/engine/pkg/tarsum/tarsum_test.go @@ -17,8 +17,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) type testLayer struct { @@ -225,13 +225,13 @@ func TestNewTarSumForLabel(t *testing.T) { func TestEmptyTar(t *testing.T) { // Test without gzip. ts, err := emptyTarSum(false) - require.NoError(t, err) + assert.NilError(t, err) zeroBlock := make([]byte, 1024) buf := new(bytes.Buffer) n, err := io.Copy(buf, ts) - require.NoError(t, err) + assert.NilError(t, err) if n != int64(len(zeroBlock)) || !bytes.Equal(buf.Bytes(), zeroBlock) { t.Fatalf("tarSum did not write the correct number of zeroed bytes: %d", n) @@ -246,16 +246,16 @@ func TestEmptyTar(t *testing.T) { // Test with gzip. ts, err = emptyTarSum(true) - require.NoError(t, err) + assert.NilError(t, err) buf.Reset() _, err = io.Copy(buf, ts) - require.NoError(t, err) + assert.NilError(t, err) bufgz := new(bytes.Buffer) gz := gzip.NewWriter(bufgz) n, err = io.Copy(gz, bytes.NewBuffer(zeroBlock)) - require.NoError(t, err) + assert.NilError(t, err) gz.Close() gzBytes := bufgz.Bytes() @@ -275,7 +275,7 @@ func TestEmptyTar(t *testing.T) { } resultSum = ts.Sum(nil) - assert.Equal(t, expectedSum, resultSum) + assert.Check(t, is.Equal(expectedSum, resultSum)) } var ( diff --git a/components/engine/pkg/term/ascii_test.go b/components/engine/pkg/term/ascii_test.go index e426de35b4..321d1b87de 100644 --- a/components/engine/pkg/term/ascii_test.go +++ b/components/engine/pkg/term/ascii_test.go @@ -3,23 +3,23 @@ package term // import "github.com/docker/docker/pkg/term" import ( "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestToBytes(t *testing.T) { codes, err := ToBytes("ctrl-a,a") - require.NoError(t, err) - assert.Equal(t, []byte{1, 97}, codes) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual([]byte{1, 97}, codes)) _, err = ToBytes("shift-z") - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o") - require.NoError(t, err) - assert.Equal(t, []byte{0, 27, 126, 15}, codes) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual([]byte{0, 27, 126, 15}, codes)) codes, err = ToBytes("DEL,+") - require.NoError(t, err) - assert.Equal(t, []byte{127, 43}, codes) + assert.NilError(t, err) + assert.Check(t, is.DeepEqual([]byte{127, 43}, codes)) } diff --git a/components/engine/pkg/term/proxy_test.go b/components/engine/pkg/term/proxy_test.go index ff40c1beff..759be51456 100644 --- a/components/engine/pkg/term/proxy_test.go +++ b/components/engine/pkg/term/proxy_test.go @@ -3,10 +3,10 @@ package term // import "github.com/docker/docker/pkg/term" import ( "bytes" "fmt" - "reflect" "testing" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestEscapeProxyRead(t *testing.T) { @@ -15,78 +15,75 @@ func TestEscapeProxyRead(t *testing.T) { reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf := make([]byte, len(keys)) nr, err := reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, len(keys), fmt.Sprintf("nr %d should be equal to the number of %d", nr, len(keys))) - require.Equal(t, keys, buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, len(keys), fmt.Sprintf("nr %d should be equal to the number of %d", nr, len(keys))) + assert.DeepEqual(t, keys, buf) keys, _ = ToBytes("") reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf = make([]byte, len(keys)) nr, err = reader.Read(buf) - require.Error(t, err, "Should throw error when no keys are to read") - require.EqualValues(t, nr, 0, "nr should be zero") - require.Condition(t, func() (success bool) { return len(keys) == 0 && len(buf) == 0 }, "keys & the read buffer size should be zero") + assert.Assert(t, is.ErrorContains(err, ""), "Should throw error when no keys are to read") + assert.Equal(t, nr, 0, "nr should be zero") + assert.Check(t, is.Len(keys, 0)) + assert.Check(t, is.Len(buf, 0)) escapeKeys, _ = ToBytes("ctrl-x,ctrl-@") keys, _ = ToBytes("DEL") reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf = make([]byte, len(keys)) nr, err = reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, 1, fmt.Sprintf("nr %d should be equal to the number of 1", nr)) - require.Equal(t, keys, buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, 1, fmt.Sprintf("nr %d should be equal to the number of 1", nr)) + assert.DeepEqual(t, keys, buf) escapeKeys, _ = ToBytes("ctrl-c") keys, _ = ToBytes("ctrl-c") reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf = make([]byte, len(keys)) nr, err = reader.Read(buf) - require.Condition(t, func() (success bool) { - return reflect.TypeOf(err).Name() == "EscapeError" - }, err) - require.EqualValues(t, nr, 0, "nr should be equal to 0") - require.Equal(t, keys, buf, "keys & the read buffer should be equal") + assert.Error(t, err, "read escape sequence") + assert.Equal(t, nr, 0, "nr should be equal to 0") + assert.DeepEqual(t, keys, buf) escapeKeys, _ = ToBytes("ctrl-c,ctrl-z") keys, _ = ToBytes("ctrl-c,ctrl-z") reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf = make([]byte, 1) nr, err = reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, 0, "nr should be equal to 0") - require.Equal(t, keys[0:1], buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, 0, "nr should be equal to 0") + assert.DeepEqual(t, keys[0:1], buf) nr, err = reader.Read(buf) - require.Condition(t, func() (success bool) { - return reflect.TypeOf(err).Name() == "EscapeError" - }, err) - require.EqualValues(t, nr, 0, "nr should be equal to 0") - require.Equal(t, keys[1:], buf, "keys & the read buffer should be equal") + assert.Error(t, err, "read escape sequence") + assert.Equal(t, nr, 0, "nr should be equal to 0") + assert.DeepEqual(t, keys[1:], buf) escapeKeys, _ = ToBytes("ctrl-c,ctrl-z") keys, _ = ToBytes("ctrl-c,DEL,+") reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf = make([]byte, 1) nr, err = reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, 0, "nr should be equal to 0") - require.Equal(t, keys[0:1], buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, 0, "nr should be equal to 0") + assert.DeepEqual(t, keys[0:1], buf) buf = make([]byte, len(keys)) nr, err = reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys))) - require.Equal(t, keys, buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys))) + assert.DeepEqual(t, keys, buf) escapeKeys, _ = ToBytes("ctrl-c,ctrl-z") keys, _ = ToBytes("ctrl-c,DEL") reader = NewEscapeProxy(bytes.NewReader(keys), escapeKeys) buf = make([]byte, 1) nr, err = reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, 0, "nr should be equal to 0") - require.Equal(t, keys[0:1], buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, 0, "nr should be equal to 0") + assert.DeepEqual(t, keys[0:1], buf) buf = make([]byte, len(keys)) nr, err = reader.Read(buf) - require.NoError(t, err) - require.EqualValues(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys))) - require.Equal(t, keys, buf, "keys & the read buffer should be equal") + assert.NilError(t, err) + assert.Equal(t, nr, len(keys), fmt.Sprintf("nr should be equal to %d", len(keys))) + assert.DeepEqual(t, keys, buf) } diff --git a/components/engine/pkg/term/term_linux_test.go b/components/engine/pkg/term/term_linux_test.go index 6e42d3edd7..4f1d67586f 100644 --- a/components/engine/pkg/term/term_linux_test.go +++ b/components/engine/pkg/term/term_linux_test.go @@ -7,7 +7,8 @@ import ( "os" "testing" - "github.com/stretchr/testify/require" + "github.com/google/go-cmp/cmp" + "github.com/gotestyourself/gotestyourself/assert" ) // RequiresRoot skips tests that require root, unless the test.root flag has @@ -31,85 +32,86 @@ func newTempFile() (*os.File, error) { func TestGetWinsize(t *testing.T) { tty, err := newTtyForTest(t) defer tty.Close() - require.NoError(t, err) + assert.NilError(t, err) winSize, err := GetWinsize(tty.Fd()) - require.NoError(t, err) - require.NotNil(t, winSize) - require.NotNil(t, winSize.Height) - require.NotNil(t, winSize.Width) + assert.NilError(t, err) + assert.Assert(t, winSize != nil) + newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y} err = SetWinsize(tty.Fd(), &newSize) - require.NoError(t, err) + assert.NilError(t, err) winSize, err = GetWinsize(tty.Fd()) - require.NoError(t, err) - require.Equal(t, *winSize, newSize) + assert.NilError(t, err) + assert.DeepEqual(t, *winSize, newSize, cmpWinsize) } +var cmpWinsize = cmp.AllowUnexported(Winsize{}) + func TestSetWinsize(t *testing.T) { tty, err := newTtyForTest(t) defer tty.Close() - require.NoError(t, err) + assert.NilError(t, err) winSize, err := GetWinsize(tty.Fd()) - require.NoError(t, err) - require.NotNil(t, winSize) + assert.NilError(t, err) + assert.Assert(t, winSize != nil) newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y} err = SetWinsize(tty.Fd(), &newSize) - require.NoError(t, err) + assert.NilError(t, err) winSize, err = GetWinsize(tty.Fd()) - require.NoError(t, err) - require.Equal(t, *winSize, newSize) + assert.NilError(t, err) + assert.DeepEqual(t, *winSize, newSize, cmpWinsize) } func TestGetFdInfo(t *testing.T) { tty, err := newTtyForTest(t) defer tty.Close() - require.NoError(t, err) + assert.NilError(t, err) inFd, isTerminal := GetFdInfo(tty) - require.Equal(t, inFd, tty.Fd()) - require.Equal(t, isTerminal, true) + assert.Equal(t, inFd, tty.Fd()) + assert.Equal(t, isTerminal, true) tmpFile, err := newTempFile() - require.NoError(t, err) + assert.NilError(t, err) defer tmpFile.Close() inFd, isTerminal = GetFdInfo(tmpFile) - require.Equal(t, inFd, tmpFile.Fd()) - require.Equal(t, isTerminal, false) + assert.Equal(t, inFd, tmpFile.Fd()) + assert.Equal(t, isTerminal, false) } func TestIsTerminal(t *testing.T) { tty, err := newTtyForTest(t) defer tty.Close() - require.NoError(t, err) + assert.NilError(t, err) isTerminal := IsTerminal(tty.Fd()) - require.Equal(t, isTerminal, true) + assert.Equal(t, isTerminal, true) tmpFile, err := newTempFile() - require.NoError(t, err) + assert.NilError(t, err) defer tmpFile.Close() isTerminal = IsTerminal(tmpFile.Fd()) - require.Equal(t, isTerminal, false) + assert.Equal(t, isTerminal, false) } func TestSaveState(t *testing.T) { tty, err := newTtyForTest(t) defer tty.Close() - require.NoError(t, err) + assert.NilError(t, err) state, err := SaveState(tty.Fd()) - require.NoError(t, err) - require.NotNil(t, state) + assert.NilError(t, err) + assert.Assert(t, state != nil) tty, err = newTtyForTest(t) - require.NoError(t, err) + assert.NilError(t, err) defer tty.Close() err = RestoreTerminal(tty.Fd(), state) - require.NoError(t, err) + assert.NilError(t, err) } func TestDisableEcho(t *testing.T) { tty, err := newTtyForTest(t) defer tty.Close() - require.NoError(t, err) + assert.NilError(t, err) state, err := SetRawTerminal(tty.Fd()) defer RestoreTerminal(tty.Fd(), state) - require.NoError(t, err) - require.NotNil(t, state) + assert.NilError(t, err) + assert.Assert(t, state != nil) err = DisableEcho(tty.Fd(), state) - require.NoError(t, err) + assert.NilError(t, err) } diff --git a/components/engine/reference/store_test.go b/components/engine/reference/store_test.go index e423f5db2e..24c0597a3e 100644 --- a/components/engine/reference/store_test.go +++ b/components/engine/reference/store_test.go @@ -9,9 +9,9 @@ import ( "testing" "github.com/docker/distribution/reference" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" digest "github.com/opencontainers/go-digest" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" ) var ( @@ -64,10 +64,10 @@ func TestLoad(t *testing.T) { func TestSave(t *testing.T) { jsonFile, err := ioutil.TempFile("", "tag-store-test") - require.NoError(t, err) + assert.NilError(t, err) _, err = jsonFile.Write([]byte(`{}`)) - require.NoError(t, err) + assert.NilError(t, err) jsonFile.Close() defer os.RemoveAll(jsonFile.Name()) @@ -328,23 +328,23 @@ func TestAddDeleteGet(t *testing.T) { func TestInvalidTags(t *testing.T) { tmpDir, err := ioutil.TempDir("", "tag-store-test") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(tmpDir) store, err := NewReferenceStore(filepath.Join(tmpDir, "repositories.json")) - require.NoError(t, err) + assert.NilError(t, err) id := digest.Digest("sha256:470022b8af682154f57a2163d030eb369549549cba00edc69e1b99b46bb924d6") // sha256 as repo name ref, err := reference.ParseNormalizedNamed("sha256:abc") - require.NoError(t, err) + assert.NilError(t, err) err = store.AddTag(ref, id, true) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) // setting digest as a tag ref, err = reference.ParseNormalizedNamed("registry@sha256:367eb40fd0330a7e464777121e39d2f5b3e8e23a1e159342e53ab05c9e4d94e6") - require.NoError(t, err) + assert.NilError(t, err) err = store.AddTag(ref, id, true) - assert.Error(t, err) + assert.Check(t, is.ErrorContains(err, "")) } diff --git a/components/engine/registry/config_test.go b/components/engine/registry/config_test.go index 61b1c26d35..4df9cdb948 100644 --- a/components/engine/registry/config_test.go +++ b/components/engine/registry/config_test.go @@ -6,7 +6,8 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestLoadAllowNondistributableArtifacts(t *testing.T) { @@ -311,9 +312,9 @@ func TestNewServiceConfig(t *testing.T) { for _, testCase := range testCases { _, err := newServiceConfig(testCase.opts) if testCase.errStr != "" { - assert.EqualError(t, err, testCase.errStr) + assert.Check(t, is.Error(err, testCase.errStr)) } else { - assert.Nil(t, err) + assert.Check(t, err) } } } @@ -347,8 +348,8 @@ func TestValidateIndexName(t *testing.T) { for _, testCase := range valid { result, err := ValidateIndexName(testCase.index) - if assert.NoError(t, err) { - assert.Equal(t, testCase.expect, result) + if assert.Check(t, err) { + assert.Check(t, is.Equal(testCase.expect, result)) } } @@ -375,6 +376,6 @@ func TestValidateIndexNameWithError(t *testing.T) { } for _, testCase := range invalid { _, err := ValidateIndexName(testCase.index) - assert.EqualError(t, err, testCase.err) + assert.Check(t, is.Error(err, testCase.err)) } } diff --git a/components/engine/registry/registry_test.go b/components/engine/registry/registry_test.go index 6375301469..b4420d558c 100644 --- a/components/engine/registry/registry_test.go +++ b/components/engine/registry/registry_test.go @@ -12,7 +12,7 @@ import ( "github.com/docker/distribution/registry/client/transport" "github.com/docker/docker/api/types" registrytypes "github.com/docker/docker/api/types/registry" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" ) var ( @@ -757,12 +757,12 @@ func TestSearchRepositories(t *testing.T) { func TestTrustedLocation(t *testing.T) { for _, url := range []string{"http://example.com", "https://example.com:7777", "http://docker.io", "http://test.docker.com", "https://fakedocker.com"} { req, _ := http.NewRequest("GET", url, nil) - assert.False(t, trustedLocation(req)) + assert.Check(t, !trustedLocation(req)) } for _, url := range []string{"https://docker.io", "https://test.docker.com:80"} { req, _ := http.NewRequest("GET", url, nil) - assert.True(t, trustedLocation(req)) + assert.Check(t, trustedLocation(req)) } } diff --git a/components/engine/registry/resumable/resumablerequestreader_test.go b/components/engine/registry/resumable/resumablerequestreader_test.go index 9a08e3416e..bd3d55885f 100644 --- a/components/engine/registry/resumable/resumablerequestreader_test.go +++ b/components/engine/registry/resumable/resumablerequestreader_test.go @@ -10,8 +10,8 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestResumableRequestHeaderSimpleErrors(t *testing.T) { @@ -24,11 +24,11 @@ func TestResumableRequestHeaderSimpleErrors(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", ts.URL, nil) - require.NoError(t, err) + assert.NilError(t, err) resreq := &requestReader{} _, err = resreq.Read([]byte{}) - assert.EqualError(t, err, "client and request can't be nil") + assert.Check(t, is.Error(err, "client and request can't be nil")) resreq = &requestReader{ client: client, @@ -36,7 +36,7 @@ func TestResumableRequestHeaderSimpleErrors(t *testing.T) { totalSize: -1, } _, err = resreq.Read([]byte{}) - assert.EqualError(t, err, "failed to auto detect content length") + assert.Check(t, is.Error(err, "failed to auto detect content length")) } // Not too much failures, bails out after some wait @@ -45,7 +45,7 @@ func TestResumableRequestHeaderNotTooMuchFailures(t *testing.T) { var badReq *http.Request badReq, err := http.NewRequest("GET", "I'm not an url", nil) - require.NoError(t, err) + assert.NilError(t, err) resreq := &requestReader{ client: client, @@ -55,8 +55,8 @@ func TestResumableRequestHeaderNotTooMuchFailures(t *testing.T) { waitDuration: 10 * time.Millisecond, } read, err := resreq.Read([]byte{}) - require.NoError(t, err) - assert.Equal(t, 0, read) + assert.NilError(t, err) + assert.Check(t, is.Equal(0, read)) } // Too much failures, returns the error @@ -65,7 +65,7 @@ func TestResumableRequestHeaderTooMuchFailures(t *testing.T) { var badReq *http.Request badReq, err := http.NewRequest("GET", "I'm not an url", nil) - require.NoError(t, err) + assert.NilError(t, err) resreq := &requestReader{ client: client, @@ -77,8 +77,8 @@ func TestResumableRequestHeaderTooMuchFailures(t *testing.T) { expectedError := `Get I%27m%20not%20an%20url: unsupported protocol scheme ""` read, err := resreq.Read([]byte{}) - assert.EqualError(t, err, expectedError) - assert.Equal(t, 0, read) + assert.Check(t, is.Error(err, expectedError)) + assert.Check(t, is.Equal(0, read)) } type errorReaderCloser struct{} @@ -93,7 +93,7 @@ func (errorReaderCloser) Read(p []byte) (n int, err error) { func TestResumableRequestReaderWithReadError(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", "", nil) - require.NoError(t, err) + assert.NilError(t, err) client := &http.Client{} @@ -116,15 +116,15 @@ func TestResumableRequestReaderWithReadError(t *testing.T) { buf := make([]byte, 1) read, err := resreq.Read(buf) - require.NoError(t, err) + assert.NilError(t, err) - assert.Equal(t, 0, read) + assert.Check(t, is.Equal(0, read)) } func TestResumableRequestReaderWithEOFWith416Response(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", "", nil) - require.NoError(t, err) + assert.NilError(t, err) client := &http.Client{} @@ -147,7 +147,7 @@ func TestResumableRequestReaderWithEOFWith416Response(t *testing.T) { buf := make([]byte, 1) _, err = resreq.Read(buf) - assert.EqualError(t, err, io.EOF.Error()) + assert.Check(t, is.Error(err, io.EOF.Error())) } func TestResumableRequestReaderWithServerDoesntSupportByteRanges(t *testing.T) { @@ -160,7 +160,7 @@ func TestResumableRequestReaderWithServerDoesntSupportByteRanges(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", ts.URL, nil) - require.NoError(t, err) + assert.NilError(t, err) client := &http.Client{} @@ -173,7 +173,7 @@ func TestResumableRequestReaderWithServerDoesntSupportByteRanges(t *testing.T) { buf := make([]byte, 2) _, err = resreq.Read(buf) - assert.EqualError(t, err, "the server doesn't support byte ranges") + assert.Check(t, is.Error(err, "the server doesn't support byte ranges")) } func TestResumableRequestReaderWithZeroTotalSize(t *testing.T) { @@ -186,7 +186,7 @@ func TestResumableRequestReaderWithZeroTotalSize(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", ts.URL, nil) - require.NoError(t, err) + assert.NilError(t, err) client := &http.Client{} retries := uint32(5) @@ -195,10 +195,10 @@ func TestResumableRequestReaderWithZeroTotalSize(t *testing.T) { defer resreq.Close() data, err := ioutil.ReadAll(resreq) - require.NoError(t, err) + assert.NilError(t, err) resstr := strings.TrimSuffix(string(data), "\n") - assert.Equal(t, srvtxt, resstr) + assert.Check(t, is.Equal(srvtxt, resstr)) } func TestResumableRequestReader(t *testing.T) { @@ -211,7 +211,7 @@ func TestResumableRequestReader(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", ts.URL, nil) - require.NoError(t, err) + assert.NilError(t, err) client := &http.Client{} retries := uint32(5) @@ -221,10 +221,10 @@ func TestResumableRequestReader(t *testing.T) { defer resreq.Close() data, err := ioutil.ReadAll(resreq) - require.NoError(t, err) + assert.NilError(t, err) resstr := strings.TrimSuffix(string(data), "\n") - assert.Equal(t, srvtxt, resstr) + assert.Check(t, is.Equal(srvtxt, resstr)) } func TestResumableRequestReaderWithInitialResponse(t *testing.T) { @@ -237,21 +237,21 @@ func TestResumableRequestReaderWithInitialResponse(t *testing.T) { var req *http.Request req, err := http.NewRequest("GET", ts.URL, nil) - require.NoError(t, err) + assert.NilError(t, err) client := &http.Client{} retries := uint32(5) imgSize := int64(len(srvtxt)) res, err := client.Do(req) - require.NoError(t, err) + assert.NilError(t, err) resreq := NewRequestReaderWithInitialResponse(client, req, retries, imgSize, res) defer resreq.Close() data, err := ioutil.ReadAll(resreq) - require.NoError(t, err) + assert.NilError(t, err) resstr := strings.TrimSuffix(string(data), "\n") - assert.Equal(t, srvtxt, resstr) + assert.Check(t, is.Equal(srvtxt, resstr)) } diff --git a/components/engine/runconfig/config_test.go b/components/engine/runconfig/config_test.go index 63619fe53f..58e3a9f788 100644 --- a/components/engine/runconfig/config_test.go +++ b/components/engine/runconfig/config_test.go @@ -12,8 +12,8 @@ import ( "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/strslice" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) type f struct { @@ -149,21 +149,21 @@ func runDecodeContainerConfigTestCase(testcase decodeConfigTestcase) func(t *tes raw := marshal(t, testcase.wrapper, testcase.doc) config, hostConfig, _, err := decodeContainerConfig(bytes.NewReader(raw)) if testcase.expectedErr != "" { - if !assert.Error(t, err) { + if !assert.Check(t, is.ErrorContains(err, "")) { return } - assert.Contains(t, err.Error(), testcase.expectedErr) + assert.Check(t, is.Contains(err.Error(), testcase.expectedErr)) return } - assert.NoError(t, err) - assert.Equal(t, testcase.expectedConfig, config) - assert.Equal(t, testcase.expectedHostConfig, hostConfig) + assert.Check(t, err) + assert.Check(t, is.DeepEqual(testcase.expectedConfig, config)) + assert.Check(t, is.DeepEqual(testcase.expectedHostConfig, hostConfig)) } } func marshal(t *testing.T, w ContainerConfigWrapper, doc string) []byte { b, err := json.Marshal(w) - require.NoError(t, err, "%s: failed to encode config wrapper", doc) + assert.NilError(t, err, "%s: failed to encode config wrapper", doc) return b } diff --git a/components/engine/runconfig/hostconfig_test.go b/components/engine/runconfig/hostconfig_test.go index 48d902d4d7..d2482fbe7b 100644 --- a/components/engine/runconfig/hostconfig_test.go +++ b/components/engine/runconfig/hostconfig_test.go @@ -10,7 +10,8 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/sysinfo" - "github.com/stretchr/testify/assert" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) // TODO Windows: This will need addressing for a Windows daemon. @@ -83,12 +84,12 @@ func TestIpcModeTest(t *testing.T) { } for ipcMode, state := range ipcModes { - assert.Equal(t, state.private, ipcMode.IsPrivate(), "IpcMode.IsPrivate() parsing failed for %q", ipcMode) - assert.Equal(t, state.host, ipcMode.IsHost(), "IpcMode.IsHost() parsing failed for %q", ipcMode) - assert.Equal(t, state.container, ipcMode.IsContainer(), "IpcMode.IsContainer() parsing failed for %q", ipcMode) - assert.Equal(t, state.shareable, ipcMode.IsShareable(), "IpcMode.IsShareable() parsing failed for %q", ipcMode) - assert.Equal(t, state.valid, ipcMode.Valid(), "IpcMode.Valid() parsing failed for %q", ipcMode) - assert.Equal(t, state.ctrName, ipcMode.Container(), "IpcMode.Container() parsing failed for %q", ipcMode) + assert.Check(t, is.Equal(state.private, ipcMode.IsPrivate()), "IpcMode.IsPrivate() parsing failed for %q", ipcMode) + assert.Check(t, is.Equal(state.host, ipcMode.IsHost()), "IpcMode.IsHost() parsing failed for %q", ipcMode) + assert.Check(t, is.Equal(state.container, ipcMode.IsContainer()), "IpcMode.IsContainer() parsing failed for %q", ipcMode) + assert.Check(t, is.Equal(state.shareable, ipcMode.IsShareable()), "IpcMode.IsShareable() parsing failed for %q", ipcMode) + assert.Check(t, is.Equal(state.valid, ipcMode.Valid()), "IpcMode.Valid() parsing failed for %q", ipcMode) + assert.Check(t, is.Equal(state.ctrName, ipcMode.Container()), "IpcMode.Container() parsing failed for %q", ipcMode) } } @@ -195,7 +196,7 @@ func TestDecodeHostConfig(t *testing.T) { t.Fatal(fmt.Errorf("Error parsing %s: %v", f, err)) } - assert.False(t, c.Privileged) + assert.Check(t, !c.Privileged) if l := len(c.Binds); l != 1 { t.Fatalf("Expected 1 bind, found %d\n", l) diff --git a/components/engine/vendor.conf b/components/engine/vendor.conf index 42003972e0..faf4f9c043 100644 --- a/components/engine/vendor.conf +++ b/components/engine/vendor.conf @@ -2,7 +2,6 @@ github.com/Azure/go-ansiterm d6e3b3328b783f23731bc4d058875b0371ff8109 github.com/Microsoft/hcsshim v0.6.8 github.com/Microsoft/go-winio v0.4.6 -github.com/davecgh/go-spew 346938d642f2ec3594ed81d874461961cd0faa76 github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git github.com/golang/gddo 9b12a26f3fbd7397dee4e20939ddca719d840d2a @@ -19,10 +18,9 @@ golang.org/x/sys 37707fdb30a5b38865cfb95e5aab41707daec7fd github.com/docker/go-units 9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1 github.com/docker/go-connections 7beb39f0b969b075d1325fecb092faf27fd357b6 golang.org/x/text f72d8390a633d5dfb0cc84043294db9f6c935756 -github.com/stretchr/testify 4d4bfba8f1d1027c4fdbe371823030df51419987 github.com/pmezard/go-difflib v1.0.0 -github.com/gotestyourself/gotestyourself 511344eed30e4384f010579a593dfb442033a692 -github.com/google/go-cmp v0.1.0 +github.com/gotestyourself/gotestyourself cf3a5ab914a2efa8bc838d09f5918c1d44d029 +github.com/google/go-cmp v0.2.0 github.com/RackSec/srslog 456df3a81436d29ba874f3590eeeee25d666f8a5 github.com/imdario/mergo 0.2.1 diff --git a/components/engine/vendor/github.com/davecgh/go-spew/LICENSE b/components/engine/vendor/github.com/davecgh/go-spew/LICENSE deleted file mode 100644 index c836416192..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/LICENSE +++ /dev/null @@ -1,15 +0,0 @@ -ISC License - -Copyright (c) 2012-2016 Dave Collins - -Permission to use, copy, modify, and distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/components/engine/vendor/github.com/davecgh/go-spew/README.md b/components/engine/vendor/github.com/davecgh/go-spew/README.md deleted file mode 100644 index 262430449b..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/README.md +++ /dev/null @@ -1,205 +0,0 @@ -go-spew -======= - -[![Build Status](https://img.shields.io/travis/davecgh/go-spew.svg)] -(https://travis-ci.org/davecgh/go-spew) [![ISC License] -(http://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org) [![Coverage Status] -(https://img.shields.io/coveralls/davecgh/go-spew.svg)] -(https://coveralls.io/r/davecgh/go-spew?branch=master) - - -Go-spew implements a deep pretty printer for Go data structures to aid in -debugging. A comprehensive suite of tests with 100% test coverage is provided -to ensure proper functionality. See `test_coverage.txt` for the gocov coverage -report. Go-spew is licensed under the liberal ISC license, so it may be used in -open source or commercial projects. - -If you're interested in reading about how this package came to life and some -of the challenges involved in providing a deep pretty printer, there is a blog -post about it -[here](https://web.archive.org/web/20160304013555/https://blog.cyphertite.com/go-spew-a-journey-into-dumping-go-data-structures/). - -## Documentation - -[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg)] -(http://godoc.org/github.com/davecgh/go-spew/spew) - -Full `go doc` style documentation for the project can be viewed online without -installing this package by using the excellent GoDoc site here: -http://godoc.org/github.com/davecgh/go-spew/spew - -You can also view the documentation locally once the package is installed with -the `godoc` tool by running `godoc -http=":6060"` and pointing your browser to -http://localhost:6060/pkg/github.com/davecgh/go-spew/spew - -## Installation - -```bash -$ go get -u github.com/davecgh/go-spew/spew -``` - -## Quick Start - -Add this import line to the file you're working in: - -```Go -import "github.com/davecgh/go-spew/spew" -``` - -To dump a variable with full newlines, indentation, type, and pointer -information use Dump, Fdump, or Sdump: - -```Go -spew.Dump(myVar1, myVar2, ...) -spew.Fdump(someWriter, myVar1, myVar2, ...) -str := spew.Sdump(myVar1, myVar2, ...) -``` - -Alternatively, if you would prefer to use format strings with a compacted inline -printing style, use the convenience wrappers Printf, Fprintf, etc with %v (most -compact), %+v (adds pointer addresses), %#v (adds types), or %#+v (adds types -and pointer addresses): - -```Go -spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) -spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) -spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) -spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) -``` - -## Debugging a Web Application Example - -Here is an example of how you can use `spew.Sdump()` to help debug a web application. Please be sure to wrap your output using the `html.EscapeString()` function for safety reasons. You should also only use this debugging technique in a development environment, never in production. - -```Go -package main - -import ( - "fmt" - "html" - "net/http" - - "github.com/davecgh/go-spew/spew" -) - -func handler(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/html") - fmt.Fprintf(w, "Hi there, %s!", r.URL.Path[1:]) - fmt.Fprintf(w, "") -} - -func main() { - http.HandleFunc("/", handler) - http.ListenAndServe(":8080", nil) -} -``` - -## Sample Dump Output - -``` -(main.Foo) { - unexportedField: (*main.Bar)(0xf84002e210)({ - flag: (main.Flag) flagTwo, - data: (uintptr) - }), - ExportedField: (map[interface {}]interface {}) { - (string) "one": (bool) true - } -} -([]uint8) { - 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | - 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| - 00000020 31 32 |12| -} -``` - -## Sample Formatter Output - -Double pointer to a uint8: -``` - %v: <**>5 - %+v: <**>(0xf8400420d0->0xf8400420c8)5 - %#v: (**uint8)5 - %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5 -``` - -Pointer to circular struct with a uint8 field and a pointer to itself: -``` - %v: <*>{1 <*>} - %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)} - %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)} - %#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)} -``` - -## Configuration Options - -Configuration of spew is handled by fields in the ConfigState type. For -convenience, all of the top-level functions use a global state available via the -spew.Config global. - -It is also possible to create a ConfigState instance that provides methods -equivalent to the top-level functions. This allows concurrent configuration -options. See the ConfigState documentation for more details. - -``` -* Indent - String to use for each indentation level for Dump functions. - It is a single space by default. A popular alternative is "\t". - -* MaxDepth - Maximum number of levels to descend into nested data structures. - There is no limit by default. - -* DisableMethods - Disables invocation of error and Stringer interface methods. - Method invocation is enabled by default. - -* DisablePointerMethods - Disables invocation of error and Stringer interface methods on types - which only accept pointer receivers from non-pointer variables. This option - relies on access to the unsafe package, so it will not have any effect when - running in environments without access to the unsafe package such as Google - App Engine or with the "safe" build tag specified. - Pointer method invocation is enabled by default. - -* DisablePointerAddresses - DisablePointerAddresses specifies whether to disable the printing of - pointer addresses. This is useful when diffing data structures in tests. - -* DisableCapacities - DisableCapacities specifies whether to disable the printing of capacities - for arrays, slices, maps and channels. This is useful when diffing data - structures in tests. - -* ContinueOnMethod - Enables recursion into types after invoking error and Stringer interface - methods. Recursion after method invocation is disabled by default. - -* SortKeys - Specifies map keys should be sorted before being printed. Use - this to have a more deterministic, diffable output. Note that - only native types (bool, int, uint, floats, uintptr and string) - and types which implement error or Stringer interfaces are supported, - with other types sorted according to the reflect.Value.String() output - which guarantees display stability. Natural map order is used by - default. - -* SpewKeys - SpewKeys specifies that, as a last resort attempt, map keys should be - spewed to strings and sorted by those strings. This is only considered - if SortKeys is true. - -``` - -## Unsafe Package Dependency - -This package relies on the unsafe package to perform some of the more advanced -features, however it also supports a "limited" mode which allows it to work in -environments where the unsafe package is not available. By default, it will -operate in this mode on Google App Engine and when compiled with GopherJS. The -"safe" build tag may also be specified to force the package to build without -using the unsafe package. - -## License - -Go-spew is licensed under the [copyfree](http://copyfree.org) ISC License. diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/bypass.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/bypass.go deleted file mode 100644 index 8a4a6589a2..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/bypass.go +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) 2015-2016 Dave Collins -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// NOTE: Due to the following build constraints, this file will only be compiled -// when the code is not running on Google App Engine, compiled by GopherJS, and -// "-tags safe" is not added to the go build command line. The "disableunsafe" -// tag is deprecated and thus should not be used. -// +build !js,!appengine,!safe,!disableunsafe - -package spew - -import ( - "reflect" - "unsafe" -) - -const ( - // UnsafeDisabled is a build-time constant which specifies whether or - // not access to the unsafe package is available. - UnsafeDisabled = false - - // ptrSize is the size of a pointer on the current arch. - ptrSize = unsafe.Sizeof((*byte)(nil)) -) - -var ( - // offsetPtr, offsetScalar, and offsetFlag are the offsets for the - // internal reflect.Value fields. These values are valid before golang - // commit ecccf07e7f9d which changed the format. The are also valid - // after commit 82f48826c6c7 which changed the format again to mirror - // the original format. Code in the init function updates these offsets - // as necessary. - offsetPtr = uintptr(ptrSize) - offsetScalar = uintptr(0) - offsetFlag = uintptr(ptrSize * 2) - - // flagKindWidth and flagKindShift indicate various bits that the - // reflect package uses internally to track kind information. - // - // flagRO indicates whether or not the value field of a reflect.Value is - // read-only. - // - // flagIndir indicates whether the value field of a reflect.Value is - // the actual data or a pointer to the data. - // - // These values are valid before golang commit 90a7c3c86944 which - // changed their positions. Code in the init function updates these - // flags as necessary. - flagKindWidth = uintptr(5) - flagKindShift = uintptr(flagKindWidth - 1) - flagRO = uintptr(1 << 0) - flagIndir = uintptr(1 << 1) -) - -func init() { - // Older versions of reflect.Value stored small integers directly in the - // ptr field (which is named val in the older versions). Versions - // between commits ecccf07e7f9d and 82f48826c6c7 added a new field named - // scalar for this purpose which unfortunately came before the flag - // field, so the offset of the flag field is different for those - // versions. - // - // This code constructs a new reflect.Value from a known small integer - // and checks if the size of the reflect.Value struct indicates it has - // the scalar field. When it does, the offsets are updated accordingly. - vv := reflect.ValueOf(0xf00) - if unsafe.Sizeof(vv) == (ptrSize * 4) { - offsetScalar = ptrSize * 2 - offsetFlag = ptrSize * 3 - } - - // Commit 90a7c3c86944 changed the flag positions such that the low - // order bits are the kind. This code extracts the kind from the flags - // field and ensures it's the correct type. When it's not, the flag - // order has been changed to the newer format, so the flags are updated - // accordingly. - upf := unsafe.Pointer(uintptr(unsafe.Pointer(&vv)) + offsetFlag) - upfv := *(*uintptr)(upf) - flagKindMask := uintptr((1<>flagKindShift != uintptr(reflect.Int) { - flagKindShift = 0 - flagRO = 1 << 5 - flagIndir = 1 << 6 - - // Commit adf9b30e5594 modified the flags to separate the - // flagRO flag into two bits which specifies whether or not the - // field is embedded. This causes flagIndir to move over a bit - // and means that flagRO is the combination of either of the - // original flagRO bit and the new bit. - // - // This code detects the change by extracting what used to be - // the indirect bit to ensure it's set. When it's not, the flag - // order has been changed to the newer format, so the flags are - // updated accordingly. - if upfv&flagIndir == 0 { - flagRO = 3 << 5 - flagIndir = 1 << 7 - } - } -} - -// unsafeReflectValue converts the passed reflect.Value into a one that bypasses -// the typical safety restrictions preventing access to unaddressable and -// unexported data. It works by digging the raw pointer to the underlying -// value out of the protected value and generating a new unprotected (unsafe) -// reflect.Value to it. -// -// This allows us to check for implementations of the Stringer and error -// interfaces to be used for pretty printing ordinarily unaddressable and -// inaccessible values such as unexported struct fields. -func unsafeReflectValue(v reflect.Value) (rv reflect.Value) { - indirects := 1 - vt := v.Type() - upv := unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetPtr) - rvf := *(*uintptr)(unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + offsetFlag)) - if rvf&flagIndir != 0 { - vt = reflect.PtrTo(v.Type()) - indirects++ - } else if offsetScalar != 0 { - // The value is in the scalar field when it's not one of the - // reference types. - switch vt.Kind() { - case reflect.Uintptr: - case reflect.Chan: - case reflect.Func: - case reflect.Map: - case reflect.Ptr: - case reflect.UnsafePointer: - default: - upv = unsafe.Pointer(uintptr(unsafe.Pointer(&v)) + - offsetScalar) - } - } - - pv := reflect.NewAt(vt, upv) - rv = pv - for i := 0; i < indirects; i++ { - rv = rv.Elem() - } - return rv -} diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go deleted file mode 100644 index 1fe3cf3d5d..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/bypasssafe.go +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2015-2016 Dave Collins -// -// Permission to use, copy, modify, and distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - -// NOTE: Due to the following build constraints, this file will only be compiled -// when the code is running on Google App Engine, compiled by GopherJS, or -// "-tags safe" is added to the go build command line. The "disableunsafe" -// tag is deprecated and thus should not be used. -// +build js appengine safe disableunsafe - -package spew - -import "reflect" - -const ( - // UnsafeDisabled is a build-time constant which specifies whether or - // not access to the unsafe package is available. - UnsafeDisabled = true -) - -// unsafeReflectValue typically converts the passed reflect.Value into a one -// that bypasses the typical safety restrictions preventing access to -// unaddressable and unexported data. However, doing this relies on access to -// the unsafe package. This is a stub version which simply returns the passed -// reflect.Value when the unsafe package is not available. -func unsafeReflectValue(v reflect.Value) reflect.Value { - return v -} diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/common.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/common.go deleted file mode 100644 index 7c519ff47a..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/common.go +++ /dev/null @@ -1,341 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "fmt" - "io" - "reflect" - "sort" - "strconv" -) - -// Some constants in the form of bytes to avoid string overhead. This mirrors -// the technique used in the fmt package. -var ( - panicBytes = []byte("(PANIC=") - plusBytes = []byte("+") - iBytes = []byte("i") - trueBytes = []byte("true") - falseBytes = []byte("false") - interfaceBytes = []byte("(interface {})") - commaNewlineBytes = []byte(",\n") - newlineBytes = []byte("\n") - openBraceBytes = []byte("{") - openBraceNewlineBytes = []byte("{\n") - closeBraceBytes = []byte("}") - asteriskBytes = []byte("*") - colonBytes = []byte(":") - colonSpaceBytes = []byte(": ") - openParenBytes = []byte("(") - closeParenBytes = []byte(")") - spaceBytes = []byte(" ") - pointerChainBytes = []byte("->") - nilAngleBytes = []byte("") - maxNewlineBytes = []byte("\n") - maxShortBytes = []byte("") - circularBytes = []byte("") - circularShortBytes = []byte("") - invalidAngleBytes = []byte("") - openBracketBytes = []byte("[") - closeBracketBytes = []byte("]") - percentBytes = []byte("%") - precisionBytes = []byte(".") - openAngleBytes = []byte("<") - closeAngleBytes = []byte(">") - openMapBytes = []byte("map[") - closeMapBytes = []byte("]") - lenEqualsBytes = []byte("len=") - capEqualsBytes = []byte("cap=") -) - -// hexDigits is used to map a decimal value to a hex digit. -var hexDigits = "0123456789abcdef" - -// catchPanic handles any panics that might occur during the handleMethods -// calls. -func catchPanic(w io.Writer, v reflect.Value) { - if err := recover(); err != nil { - w.Write(panicBytes) - fmt.Fprintf(w, "%v", err) - w.Write(closeParenBytes) - } -} - -// handleMethods attempts to call the Error and String methods on the underlying -// type the passed reflect.Value represents and outputes the result to Writer w. -// -// It handles panics in any called methods by catching and displaying the error -// as the formatted value. -func handleMethods(cs *ConfigState, w io.Writer, v reflect.Value) (handled bool) { - // We need an interface to check if the type implements the error or - // Stringer interface. However, the reflect package won't give us an - // interface on certain things like unexported struct fields in order - // to enforce visibility rules. We use unsafe, when it's available, - // to bypass these restrictions since this package does not mutate the - // values. - if !v.CanInterface() { - if UnsafeDisabled { - return false - } - - v = unsafeReflectValue(v) - } - - // Choose whether or not to do error and Stringer interface lookups against - // the base type or a pointer to the base type depending on settings. - // Technically calling one of these methods with a pointer receiver can - // mutate the value, however, types which choose to satisify an error or - // Stringer interface with a pointer receiver should not be mutating their - // state inside these interface methods. - if !cs.DisablePointerMethods && !UnsafeDisabled && !v.CanAddr() { - v = unsafeReflectValue(v) - } - if v.CanAddr() { - v = v.Addr() - } - - // Is it an error or Stringer? - switch iface := v.Interface().(type) { - case error: - defer catchPanic(w, v) - if cs.ContinueOnMethod { - w.Write(openParenBytes) - w.Write([]byte(iface.Error())) - w.Write(closeParenBytes) - w.Write(spaceBytes) - return false - } - - w.Write([]byte(iface.Error())) - return true - - case fmt.Stringer: - defer catchPanic(w, v) - if cs.ContinueOnMethod { - w.Write(openParenBytes) - w.Write([]byte(iface.String())) - w.Write(closeParenBytes) - w.Write(spaceBytes) - return false - } - w.Write([]byte(iface.String())) - return true - } - return false -} - -// printBool outputs a boolean value as true or false to Writer w. -func printBool(w io.Writer, val bool) { - if val { - w.Write(trueBytes) - } else { - w.Write(falseBytes) - } -} - -// printInt outputs a signed integer value to Writer w. -func printInt(w io.Writer, val int64, base int) { - w.Write([]byte(strconv.FormatInt(val, base))) -} - -// printUint outputs an unsigned integer value to Writer w. -func printUint(w io.Writer, val uint64, base int) { - w.Write([]byte(strconv.FormatUint(val, base))) -} - -// printFloat outputs a floating point value using the specified precision, -// which is expected to be 32 or 64bit, to Writer w. -func printFloat(w io.Writer, val float64, precision int) { - w.Write([]byte(strconv.FormatFloat(val, 'g', -1, precision))) -} - -// printComplex outputs a complex value using the specified float precision -// for the real and imaginary parts to Writer w. -func printComplex(w io.Writer, c complex128, floatPrecision int) { - r := real(c) - w.Write(openParenBytes) - w.Write([]byte(strconv.FormatFloat(r, 'g', -1, floatPrecision))) - i := imag(c) - if i >= 0 { - w.Write(plusBytes) - } - w.Write([]byte(strconv.FormatFloat(i, 'g', -1, floatPrecision))) - w.Write(iBytes) - w.Write(closeParenBytes) -} - -// printHexPtr outputs a uintptr formatted as hexidecimal with a leading '0x' -// prefix to Writer w. -func printHexPtr(w io.Writer, p uintptr) { - // Null pointer. - num := uint64(p) - if num == 0 { - w.Write(nilAngleBytes) - return - } - - // Max uint64 is 16 bytes in hex + 2 bytes for '0x' prefix - buf := make([]byte, 18) - - // It's simpler to construct the hex string right to left. - base := uint64(16) - i := len(buf) - 1 - for num >= base { - buf[i] = hexDigits[num%base] - num /= base - i-- - } - buf[i] = hexDigits[num] - - // Add '0x' prefix. - i-- - buf[i] = 'x' - i-- - buf[i] = '0' - - // Strip unused leading bytes. - buf = buf[i:] - w.Write(buf) -} - -// valuesSorter implements sort.Interface to allow a slice of reflect.Value -// elements to be sorted. -type valuesSorter struct { - values []reflect.Value - strings []string // either nil or same len and values - cs *ConfigState -} - -// newValuesSorter initializes a valuesSorter instance, which holds a set of -// surrogate keys on which the data should be sorted. It uses flags in -// ConfigState to decide if and how to populate those surrogate keys. -func newValuesSorter(values []reflect.Value, cs *ConfigState) sort.Interface { - vs := &valuesSorter{values: values, cs: cs} - if canSortSimply(vs.values[0].Kind()) { - return vs - } - if !cs.DisableMethods { - vs.strings = make([]string, len(values)) - for i := range vs.values { - b := bytes.Buffer{} - if !handleMethods(cs, &b, vs.values[i]) { - vs.strings = nil - break - } - vs.strings[i] = b.String() - } - } - if vs.strings == nil && cs.SpewKeys { - vs.strings = make([]string, len(values)) - for i := range vs.values { - vs.strings[i] = Sprintf("%#v", vs.values[i].Interface()) - } - } - return vs -} - -// canSortSimply tests whether a reflect.Kind is a primitive that can be sorted -// directly, or whether it should be considered for sorting by surrogate keys -// (if the ConfigState allows it). -func canSortSimply(kind reflect.Kind) bool { - // This switch parallels valueSortLess, except for the default case. - switch kind { - case reflect.Bool: - return true - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - return true - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - return true - case reflect.Float32, reflect.Float64: - return true - case reflect.String: - return true - case reflect.Uintptr: - return true - case reflect.Array: - return true - } - return false -} - -// Len returns the number of values in the slice. It is part of the -// sort.Interface implementation. -func (s *valuesSorter) Len() int { - return len(s.values) -} - -// Swap swaps the values at the passed indices. It is part of the -// sort.Interface implementation. -func (s *valuesSorter) Swap(i, j int) { - s.values[i], s.values[j] = s.values[j], s.values[i] - if s.strings != nil { - s.strings[i], s.strings[j] = s.strings[j], s.strings[i] - } -} - -// valueSortLess returns whether the first value should sort before the second -// value. It is used by valueSorter.Less as part of the sort.Interface -// implementation. -func valueSortLess(a, b reflect.Value) bool { - switch a.Kind() { - case reflect.Bool: - return !a.Bool() && b.Bool() - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - return a.Int() < b.Int() - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - return a.Uint() < b.Uint() - case reflect.Float32, reflect.Float64: - return a.Float() < b.Float() - case reflect.String: - return a.String() < b.String() - case reflect.Uintptr: - return a.Uint() < b.Uint() - case reflect.Array: - // Compare the contents of both arrays. - l := a.Len() - for i := 0; i < l; i++ { - av := a.Index(i) - bv := b.Index(i) - if av.Interface() == bv.Interface() { - continue - } - return valueSortLess(av, bv) - } - } - return a.String() < b.String() -} - -// Less returns whether the value at index i should sort before the -// value at index j. It is part of the sort.Interface implementation. -func (s *valuesSorter) Less(i, j int) bool { - if s.strings == nil { - return valueSortLess(s.values[i], s.values[j]) - } - return s.strings[i] < s.strings[j] -} - -// sortValues is a sort function that handles both native types and any type that -// can be converted to error or Stringer. Other inputs are sorted according to -// their Value.String() value to ensure display stability. -func sortValues(values []reflect.Value, cs *ConfigState) { - if len(values) == 0 { - return - } - sort.Sort(newValuesSorter(values, cs)) -} diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/config.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/config.go deleted file mode 100644 index 2e3d22f312..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/config.go +++ /dev/null @@ -1,306 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "fmt" - "io" - "os" -) - -// ConfigState houses the configuration options used by spew to format and -// display values. There is a global instance, Config, that is used to control -// all top-level Formatter and Dump functionality. Each ConfigState instance -// provides methods equivalent to the top-level functions. -// -// The zero value for ConfigState provides no indentation. You would typically -// want to set it to a space or a tab. -// -// Alternatively, you can use NewDefaultConfig to get a ConfigState instance -// with default settings. See the documentation of NewDefaultConfig for default -// values. -type ConfigState struct { - // Indent specifies the string to use for each indentation level. The - // global config instance that all top-level functions use set this to a - // single space by default. If you would like more indentation, you might - // set this to a tab with "\t" or perhaps two spaces with " ". - Indent string - - // MaxDepth controls the maximum number of levels to descend into nested - // data structures. The default, 0, means there is no limit. - // - // NOTE: Circular data structures are properly detected, so it is not - // necessary to set this value unless you specifically want to limit deeply - // nested data structures. - MaxDepth int - - // DisableMethods specifies whether or not error and Stringer interfaces are - // invoked for types that implement them. - DisableMethods bool - - // DisablePointerMethods specifies whether or not to check for and invoke - // error and Stringer interfaces on types which only accept a pointer - // receiver when the current type is not a pointer. - // - // NOTE: This might be an unsafe action since calling one of these methods - // with a pointer receiver could technically mutate the value, however, - // in practice, types which choose to satisify an error or Stringer - // interface with a pointer receiver should not be mutating their state - // inside these interface methods. As a result, this option relies on - // access to the unsafe package, so it will not have any effect when - // running in environments without access to the unsafe package such as - // Google App Engine or with the "safe" build tag specified. - DisablePointerMethods bool - - // DisablePointerAddresses specifies whether to disable the printing of - // pointer addresses. This is useful when diffing data structures in tests. - DisablePointerAddresses bool - - // DisableCapacities specifies whether to disable the printing of capacities - // for arrays, slices, maps and channels. This is useful when diffing - // data structures in tests. - DisableCapacities bool - - // ContinueOnMethod specifies whether or not recursion should continue once - // a custom error or Stringer interface is invoked. The default, false, - // means it will print the results of invoking the custom error or Stringer - // interface and return immediately instead of continuing to recurse into - // the internals of the data type. - // - // NOTE: This flag does not have any effect if method invocation is disabled - // via the DisableMethods or DisablePointerMethods options. - ContinueOnMethod bool - - // SortKeys specifies map keys should be sorted before being printed. Use - // this to have a more deterministic, diffable output. Note that only - // native types (bool, int, uint, floats, uintptr and string) and types - // that support the error or Stringer interfaces (if methods are - // enabled) are supported, with other types sorted according to the - // reflect.Value.String() output which guarantees display stability. - SortKeys bool - - // SpewKeys specifies that, as a last resort attempt, map keys should - // be spewed to strings and sorted by those strings. This is only - // considered if SortKeys is true. - SpewKeys bool -} - -// Config is the active configuration of the top-level functions. -// The configuration can be changed by modifying the contents of spew.Config. -var Config = ConfigState{Indent: " "} - -// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the formatted string as a value that satisfies error. See NewFormatter -// for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Errorf(format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Errorf(format string, a ...interface{}) (err error) { - return fmt.Errorf(format, c.convertArgs(a)...) -} - -// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprint(w, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Fprint(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprint(w, c.convertArgs(a)...) -} - -// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintf(w, format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { - return fmt.Fprintf(w, format, c.convertArgs(a)...) -} - -// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it -// passed with a Formatter interface returned by c.NewFormatter. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintln(w, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Fprintln(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprintln(w, c.convertArgs(a)...) -} - -// Print is a wrapper for fmt.Print that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Print(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Print(a ...interface{}) (n int, err error) { - return fmt.Print(c.convertArgs(a)...) -} - -// Printf is a wrapper for fmt.Printf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Printf(format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Printf(format string, a ...interface{}) (n int, err error) { - return fmt.Printf(format, c.convertArgs(a)...) -} - -// Println is a wrapper for fmt.Println that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Println(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Println(a ...interface{}) (n int, err error) { - return fmt.Println(c.convertArgs(a)...) -} - -// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprint(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Sprint(a ...interface{}) string { - return fmt.Sprint(c.convertArgs(a)...) -} - -// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were -// passed with a Formatter interface returned by c.NewFormatter. It returns -// the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintf(format, c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Sprintf(format string, a ...interface{}) string { - return fmt.Sprintf(format, c.convertArgs(a)...) -} - -// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it -// were passed with a Formatter interface returned by c.NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintln(c.NewFormatter(a), c.NewFormatter(b)) -func (c *ConfigState) Sprintln(a ...interface{}) string { - return fmt.Sprintln(c.convertArgs(a)...) -} - -/* -NewFormatter returns a custom formatter that satisfies the fmt.Formatter -interface. As a result, it integrates cleanly with standard fmt package -printing functions. The formatter is useful for inline printing of smaller data -types similar to the standard %v format specifier. - -The custom formatter only responds to the %v (most compact), %+v (adds pointer -addresses), %#v (adds types), and %#+v (adds types and pointer addresses) verb -combinations. Any other verbs such as %x and %q will be sent to the the -standard fmt package for formatting. In addition, the custom formatter ignores -the width and precision arguments (however they will still work on the format -specifiers not handled by the custom formatter). - -Typically this function shouldn't be called directly. It is much easier to make -use of the custom formatter by calling one of the convenience functions such as -c.Printf, c.Println, or c.Printf. -*/ -func (c *ConfigState) NewFormatter(v interface{}) fmt.Formatter { - return newFormatter(c, v) -} - -// Fdump formats and displays the passed arguments to io.Writer w. It formats -// exactly the same as Dump. -func (c *ConfigState) Fdump(w io.Writer, a ...interface{}) { - fdump(c, w, a...) -} - -/* -Dump displays the passed parameters to standard out with newlines, customizable -indentation, and additional debug information such as complete types and all -pointer addresses used to indirect to the final value. It provides the -following features over the built-in printing facilities provided by the fmt -package: - - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output - -The configuration options are controlled by modifying the public members -of c. See ConfigState for options documentation. - -See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to -get the formatted result as a string. -*/ -func (c *ConfigState) Dump(a ...interface{}) { - fdump(c, os.Stdout, a...) -} - -// Sdump returns a string with the passed arguments formatted exactly the same -// as Dump. -func (c *ConfigState) Sdump(a ...interface{}) string { - var buf bytes.Buffer - fdump(c, &buf, a...) - return buf.String() -} - -// convertArgs accepts a slice of arguments and returns a slice of the same -// length with each argument converted to a spew Formatter interface using -// the ConfigState associated with s. -func (c *ConfigState) convertArgs(args []interface{}) (formatters []interface{}) { - formatters = make([]interface{}, len(args)) - for index, arg := range args { - formatters[index] = newFormatter(c, arg) - } - return formatters -} - -// NewDefaultConfig returns a ConfigState with the following default settings. -// -// Indent: " " -// MaxDepth: 0 -// DisableMethods: false -// DisablePointerMethods: false -// ContinueOnMethod: false -// SortKeys: false -func NewDefaultConfig() *ConfigState { - return &ConfigState{Indent: " "} -} diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/doc.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/doc.go deleted file mode 100644 index aacaac6f1e..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/doc.go +++ /dev/null @@ -1,211 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* -Package spew implements a deep pretty printer for Go data structures to aid in -debugging. - -A quick overview of the additional features spew provides over the built-in -printing facilities for Go data types are as follows: - - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output (only when using - Dump style) - -There are two different approaches spew allows for dumping Go data structures: - - * Dump style which prints with newlines, customizable indentation, - and additional debug information such as types and all pointer addresses - used to indirect to the final value - * A custom Formatter interface that integrates cleanly with the standard fmt - package and replaces %v, %+v, %#v, and %#+v to provide inline printing - similar to the default %v while providing the additional functionality - outlined above and passing unsupported format verbs such as %x and %q - along to fmt - -Quick Start - -This section demonstrates how to quickly get started with spew. See the -sections below for further details on formatting and configuration options. - -To dump a variable with full newlines, indentation, type, and pointer -information use Dump, Fdump, or Sdump: - spew.Dump(myVar1, myVar2, ...) - spew.Fdump(someWriter, myVar1, myVar2, ...) - str := spew.Sdump(myVar1, myVar2, ...) - -Alternatively, if you would prefer to use format strings with a compacted inline -printing style, use the convenience wrappers Printf, Fprintf, etc with -%v (most compact), %+v (adds pointer addresses), %#v (adds types), or -%#+v (adds types and pointer addresses): - spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - spew.Fprintf(someWriter, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Fprintf(someWriter, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - -Configuration Options - -Configuration of spew is handled by fields in the ConfigState type. For -convenience, all of the top-level functions use a global state available -via the spew.Config global. - -It is also possible to create a ConfigState instance that provides methods -equivalent to the top-level functions. This allows concurrent configuration -options. See the ConfigState documentation for more details. - -The following configuration options are available: - * Indent - String to use for each indentation level for Dump functions. - It is a single space by default. A popular alternative is "\t". - - * MaxDepth - Maximum number of levels to descend into nested data structures. - There is no limit by default. - - * DisableMethods - Disables invocation of error and Stringer interface methods. - Method invocation is enabled by default. - - * DisablePointerMethods - Disables invocation of error and Stringer interface methods on types - which only accept pointer receivers from non-pointer variables. - Pointer method invocation is enabled by default. - - * DisablePointerAddresses - DisablePointerAddresses specifies whether to disable the printing of - pointer addresses. This is useful when diffing data structures in tests. - - * DisableCapacities - DisableCapacities specifies whether to disable the printing of - capacities for arrays, slices, maps and channels. This is useful when - diffing data structures in tests. - - * ContinueOnMethod - Enables recursion into types after invoking error and Stringer interface - methods. Recursion after method invocation is disabled by default. - - * SortKeys - Specifies map keys should be sorted before being printed. Use - this to have a more deterministic, diffable output. Note that - only native types (bool, int, uint, floats, uintptr and string) - and types which implement error or Stringer interfaces are - supported with other types sorted according to the - reflect.Value.String() output which guarantees display - stability. Natural map order is used by default. - - * SpewKeys - Specifies that, as a last resort attempt, map keys should be - spewed to strings and sorted by those strings. This is only - considered if SortKeys is true. - -Dump Usage - -Simply call spew.Dump with a list of variables you want to dump: - - spew.Dump(myVar1, myVar2, ...) - -You may also call spew.Fdump if you would prefer to output to an arbitrary -io.Writer. For example, to dump to standard error: - - spew.Fdump(os.Stderr, myVar1, myVar2, ...) - -A third option is to call spew.Sdump to get the formatted output as a string: - - str := spew.Sdump(myVar1, myVar2, ...) - -Sample Dump Output - -See the Dump example for details on the setup of the types and variables being -shown here. - - (main.Foo) { - unexportedField: (*main.Bar)(0xf84002e210)({ - flag: (main.Flag) flagTwo, - data: (uintptr) - }), - ExportedField: (map[interface {}]interface {}) (len=1) { - (string) (len=3) "one": (bool) true - } - } - -Byte (and uint8) arrays and slices are displayed uniquely like the hexdump -C -command as shown. - ([]uint8) (len=32 cap=32) { - 00000000 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 |............... | - 00000010 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 |!"#$%&'()*+,-./0| - 00000020 31 32 |12| - } - -Custom Formatter - -Spew provides a custom formatter that implements the fmt.Formatter interface -so that it integrates cleanly with standard fmt package printing functions. The -formatter is useful for inline printing of smaller data types similar to the -standard %v format specifier. - -The custom formatter only responds to the %v (most compact), %+v (adds pointer -addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb -combinations. Any other verbs such as %x and %q will be sent to the the -standard fmt package for formatting. In addition, the custom formatter ignores -the width and precision arguments (however they will still work on the format -specifiers not handled by the custom formatter). - -Custom Formatter Usage - -The simplest way to make use of the spew custom formatter is to call one of the -convenience functions such as spew.Printf, spew.Println, or spew.Printf. The -functions have syntax you are most likely already familiar with: - - spew.Printf("myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Printf("myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - spew.Println(myVar, myVar2) - spew.Fprintf(os.Stderr, "myVar1: %v -- myVar2: %+v", myVar1, myVar2) - spew.Fprintf(os.Stderr, "myVar3: %#v -- myVar4: %#+v", myVar3, myVar4) - -See the Index for the full list convenience functions. - -Sample Formatter Output - -Double pointer to a uint8: - %v: <**>5 - %+v: <**>(0xf8400420d0->0xf8400420c8)5 - %#v: (**uint8)5 - %#+v: (**uint8)(0xf8400420d0->0xf8400420c8)5 - -Pointer to circular struct with a uint8 field and a pointer to itself: - %v: <*>{1 <*>} - %+v: <*>(0xf84003e260){ui8:1 c:<*>(0xf84003e260)} - %#v: (*main.circular){ui8:(uint8)1 c:(*main.circular)} - %#+v: (*main.circular)(0xf84003e260){ui8:(uint8)1 c:(*main.circular)(0xf84003e260)} - -See the Printf example for details on the setup of variables being shown -here. - -Errors - -Since it is possible for custom Stringer/error interfaces to panic, spew -detects them and handles them internally by printing the panic information -inline with the output. Since spew is intended to provide deep pretty printing -capabilities on structures, it intentionally does not return any errors. -*/ -package spew diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/dump.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/dump.go deleted file mode 100644 index df1d582a72..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/dump.go +++ /dev/null @@ -1,509 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "encoding/hex" - "fmt" - "io" - "os" - "reflect" - "regexp" - "strconv" - "strings" -) - -var ( - // uint8Type is a reflect.Type representing a uint8. It is used to - // convert cgo types to uint8 slices for hexdumping. - uint8Type = reflect.TypeOf(uint8(0)) - - // cCharRE is a regular expression that matches a cgo char. - // It is used to detect character arrays to hexdump them. - cCharRE = regexp.MustCompile("^.*\\._Ctype_char$") - - // cUnsignedCharRE is a regular expression that matches a cgo unsigned - // char. It is used to detect unsigned character arrays to hexdump - // them. - cUnsignedCharRE = regexp.MustCompile("^.*\\._Ctype_unsignedchar$") - - // cUint8tCharRE is a regular expression that matches a cgo uint8_t. - // It is used to detect uint8_t arrays to hexdump them. - cUint8tCharRE = regexp.MustCompile("^.*\\._Ctype_uint8_t$") -) - -// dumpState contains information about the state of a dump operation. -type dumpState struct { - w io.Writer - depth int - pointers map[uintptr]int - ignoreNextType bool - ignoreNextIndent bool - cs *ConfigState -} - -// indent performs indentation according to the depth level and cs.Indent -// option. -func (d *dumpState) indent() { - if d.ignoreNextIndent { - d.ignoreNextIndent = false - return - } - d.w.Write(bytes.Repeat([]byte(d.cs.Indent), d.depth)) -} - -// unpackValue returns values inside of non-nil interfaces when possible. -// This is useful for data types like structs, arrays, slices, and maps which -// can contain varying types packed inside an interface. -func (d *dumpState) unpackValue(v reflect.Value) reflect.Value { - if v.Kind() == reflect.Interface && !v.IsNil() { - v = v.Elem() - } - return v -} - -// dumpPtr handles formatting of pointers by indirecting them as necessary. -func (d *dumpState) dumpPtr(v reflect.Value) { - // Remove pointers at or below the current depth from map used to detect - // circular refs. - for k, depth := range d.pointers { - if depth >= d.depth { - delete(d.pointers, k) - } - } - - // Keep list of all dereferenced pointers to show later. - pointerChain := make([]uintptr, 0) - - // Figure out how many levels of indirection there are by dereferencing - // pointers and unpacking interfaces down the chain while detecting circular - // references. - nilFound := false - cycleFound := false - indirects := 0 - ve := v - for ve.Kind() == reflect.Ptr { - if ve.IsNil() { - nilFound = true - break - } - indirects++ - addr := ve.Pointer() - pointerChain = append(pointerChain, addr) - if pd, ok := d.pointers[addr]; ok && pd < d.depth { - cycleFound = true - indirects-- - break - } - d.pointers[addr] = d.depth - - ve = ve.Elem() - if ve.Kind() == reflect.Interface { - if ve.IsNil() { - nilFound = true - break - } - ve = ve.Elem() - } - } - - // Display type information. - d.w.Write(openParenBytes) - d.w.Write(bytes.Repeat(asteriskBytes, indirects)) - d.w.Write([]byte(ve.Type().String())) - d.w.Write(closeParenBytes) - - // Display pointer information. - if !d.cs.DisablePointerAddresses && len(pointerChain) > 0 { - d.w.Write(openParenBytes) - for i, addr := range pointerChain { - if i > 0 { - d.w.Write(pointerChainBytes) - } - printHexPtr(d.w, addr) - } - d.w.Write(closeParenBytes) - } - - // Display dereferenced value. - d.w.Write(openParenBytes) - switch { - case nilFound == true: - d.w.Write(nilAngleBytes) - - case cycleFound == true: - d.w.Write(circularBytes) - - default: - d.ignoreNextType = true - d.dump(ve) - } - d.w.Write(closeParenBytes) -} - -// dumpSlice handles formatting of arrays and slices. Byte (uint8 under -// reflection) arrays and slices are dumped in hexdump -C fashion. -func (d *dumpState) dumpSlice(v reflect.Value) { - // Determine whether this type should be hex dumped or not. Also, - // for types which should be hexdumped, try to use the underlying data - // first, then fall back to trying to convert them to a uint8 slice. - var buf []uint8 - doConvert := false - doHexDump := false - numEntries := v.Len() - if numEntries > 0 { - vt := v.Index(0).Type() - vts := vt.String() - switch { - // C types that need to be converted. - case cCharRE.MatchString(vts): - fallthrough - case cUnsignedCharRE.MatchString(vts): - fallthrough - case cUint8tCharRE.MatchString(vts): - doConvert = true - - // Try to use existing uint8 slices and fall back to converting - // and copying if that fails. - case vt.Kind() == reflect.Uint8: - // We need an addressable interface to convert the type - // to a byte slice. However, the reflect package won't - // give us an interface on certain things like - // unexported struct fields in order to enforce - // visibility rules. We use unsafe, when available, to - // bypass these restrictions since this package does not - // mutate the values. - vs := v - if !vs.CanInterface() || !vs.CanAddr() { - vs = unsafeReflectValue(vs) - } - if !UnsafeDisabled { - vs = vs.Slice(0, numEntries) - - // Use the existing uint8 slice if it can be - // type asserted. - iface := vs.Interface() - if slice, ok := iface.([]uint8); ok { - buf = slice - doHexDump = true - break - } - } - - // The underlying data needs to be converted if it can't - // be type asserted to a uint8 slice. - doConvert = true - } - - // Copy and convert the underlying type if needed. - if doConvert && vt.ConvertibleTo(uint8Type) { - // Convert and copy each element into a uint8 byte - // slice. - buf = make([]uint8, numEntries) - for i := 0; i < numEntries; i++ { - vv := v.Index(i) - buf[i] = uint8(vv.Convert(uint8Type).Uint()) - } - doHexDump = true - } - } - - // Hexdump the entire slice as needed. - if doHexDump { - indent := strings.Repeat(d.cs.Indent, d.depth) - str := indent + hex.Dump(buf) - str = strings.Replace(str, "\n", "\n"+indent, -1) - str = strings.TrimRight(str, d.cs.Indent) - d.w.Write([]byte(str)) - return - } - - // Recursively call dump for each item. - for i := 0; i < numEntries; i++ { - d.dump(d.unpackValue(v.Index(i))) - if i < (numEntries - 1) { - d.w.Write(commaNewlineBytes) - } else { - d.w.Write(newlineBytes) - } - } -} - -// dump is the main workhorse for dumping a value. It uses the passed reflect -// value to figure out what kind of object we are dealing with and formats it -// appropriately. It is a recursive function, however circular data structures -// are detected and handled properly. -func (d *dumpState) dump(v reflect.Value) { - // Handle invalid reflect values immediately. - kind := v.Kind() - if kind == reflect.Invalid { - d.w.Write(invalidAngleBytes) - return - } - - // Handle pointers specially. - if kind == reflect.Ptr { - d.indent() - d.dumpPtr(v) - return - } - - // Print type information unless already handled elsewhere. - if !d.ignoreNextType { - d.indent() - d.w.Write(openParenBytes) - d.w.Write([]byte(v.Type().String())) - d.w.Write(closeParenBytes) - d.w.Write(spaceBytes) - } - d.ignoreNextType = false - - // Display length and capacity if the built-in len and cap functions - // work with the value's kind and the len/cap itself is non-zero. - valueLen, valueCap := 0, 0 - switch v.Kind() { - case reflect.Array, reflect.Slice, reflect.Chan: - valueLen, valueCap = v.Len(), v.Cap() - case reflect.Map, reflect.String: - valueLen = v.Len() - } - if valueLen != 0 || !d.cs.DisableCapacities && valueCap != 0 { - d.w.Write(openParenBytes) - if valueLen != 0 { - d.w.Write(lenEqualsBytes) - printInt(d.w, int64(valueLen), 10) - } - if !d.cs.DisableCapacities && valueCap != 0 { - if valueLen != 0 { - d.w.Write(spaceBytes) - } - d.w.Write(capEqualsBytes) - printInt(d.w, int64(valueCap), 10) - } - d.w.Write(closeParenBytes) - d.w.Write(spaceBytes) - } - - // Call Stringer/error interfaces if they exist and the handle methods flag - // is enabled - if !d.cs.DisableMethods { - if (kind != reflect.Invalid) && (kind != reflect.Interface) { - if handled := handleMethods(d.cs, d.w, v); handled { - return - } - } - } - - switch kind { - case reflect.Invalid: - // Do nothing. We should never get here since invalid has already - // been handled above. - - case reflect.Bool: - printBool(d.w, v.Bool()) - - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - printInt(d.w, v.Int(), 10) - - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - printUint(d.w, v.Uint(), 10) - - case reflect.Float32: - printFloat(d.w, v.Float(), 32) - - case reflect.Float64: - printFloat(d.w, v.Float(), 64) - - case reflect.Complex64: - printComplex(d.w, v.Complex(), 32) - - case reflect.Complex128: - printComplex(d.w, v.Complex(), 64) - - case reflect.Slice: - if v.IsNil() { - d.w.Write(nilAngleBytes) - break - } - fallthrough - - case reflect.Array: - d.w.Write(openBraceNewlineBytes) - d.depth++ - if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { - d.indent() - d.w.Write(maxNewlineBytes) - } else { - d.dumpSlice(v) - } - d.depth-- - d.indent() - d.w.Write(closeBraceBytes) - - case reflect.String: - d.w.Write([]byte(strconv.Quote(v.String()))) - - case reflect.Interface: - // The only time we should get here is for nil interfaces due to - // unpackValue calls. - if v.IsNil() { - d.w.Write(nilAngleBytes) - } - - case reflect.Ptr: - // Do nothing. We should never get here since pointers have already - // been handled above. - - case reflect.Map: - // nil maps should be indicated as different than empty maps - if v.IsNil() { - d.w.Write(nilAngleBytes) - break - } - - d.w.Write(openBraceNewlineBytes) - d.depth++ - if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { - d.indent() - d.w.Write(maxNewlineBytes) - } else { - numEntries := v.Len() - keys := v.MapKeys() - if d.cs.SortKeys { - sortValues(keys, d.cs) - } - for i, key := range keys { - d.dump(d.unpackValue(key)) - d.w.Write(colonSpaceBytes) - d.ignoreNextIndent = true - d.dump(d.unpackValue(v.MapIndex(key))) - if i < (numEntries - 1) { - d.w.Write(commaNewlineBytes) - } else { - d.w.Write(newlineBytes) - } - } - } - d.depth-- - d.indent() - d.w.Write(closeBraceBytes) - - case reflect.Struct: - d.w.Write(openBraceNewlineBytes) - d.depth++ - if (d.cs.MaxDepth != 0) && (d.depth > d.cs.MaxDepth) { - d.indent() - d.w.Write(maxNewlineBytes) - } else { - vt := v.Type() - numFields := v.NumField() - for i := 0; i < numFields; i++ { - d.indent() - vtf := vt.Field(i) - d.w.Write([]byte(vtf.Name)) - d.w.Write(colonSpaceBytes) - d.ignoreNextIndent = true - d.dump(d.unpackValue(v.Field(i))) - if i < (numFields - 1) { - d.w.Write(commaNewlineBytes) - } else { - d.w.Write(newlineBytes) - } - } - } - d.depth-- - d.indent() - d.w.Write(closeBraceBytes) - - case reflect.Uintptr: - printHexPtr(d.w, uintptr(v.Uint())) - - case reflect.UnsafePointer, reflect.Chan, reflect.Func: - printHexPtr(d.w, v.Pointer()) - - // There were not any other types at the time this code was written, but - // fall back to letting the default fmt package handle it in case any new - // types are added. - default: - if v.CanInterface() { - fmt.Fprintf(d.w, "%v", v.Interface()) - } else { - fmt.Fprintf(d.w, "%v", v.String()) - } - } -} - -// fdump is a helper function to consolidate the logic from the various public -// methods which take varying writers and config states. -func fdump(cs *ConfigState, w io.Writer, a ...interface{}) { - for _, arg := range a { - if arg == nil { - w.Write(interfaceBytes) - w.Write(spaceBytes) - w.Write(nilAngleBytes) - w.Write(newlineBytes) - continue - } - - d := dumpState{w: w, cs: cs} - d.pointers = make(map[uintptr]int) - d.dump(reflect.ValueOf(arg)) - d.w.Write(newlineBytes) - } -} - -// Fdump formats and displays the passed arguments to io.Writer w. It formats -// exactly the same as Dump. -func Fdump(w io.Writer, a ...interface{}) { - fdump(&Config, w, a...) -} - -// Sdump returns a string with the passed arguments formatted exactly the same -// as Dump. -func Sdump(a ...interface{}) string { - var buf bytes.Buffer - fdump(&Config, &buf, a...) - return buf.String() -} - -/* -Dump displays the passed parameters to standard out with newlines, customizable -indentation, and additional debug information such as complete types and all -pointer addresses used to indirect to the final value. It provides the -following features over the built-in printing facilities provided by the fmt -package: - - * Pointers are dereferenced and followed - * Circular data structures are detected and handled properly - * Custom Stringer/error interfaces are optionally invoked, including - on unexported types - * Custom types which only implement the Stringer/error interfaces via - a pointer receiver are optionally invoked when passing non-pointer - variables - * Byte arrays and slices are dumped like the hexdump -C command which - includes offsets, byte values in hex, and ASCII output - -The configuration options are controlled by an exported package global, -spew.Config. See ConfigState for options documentation. - -See Fdump if you would prefer dumping to an arbitrary io.Writer or Sdump to -get the formatted result as a string. -*/ -func Dump(a ...interface{}) { - fdump(&Config, os.Stdout, a...) -} diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/format.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/format.go deleted file mode 100644 index c49875bacb..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/format.go +++ /dev/null @@ -1,419 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "bytes" - "fmt" - "reflect" - "strconv" - "strings" -) - -// supportedFlags is a list of all the character flags supported by fmt package. -const supportedFlags = "0-+# " - -// formatState implements the fmt.Formatter interface and contains information -// about the state of a formatting operation. The NewFormatter function can -// be used to get a new Formatter which can be used directly as arguments -// in standard fmt package printing calls. -type formatState struct { - value interface{} - fs fmt.State - depth int - pointers map[uintptr]int - ignoreNextType bool - cs *ConfigState -} - -// buildDefaultFormat recreates the original format string without precision -// and width information to pass in to fmt.Sprintf in the case of an -// unrecognized type. Unless new types are added to the language, this -// function won't ever be called. -func (f *formatState) buildDefaultFormat() (format string) { - buf := bytes.NewBuffer(percentBytes) - - for _, flag := range supportedFlags { - if f.fs.Flag(int(flag)) { - buf.WriteRune(flag) - } - } - - buf.WriteRune('v') - - format = buf.String() - return format -} - -// constructOrigFormat recreates the original format string including precision -// and width information to pass along to the standard fmt package. This allows -// automatic deferral of all format strings this package doesn't support. -func (f *formatState) constructOrigFormat(verb rune) (format string) { - buf := bytes.NewBuffer(percentBytes) - - for _, flag := range supportedFlags { - if f.fs.Flag(int(flag)) { - buf.WriteRune(flag) - } - } - - if width, ok := f.fs.Width(); ok { - buf.WriteString(strconv.Itoa(width)) - } - - if precision, ok := f.fs.Precision(); ok { - buf.Write(precisionBytes) - buf.WriteString(strconv.Itoa(precision)) - } - - buf.WriteRune(verb) - - format = buf.String() - return format -} - -// unpackValue returns values inside of non-nil interfaces when possible and -// ensures that types for values which have been unpacked from an interface -// are displayed when the show types flag is also set. -// This is useful for data types like structs, arrays, slices, and maps which -// can contain varying types packed inside an interface. -func (f *formatState) unpackValue(v reflect.Value) reflect.Value { - if v.Kind() == reflect.Interface { - f.ignoreNextType = false - if !v.IsNil() { - v = v.Elem() - } - } - return v -} - -// formatPtr handles formatting of pointers by indirecting them as necessary. -func (f *formatState) formatPtr(v reflect.Value) { - // Display nil if top level pointer is nil. - showTypes := f.fs.Flag('#') - if v.IsNil() && (!showTypes || f.ignoreNextType) { - f.fs.Write(nilAngleBytes) - return - } - - // Remove pointers at or below the current depth from map used to detect - // circular refs. - for k, depth := range f.pointers { - if depth >= f.depth { - delete(f.pointers, k) - } - } - - // Keep list of all dereferenced pointers to possibly show later. - pointerChain := make([]uintptr, 0) - - // Figure out how many levels of indirection there are by derferencing - // pointers and unpacking interfaces down the chain while detecting circular - // references. - nilFound := false - cycleFound := false - indirects := 0 - ve := v - for ve.Kind() == reflect.Ptr { - if ve.IsNil() { - nilFound = true - break - } - indirects++ - addr := ve.Pointer() - pointerChain = append(pointerChain, addr) - if pd, ok := f.pointers[addr]; ok && pd < f.depth { - cycleFound = true - indirects-- - break - } - f.pointers[addr] = f.depth - - ve = ve.Elem() - if ve.Kind() == reflect.Interface { - if ve.IsNil() { - nilFound = true - break - } - ve = ve.Elem() - } - } - - // Display type or indirection level depending on flags. - if showTypes && !f.ignoreNextType { - f.fs.Write(openParenBytes) - f.fs.Write(bytes.Repeat(asteriskBytes, indirects)) - f.fs.Write([]byte(ve.Type().String())) - f.fs.Write(closeParenBytes) - } else { - if nilFound || cycleFound { - indirects += strings.Count(ve.Type().String(), "*") - } - f.fs.Write(openAngleBytes) - f.fs.Write([]byte(strings.Repeat("*", indirects))) - f.fs.Write(closeAngleBytes) - } - - // Display pointer information depending on flags. - if f.fs.Flag('+') && (len(pointerChain) > 0) { - f.fs.Write(openParenBytes) - for i, addr := range pointerChain { - if i > 0 { - f.fs.Write(pointerChainBytes) - } - printHexPtr(f.fs, addr) - } - f.fs.Write(closeParenBytes) - } - - // Display dereferenced value. - switch { - case nilFound == true: - f.fs.Write(nilAngleBytes) - - case cycleFound == true: - f.fs.Write(circularShortBytes) - - default: - f.ignoreNextType = true - f.format(ve) - } -} - -// format is the main workhorse for providing the Formatter interface. It -// uses the passed reflect value to figure out what kind of object we are -// dealing with and formats it appropriately. It is a recursive function, -// however circular data structures are detected and handled properly. -func (f *formatState) format(v reflect.Value) { - // Handle invalid reflect values immediately. - kind := v.Kind() - if kind == reflect.Invalid { - f.fs.Write(invalidAngleBytes) - return - } - - // Handle pointers specially. - if kind == reflect.Ptr { - f.formatPtr(v) - return - } - - // Print type information unless already handled elsewhere. - if !f.ignoreNextType && f.fs.Flag('#') { - f.fs.Write(openParenBytes) - f.fs.Write([]byte(v.Type().String())) - f.fs.Write(closeParenBytes) - } - f.ignoreNextType = false - - // Call Stringer/error interfaces if they exist and the handle methods - // flag is enabled. - if !f.cs.DisableMethods { - if (kind != reflect.Invalid) && (kind != reflect.Interface) { - if handled := handleMethods(f.cs, f.fs, v); handled { - return - } - } - } - - switch kind { - case reflect.Invalid: - // Do nothing. We should never get here since invalid has already - // been handled above. - - case reflect.Bool: - printBool(f.fs, v.Bool()) - - case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Int: - printInt(f.fs, v.Int(), 10) - - case reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uint: - printUint(f.fs, v.Uint(), 10) - - case reflect.Float32: - printFloat(f.fs, v.Float(), 32) - - case reflect.Float64: - printFloat(f.fs, v.Float(), 64) - - case reflect.Complex64: - printComplex(f.fs, v.Complex(), 32) - - case reflect.Complex128: - printComplex(f.fs, v.Complex(), 64) - - case reflect.Slice: - if v.IsNil() { - f.fs.Write(nilAngleBytes) - break - } - fallthrough - - case reflect.Array: - f.fs.Write(openBracketBytes) - f.depth++ - if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { - f.fs.Write(maxShortBytes) - } else { - numEntries := v.Len() - for i := 0; i < numEntries; i++ { - if i > 0 { - f.fs.Write(spaceBytes) - } - f.ignoreNextType = true - f.format(f.unpackValue(v.Index(i))) - } - } - f.depth-- - f.fs.Write(closeBracketBytes) - - case reflect.String: - f.fs.Write([]byte(v.String())) - - case reflect.Interface: - // The only time we should get here is for nil interfaces due to - // unpackValue calls. - if v.IsNil() { - f.fs.Write(nilAngleBytes) - } - - case reflect.Ptr: - // Do nothing. We should never get here since pointers have already - // been handled above. - - case reflect.Map: - // nil maps should be indicated as different than empty maps - if v.IsNil() { - f.fs.Write(nilAngleBytes) - break - } - - f.fs.Write(openMapBytes) - f.depth++ - if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { - f.fs.Write(maxShortBytes) - } else { - keys := v.MapKeys() - if f.cs.SortKeys { - sortValues(keys, f.cs) - } - for i, key := range keys { - if i > 0 { - f.fs.Write(spaceBytes) - } - f.ignoreNextType = true - f.format(f.unpackValue(key)) - f.fs.Write(colonBytes) - f.ignoreNextType = true - f.format(f.unpackValue(v.MapIndex(key))) - } - } - f.depth-- - f.fs.Write(closeMapBytes) - - case reflect.Struct: - numFields := v.NumField() - f.fs.Write(openBraceBytes) - f.depth++ - if (f.cs.MaxDepth != 0) && (f.depth > f.cs.MaxDepth) { - f.fs.Write(maxShortBytes) - } else { - vt := v.Type() - for i := 0; i < numFields; i++ { - if i > 0 { - f.fs.Write(spaceBytes) - } - vtf := vt.Field(i) - if f.fs.Flag('+') || f.fs.Flag('#') { - f.fs.Write([]byte(vtf.Name)) - f.fs.Write(colonBytes) - } - f.format(f.unpackValue(v.Field(i))) - } - } - f.depth-- - f.fs.Write(closeBraceBytes) - - case reflect.Uintptr: - printHexPtr(f.fs, uintptr(v.Uint())) - - case reflect.UnsafePointer, reflect.Chan, reflect.Func: - printHexPtr(f.fs, v.Pointer()) - - // There were not any other types at the time this code was written, but - // fall back to letting the default fmt package handle it if any get added. - default: - format := f.buildDefaultFormat() - if v.CanInterface() { - fmt.Fprintf(f.fs, format, v.Interface()) - } else { - fmt.Fprintf(f.fs, format, v.String()) - } - } -} - -// Format satisfies the fmt.Formatter interface. See NewFormatter for usage -// details. -func (f *formatState) Format(fs fmt.State, verb rune) { - f.fs = fs - - // Use standard formatting for verbs that are not v. - if verb != 'v' { - format := f.constructOrigFormat(verb) - fmt.Fprintf(fs, format, f.value) - return - } - - if f.value == nil { - if fs.Flag('#') { - fs.Write(interfaceBytes) - } - fs.Write(nilAngleBytes) - return - } - - f.format(reflect.ValueOf(f.value)) -} - -// newFormatter is a helper function to consolidate the logic from the various -// public methods which take varying config states. -func newFormatter(cs *ConfigState, v interface{}) fmt.Formatter { - fs := &formatState{value: v, cs: cs} - fs.pointers = make(map[uintptr]int) - return fs -} - -/* -NewFormatter returns a custom formatter that satisfies the fmt.Formatter -interface. As a result, it integrates cleanly with standard fmt package -printing functions. The formatter is useful for inline printing of smaller data -types similar to the standard %v format specifier. - -The custom formatter only responds to the %v (most compact), %+v (adds pointer -addresses), %#v (adds types), or %#+v (adds types and pointer addresses) verb -combinations. Any other verbs such as %x and %q will be sent to the the -standard fmt package for formatting. In addition, the custom formatter ignores -the width and precision arguments (however they will still work on the format -specifiers not handled by the custom formatter). - -Typically this function shouldn't be called directly. It is much easier to make -use of the custom formatter by calling one of the convenience functions such as -Printf, Println, or Fprintf. -*/ -func NewFormatter(v interface{}) fmt.Formatter { - return newFormatter(&Config, v) -} diff --git a/components/engine/vendor/github.com/davecgh/go-spew/spew/spew.go b/components/engine/vendor/github.com/davecgh/go-spew/spew/spew.go deleted file mode 100644 index 32c0e33882..0000000000 --- a/components/engine/vendor/github.com/davecgh/go-spew/spew/spew.go +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2013-2016 Dave Collins - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -package spew - -import ( - "fmt" - "io" -) - -// Errorf is a wrapper for fmt.Errorf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the formatted string as a value that satisfies error. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Errorf(format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Errorf(format string, a ...interface{}) (err error) { - return fmt.Errorf(format, convertArgs(a)...) -} - -// Fprint is a wrapper for fmt.Fprint that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprint(w, spew.NewFormatter(a), spew.NewFormatter(b)) -func Fprint(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprint(w, convertArgs(a)...) -} - -// Fprintf is a wrapper for fmt.Fprintf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintf(w, format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) { - return fmt.Fprintf(w, format, convertArgs(a)...) -} - -// Fprintln is a wrapper for fmt.Fprintln that treats each argument as if it -// passed with a default Formatter interface returned by NewFormatter. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Fprintln(w, spew.NewFormatter(a), spew.NewFormatter(b)) -func Fprintln(w io.Writer, a ...interface{}) (n int, err error) { - return fmt.Fprintln(w, convertArgs(a)...) -} - -// Print is a wrapper for fmt.Print that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Print(spew.NewFormatter(a), spew.NewFormatter(b)) -func Print(a ...interface{}) (n int, err error) { - return fmt.Print(convertArgs(a)...) -} - -// Printf is a wrapper for fmt.Printf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Printf(format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Printf(format string, a ...interface{}) (n int, err error) { - return fmt.Printf(format, convertArgs(a)...) -} - -// Println is a wrapper for fmt.Println that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the number of bytes written and any write error encountered. See -// NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Println(spew.NewFormatter(a), spew.NewFormatter(b)) -func Println(a ...interface{}) (n int, err error) { - return fmt.Println(convertArgs(a)...) -} - -// Sprint is a wrapper for fmt.Sprint that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprint(spew.NewFormatter(a), spew.NewFormatter(b)) -func Sprint(a ...interface{}) string { - return fmt.Sprint(convertArgs(a)...) -} - -// Sprintf is a wrapper for fmt.Sprintf that treats each argument as if it were -// passed with a default Formatter interface returned by NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintf(format, spew.NewFormatter(a), spew.NewFormatter(b)) -func Sprintf(format string, a ...interface{}) string { - return fmt.Sprintf(format, convertArgs(a)...) -} - -// Sprintln is a wrapper for fmt.Sprintln that treats each argument as if it -// were passed with a default Formatter interface returned by NewFormatter. It -// returns the resulting string. See NewFormatter for formatting details. -// -// This function is shorthand for the following syntax: -// -// fmt.Sprintln(spew.NewFormatter(a), spew.NewFormatter(b)) -func Sprintln(a ...interface{}) string { - return fmt.Sprintln(convertArgs(a)...) -} - -// convertArgs accepts a slice of arguments and returns a slice of the same -// length with each argument converted to a default spew Formatter interface. -func convertArgs(args []interface{}) (formatters []interface{}) { - formatters = make([]interface{}, len(args)) - for index, arg := range args { - formatters[index] = NewFormatter(arg) - } - return formatters -} diff --git a/components/engine/vendor/github.com/google/go-cmp/README.md b/components/engine/vendor/github.com/google/go-cmp/README.md index d82f10bfcb..61c9c4cd98 100644 --- a/components/engine/vendor/github.com/google/go-cmp/README.md +++ b/components/engine/vendor/github.com/google/go-cmp/README.md @@ -21,7 +21,7 @@ The primary features of `cmp` are: equality is determined by recursively comparing the primitive kinds on both values, much like `reflect.DeepEqual`. Unlike `reflect.DeepEqual`, unexported fields are not compared by default; they result in panics unless suppressed - by using an `Ignore` option (see `cmpopts.IgnoreUnexported`) or explictly + by using an `Ignore` option (see `cmpopts.IgnoreUnexported`) or explicitly compared using the `AllowUnexported` option. See the [GoDoc documentation][godoc] for more information. diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go new file mode 100644 index 0000000000..41bbddc61b --- /dev/null +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go @@ -0,0 +1,89 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE.md file. + +// Package cmpopts provides common options for the cmp package. +package cmpopts + +import ( + "math" + "reflect" + + "github.com/google/go-cmp/cmp" +) + +func equateAlways(_, _ interface{}) bool { return true } + +// EquateEmpty returns a Comparer option that determines all maps and slices +// with a length of zero to be equal, regardless of whether they are nil. +// +// EquateEmpty can be used in conjunction with SortSlices and SortMaps. +func EquateEmpty() cmp.Option { + return cmp.FilterValues(isEmpty, cmp.Comparer(equateAlways)) +} + +func isEmpty(x, y interface{}) bool { + vx, vy := reflect.ValueOf(x), reflect.ValueOf(y) + return (x != nil && y != nil && vx.Type() == vy.Type()) && + (vx.Kind() == reflect.Slice || vx.Kind() == reflect.Map) && + (vx.Len() == 0 && vy.Len() == 0) +} + +// EquateApprox returns a Comparer option that determines float32 or float64 +// values to be equal if they are within a relative fraction or absolute margin. +// This option is not used when either x or y is NaN or infinite. +// +// The fraction determines that the difference of two values must be within the +// smaller fraction of the two values, while the margin determines that the two +// values must be within some absolute margin. +// To express only a fraction or only a margin, use 0 for the other parameter. +// The fraction and margin must be non-negative. +// +// The mathematical expression used is equivalent to: +// |x-y| ≤ max(fraction*min(|x|, |y|), margin) +// +// EquateApprox can be used in conjunction with EquateNaNs. +func EquateApprox(fraction, margin float64) cmp.Option { + if margin < 0 || fraction < 0 || math.IsNaN(margin) || math.IsNaN(fraction) { + panic("margin or fraction must be a non-negative number") + } + a := approximator{fraction, margin} + return cmp.Options{ + cmp.FilterValues(areRealF64s, cmp.Comparer(a.compareF64)), + cmp.FilterValues(areRealF32s, cmp.Comparer(a.compareF32)), + } +} + +type approximator struct{ frac, marg float64 } + +func areRealF64s(x, y float64) bool { + return !math.IsNaN(x) && !math.IsNaN(y) && !math.IsInf(x, 0) && !math.IsInf(y, 0) +} +func areRealF32s(x, y float32) bool { + return areRealF64s(float64(x), float64(y)) +} +func (a approximator) compareF64(x, y float64) bool { + relMarg := a.frac * math.Min(math.Abs(x), math.Abs(y)) + return math.Abs(x-y) <= math.Max(a.marg, relMarg) +} +func (a approximator) compareF32(x, y float32) bool { + return a.compareF64(float64(x), float64(y)) +} + +// EquateNaNs returns a Comparer option that determines float32 and float64 +// NaN values to be equal. +// +// EquateNaNs can be used in conjunction with EquateApprox. +func EquateNaNs() cmp.Option { + return cmp.Options{ + cmp.FilterValues(areNaNsF64s, cmp.Comparer(equateAlways)), + cmp.FilterValues(areNaNsF32s, cmp.Comparer(equateAlways)), + } +} + +func areNaNsF64s(x, y float64) bool { + return math.IsNaN(x) && math.IsNaN(y) +} +func areNaNsF32s(x, y float32) bool { + return areNaNsF64s(float64(x), float64(y)) +} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/ignore.go b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/ignore.go new file mode 100644 index 0000000000..e86554b92b --- /dev/null +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/ignore.go @@ -0,0 +1,145 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE.md file. + +package cmpopts + +import ( + "fmt" + "reflect" + "unicode" + "unicode/utf8" + + "github.com/google/go-cmp/cmp" +) + +// IgnoreFields returns an Option that ignores exported fields of the +// given names on a single struct type. +// The struct type is specified by passing in a value of that type. +// +// The name may be a dot-delimited string (e.g., "Foo.Bar") to ignore a +// specific sub-field that is embedded or nested within the parent struct. +// +// This does not handle unexported fields; use IgnoreUnexported instead. +func IgnoreFields(typ interface{}, names ...string) cmp.Option { + sf := newStructFilter(typ, names...) + return cmp.FilterPath(sf.filter, cmp.Ignore()) +} + +// IgnoreTypes returns an Option that ignores all values assignable to +// certain types, which are specified by passing in a value of each type. +func IgnoreTypes(typs ...interface{}) cmp.Option { + tf := newTypeFilter(typs...) + return cmp.FilterPath(tf.filter, cmp.Ignore()) +} + +type typeFilter []reflect.Type + +func newTypeFilter(typs ...interface{}) (tf typeFilter) { + for _, typ := range typs { + t := reflect.TypeOf(typ) + if t == nil { + // This occurs if someone tries to pass in sync.Locker(nil) + panic("cannot determine type; consider using IgnoreInterfaces") + } + tf = append(tf, t) + } + return tf +} +func (tf typeFilter) filter(p cmp.Path) bool { + if len(p) < 1 { + return false + } + t := p.Last().Type() + for _, ti := range tf { + if t.AssignableTo(ti) { + return true + } + } + return false +} + +// IgnoreInterfaces returns an Option that ignores all values or references of +// values assignable to certain interface types. These interfaces are specified +// by passing in an anonymous struct with the interface types embedded in it. +// For example, to ignore sync.Locker, pass in struct{sync.Locker}{}. +func IgnoreInterfaces(ifaces interface{}) cmp.Option { + tf := newIfaceFilter(ifaces) + return cmp.FilterPath(tf.filter, cmp.Ignore()) +} + +type ifaceFilter []reflect.Type + +func newIfaceFilter(ifaces interface{}) (tf ifaceFilter) { + t := reflect.TypeOf(ifaces) + if ifaces == nil || t.Name() != "" || t.Kind() != reflect.Struct { + panic("input must be an anonymous struct") + } + for i := 0; i < t.NumField(); i++ { + fi := t.Field(i) + switch { + case !fi.Anonymous: + panic("struct cannot have named fields") + case fi.Type.Kind() != reflect.Interface: + panic("embedded field must be an interface type") + case fi.Type.NumMethod() == 0: + // This matches everything; why would you ever want this? + panic("cannot ignore empty interface") + default: + tf = append(tf, fi.Type) + } + } + return tf +} +func (tf ifaceFilter) filter(p cmp.Path) bool { + if len(p) < 1 { + return false + } + t := p.Last().Type() + for _, ti := range tf { + if t.AssignableTo(ti) { + return true + } + if t.Kind() != reflect.Ptr && reflect.PtrTo(t).AssignableTo(ti) { + return true + } + } + return false +} + +// IgnoreUnexported returns an Option that only ignores the immediate unexported +// fields of a struct, including anonymous fields of unexported types. +// In particular, unexported fields within the struct's exported fields +// of struct types, including anonymous fields, will not be ignored unless the +// type of the field itself is also passed to IgnoreUnexported. +func IgnoreUnexported(typs ...interface{}) cmp.Option { + ux := newUnexportedFilter(typs...) + return cmp.FilterPath(ux.filter, cmp.Ignore()) +} + +type unexportedFilter struct{ m map[reflect.Type]bool } + +func newUnexportedFilter(typs ...interface{}) unexportedFilter { + ux := unexportedFilter{m: make(map[reflect.Type]bool)} + for _, typ := range typs { + t := reflect.TypeOf(typ) + if t == nil || t.Kind() != reflect.Struct { + panic(fmt.Sprintf("invalid struct type: %T", typ)) + } + ux.m[t] = true + } + return ux +} +func (xf unexportedFilter) filter(p cmp.Path) bool { + sf, ok := p.Index(-1).(cmp.StructField) + if !ok { + return false + } + return xf.m[p.Index(-2).Type()] && !isExported(sf.Name()) +} + +// isExported reports whether the identifier is exported. +func isExported(id string) bool { + r, _ := utf8.DecodeRuneInString(id) + return unicode.IsUpper(r) +} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort.go b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort.go new file mode 100644 index 0000000000..da17d74693 --- /dev/null +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort.go @@ -0,0 +1,146 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE.md file. + +package cmpopts + +import ( + "fmt" + "reflect" + + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/internal/function" +) + +// SortSlices returns a Transformer option that sorts all []V. +// The less function must be of the form "func(T, T) bool" which is used to +// sort any slice with element type V that is assignable to T. +// +// The less function must be: +// • Deterministic: less(x, y) == less(x, y) +// • Irreflexive: !less(x, x) +// • Transitive: if !less(x, y) and !less(y, z), then !less(x, z) +// +// The less function does not have to be "total". That is, if !less(x, y) and +// !less(y, x) for two elements x and y, their relative order is maintained. +// +// SortSlices can be used in conjunction with EquateEmpty. +func SortSlices(less interface{}) cmp.Option { + vf := reflect.ValueOf(less) + if !function.IsType(vf.Type(), function.Less) || vf.IsNil() { + panic(fmt.Sprintf("invalid less function: %T", less)) + } + ss := sliceSorter{vf.Type().In(0), vf} + return cmp.FilterValues(ss.filter, cmp.Transformer("Sort", ss.sort)) +} + +type sliceSorter struct { + in reflect.Type // T + fnc reflect.Value // func(T, T) bool +} + +func (ss sliceSorter) filter(x, y interface{}) bool { + vx, vy := reflect.ValueOf(x), reflect.ValueOf(y) + if !(x != nil && y != nil && vx.Type() == vy.Type()) || + !(vx.Kind() == reflect.Slice && vx.Type().Elem().AssignableTo(ss.in)) || + (vx.Len() <= 1 && vy.Len() <= 1) { + return false + } + // Check whether the slices are already sorted to avoid an infinite + // recursion cycle applying the same transform to itself. + ok1 := sliceIsSorted(x, func(i, j int) bool { return ss.less(vx, i, j) }) + ok2 := sliceIsSorted(y, func(i, j int) bool { return ss.less(vy, i, j) }) + return !ok1 || !ok2 +} +func (ss sliceSorter) sort(x interface{}) interface{} { + src := reflect.ValueOf(x) + dst := reflect.MakeSlice(src.Type(), src.Len(), src.Len()) + for i := 0; i < src.Len(); i++ { + dst.Index(i).Set(src.Index(i)) + } + sortSliceStable(dst.Interface(), func(i, j int) bool { return ss.less(dst, i, j) }) + ss.checkSort(dst) + return dst.Interface() +} +func (ss sliceSorter) checkSort(v reflect.Value) { + start := -1 // Start of a sequence of equal elements. + for i := 1; i < v.Len(); i++ { + if ss.less(v, i-1, i) { + // Check that first and last elements in v[start:i] are equal. + if start >= 0 && (ss.less(v, start, i-1) || ss.less(v, i-1, start)) { + panic(fmt.Sprintf("incomparable values detected: want equal elements: %v", v.Slice(start, i))) + } + start = -1 + } else if start == -1 { + start = i + } + } +} +func (ss sliceSorter) less(v reflect.Value, i, j int) bool { + vx, vy := v.Index(i), v.Index(j) + return ss.fnc.Call([]reflect.Value{vx, vy})[0].Bool() +} + +// SortMaps returns a Transformer option that flattens map[K]V types to be a +// sorted []struct{K, V}. The less function must be of the form +// "func(T, T) bool" which is used to sort any map with key K that is +// assignable to T. +// +// Flattening the map into a slice has the property that cmp.Equal is able to +// use Comparers on K or the K.Equal method if it exists. +// +// The less function must be: +// • Deterministic: less(x, y) == less(x, y) +// • Irreflexive: !less(x, x) +// • Transitive: if !less(x, y) and !less(y, z), then !less(x, z) +// • Total: if x != y, then either less(x, y) or less(y, x) +// +// SortMaps can be used in conjunction with EquateEmpty. +func SortMaps(less interface{}) cmp.Option { + vf := reflect.ValueOf(less) + if !function.IsType(vf.Type(), function.Less) || vf.IsNil() { + panic(fmt.Sprintf("invalid less function: %T", less)) + } + ms := mapSorter{vf.Type().In(0), vf} + return cmp.FilterValues(ms.filter, cmp.Transformer("Sort", ms.sort)) +} + +type mapSorter struct { + in reflect.Type // T + fnc reflect.Value // func(T, T) bool +} + +func (ms mapSorter) filter(x, y interface{}) bool { + vx, vy := reflect.ValueOf(x), reflect.ValueOf(y) + return (x != nil && y != nil && vx.Type() == vy.Type()) && + (vx.Kind() == reflect.Map && vx.Type().Key().AssignableTo(ms.in)) && + (vx.Len() != 0 || vy.Len() != 0) +} +func (ms mapSorter) sort(x interface{}) interface{} { + src := reflect.ValueOf(x) + outType := mapEntryType(src.Type()) + dst := reflect.MakeSlice(reflect.SliceOf(outType), src.Len(), src.Len()) + for i, k := range src.MapKeys() { + v := reflect.New(outType).Elem() + v.Field(0).Set(k) + v.Field(1).Set(src.MapIndex(k)) + dst.Index(i).Set(v) + } + sortSlice(dst.Interface(), func(i, j int) bool { return ms.less(dst, i, j) }) + ms.checkSort(dst) + return dst.Interface() +} +func (ms mapSorter) checkSort(v reflect.Value) { + for i := 1; i < v.Len(); i++ { + if !ms.less(v, i-1, i) { + panic(fmt.Sprintf("partial order detected: want %v < %v", v.Index(i-1), v.Index(i))) + } + } +} +func (ms mapSorter) less(v reflect.Value, i, j int) bool { + vx, vy := v.Index(i).Field(0), v.Index(j).Field(0) + if !hasReflectStructOf { + vx, vy = vx.Elem(), vy.Elem() + } + return ms.fnc.Call([]reflect.Value{vx, vy})[0].Bool() +} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort_go17.go b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort_go17.go new file mode 100644 index 0000000000..839b88ca40 --- /dev/null +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort_go17.go @@ -0,0 +1,46 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE.md file. + +// +build !go1.8 + +package cmpopts + +import ( + "reflect" + "sort" +) + +const hasReflectStructOf = false + +func mapEntryType(reflect.Type) reflect.Type { + return reflect.TypeOf(struct{ K, V interface{} }{}) +} + +func sliceIsSorted(slice interface{}, less func(i, j int) bool) bool { + return sort.IsSorted(reflectSliceSorter{reflect.ValueOf(slice), less}) +} +func sortSlice(slice interface{}, less func(i, j int) bool) { + sort.Sort(reflectSliceSorter{reflect.ValueOf(slice), less}) +} +func sortSliceStable(slice interface{}, less func(i, j int) bool) { + sort.Stable(reflectSliceSorter{reflect.ValueOf(slice), less}) +} + +type reflectSliceSorter struct { + slice reflect.Value + less func(i, j int) bool +} + +func (ss reflectSliceSorter) Len() int { + return ss.slice.Len() +} +func (ss reflectSliceSorter) Less(i, j int) bool { + return ss.less(i, j) +} +func (ss reflectSliceSorter) Swap(i, j int) { + vi := ss.slice.Index(i).Interface() + vj := ss.slice.Index(j).Interface() + ss.slice.Index(i).Set(reflect.ValueOf(vj)) + ss.slice.Index(j).Set(reflect.ValueOf(vi)) +} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort_go18.go b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort_go18.go new file mode 100644 index 0000000000..8a59c0d38f --- /dev/null +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/sort_go18.go @@ -0,0 +1,31 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE.md file. + +// +build go1.8 + +package cmpopts + +import ( + "reflect" + "sort" +) + +const hasReflectStructOf = true + +func mapEntryType(t reflect.Type) reflect.Type { + return reflect.StructOf([]reflect.StructField{ + {Name: "K", Type: t.Key()}, + {Name: "V", Type: t.Elem()}, + }) +} + +func sliceIsSorted(slice interface{}, less func(i, j int) bool) bool { + return sort.SliceIsSorted(slice, less) +} +func sortSlice(slice interface{}, less func(i, j int) bool) { + sort.Slice(slice, less) +} +func sortSliceStable(slice interface{}, less func(i, j int) bool) { + sort.SliceStable(slice, less) +} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/struct_filter.go b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/struct_filter.go new file mode 100644 index 0000000000..97f707983c --- /dev/null +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/cmpopts/struct_filter.go @@ -0,0 +1,182 @@ +// Copyright 2017, The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE.md file. + +package cmpopts + +import ( + "fmt" + "reflect" + "strings" + + "github.com/google/go-cmp/cmp" +) + +// filterField returns a new Option where opt is only evaluated on paths that +// include a specific exported field on a single struct type. +// The struct type is specified by passing in a value of that type. +// +// The name may be a dot-delimited string (e.g., "Foo.Bar") to select a +// specific sub-field that is embedded or nested within the parent struct. +func filterField(typ interface{}, name string, opt cmp.Option) cmp.Option { + // TODO: This is currently unexported over concerns of how helper filters + // can be composed together easily. + // TODO: Add tests for FilterField. + + sf := newStructFilter(typ, name) + return cmp.FilterPath(sf.filter, opt) +} + +type structFilter struct { + t reflect.Type // The root struct type to match on + ft fieldTree // Tree of fields to match on +} + +func newStructFilter(typ interface{}, names ...string) structFilter { + // TODO: Perhaps allow * as a special identifier to allow ignoring any + // number of path steps until the next field match? + // This could be useful when a concrete struct gets transformed into + // an anonymous struct where it is not possible to specify that by type, + // but the transformer happens to provide guarantees about the names of + // the transformed fields. + + t := reflect.TypeOf(typ) + if t == nil || t.Kind() != reflect.Struct { + panic(fmt.Sprintf("%T must be a struct", typ)) + } + var ft fieldTree + for _, name := range names { + cname, err := canonicalName(t, name) + if err != nil { + panic(fmt.Sprintf("%s: %v", strings.Join(cname, "."), err)) + } + ft.insert(cname) + } + return structFilter{t, ft} +} + +func (sf structFilter) filter(p cmp.Path) bool { + for i, ps := range p { + if ps.Type().AssignableTo(sf.t) && sf.ft.matchPrefix(p[i+1:]) { + return true + } + } + return false +} + +// fieldTree represents a set of dot-separated identifiers. +// +// For example, inserting the following selectors: +// Foo +// Foo.Bar.Baz +// Foo.Buzz +// Nuka.Cola.Quantum +// +// Results in a tree of the form: +// {sub: { +// "Foo": {ok: true, sub: { +// "Bar": {sub: { +// "Baz": {ok: true}, +// }}, +// "Buzz": {ok: true}, +// }}, +// "Nuka": {sub: { +// "Cola": {sub: { +// "Quantum": {ok: true}, +// }}, +// }}, +// }} +type fieldTree struct { + ok bool // Whether this is a specified node + sub map[string]fieldTree // The sub-tree of fields under this node +} + +// insert inserts a sequence of field accesses into the tree. +func (ft *fieldTree) insert(cname []string) { + if ft.sub == nil { + ft.sub = make(map[string]fieldTree) + } + if len(cname) == 0 { + ft.ok = true + return + } + sub := ft.sub[cname[0]] + sub.insert(cname[1:]) + ft.sub[cname[0]] = sub +} + +// matchPrefix reports whether any selector in the fieldTree matches +// the start of path p. +func (ft fieldTree) matchPrefix(p cmp.Path) bool { + for _, ps := range p { + switch ps := ps.(type) { + case cmp.StructField: + ft = ft.sub[ps.Name()] + if ft.ok { + return true + } + if len(ft.sub) == 0 { + return false + } + case cmp.Indirect: + default: + return false + } + } + return false +} + +// canonicalName returns a list of identifiers where any struct field access +// through an embedded field is expanded to include the names of the embedded +// types themselves. +// +// For example, suppose field "Foo" is not directly in the parent struct, +// but actually from an embedded struct of type "Bar". Then, the canonical name +// of "Foo" is actually "Bar.Foo". +// +// Suppose field "Foo" is not directly in the parent struct, but actually +// a field in two different embedded structs of types "Bar" and "Baz". +// Then the selector "Foo" causes a panic since it is ambiguous which one it +// refers to. The user must specify either "Bar.Foo" or "Baz.Foo". +func canonicalName(t reflect.Type, sel string) ([]string, error) { + var name string + sel = strings.TrimPrefix(sel, ".") + if sel == "" { + return nil, fmt.Errorf("name must not be empty") + } + if i := strings.IndexByte(sel, '.'); i < 0 { + name, sel = sel, "" + } else { + name, sel = sel[:i], sel[i:] + } + + // Type must be a struct or pointer to struct. + if t.Kind() == reflect.Ptr { + t = t.Elem() + } + if t.Kind() != reflect.Struct { + return nil, fmt.Errorf("%v must be a struct", t) + } + + // Find the canonical name for this current field name. + // If the field exists in an embedded struct, then it will be expanded. + if !isExported(name) { + // Disallow unexported fields: + // * To discourage people from actually touching unexported fields + // * FieldByName is buggy (https://golang.org/issue/4876) + return []string{name}, fmt.Errorf("name must be exported") + } + sf, ok := t.FieldByName(name) + if !ok { + return []string{name}, fmt.Errorf("does not exist") + } + var ss []string + for i := range sf.Index { + ss = append(ss, t.FieldByIndex(sf.Index[:i+1]).Name) + } + if sel == "" { + return ss, nil + } + ssPost, err := canonicalName(sf.Type, sel) + return append(ss, ssPost...), err +} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/compare.go b/components/engine/vendor/github.com/google/go-cmp/cmp/compare.go index 5527f01497..7e215f2202 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/compare.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/compare.go @@ -22,7 +22,7 @@ // equality is determined by recursively comparing the primitive kinds on both // values, much like reflect.DeepEqual. Unlike reflect.DeepEqual, unexported // fields are not compared by default; they result in panics unless suppressed -// by using an Ignore option (see cmpopts.IgnoreUnexported) or explictly compared +// by using an Ignore option (see cmpopts.IgnoreUnexported) or explicitly compared // using the AllowUnexported option. package cmp @@ -35,7 +35,7 @@ import ( "github.com/google/go-cmp/cmp/internal/value" ) -// BUG: Maps with keys containing NaN values cannot be properly compared due to +// BUG(dsnet): Maps with keys containing NaN values cannot be properly compared due to // the reflection package's inability to retrieve such entries. Equal will panic // anytime it comes across a NaN key, but this behavior may change. // @@ -61,8 +61,8 @@ var nothing = reflect.Value{} // // • If the values have an Equal method of the form "(T) Equal(T) bool" or // "(T) Equal(I) bool" where T is assignable to I, then use the result of -// x.Equal(y). Otherwise, no such method exists and evaluation proceeds to -// the next rule. +// x.Equal(y) even if x or y is nil. +// Otherwise, no such method exists and evaluation proceeds to the next rule. // // • Lastly, try to compare x and y based on their basic kinds. // Simple kinds like booleans, integers, floats, complex numbers, strings, and @@ -304,7 +304,8 @@ func (s *state) tryOptions(vx, vy reflect.Value, t reflect.Type) bool { // Evaluate all filters and apply the remaining options. if opt := opts.filter(s, vx, vy, t); opt != nil { - return opt.apply(s, vx, vy) + opt.apply(s, vx, vy) + return true } return false } @@ -322,6 +323,7 @@ func (s *state) tryMethod(vx, vy reflect.Value, t reflect.Type) bool { } func (s *state) callTRFunc(f, v reflect.Value) reflect.Value { + v = sanitizeValue(v, f.Type().In(0)) if !s.dynChecker.Next() { return f.Call([]reflect.Value{v})[0] } @@ -345,6 +347,8 @@ func (s *state) callTRFunc(f, v reflect.Value) reflect.Value { } func (s *state) callTTBFunc(f, x, y reflect.Value) bool { + x = sanitizeValue(x, f.Type().In(0)) + y = sanitizeValue(y, f.Type().In(1)) if !s.dynChecker.Next() { return f.Call([]reflect.Value{x, y})[0].Bool() } @@ -372,20 +376,40 @@ func detectRaces(c chan<- reflect.Value, f reflect.Value, vs ...reflect.Value) { ret = f.Call(vs)[0] } +// sanitizeValue converts nil interfaces of type T to those of type R, +// assuming that T is assignable to R. +// Otherwise, it returns the input value as is. +func sanitizeValue(v reflect.Value, t reflect.Type) reflect.Value { + // TODO(dsnet): Remove this hacky workaround. + // See https://golang.org/issue/22143 + if v.Kind() == reflect.Interface && v.IsNil() && v.Type() != t { + return reflect.New(t).Elem() + } + return v +} + func (s *state) compareArray(vx, vy reflect.Value, t reflect.Type) { step := &sliceIndex{pathStep{t.Elem()}, 0, 0} s.curPath.push(step) // Compute an edit-script for slices vx and vy. - eq, es := diff.Difference(vx.Len(), vy.Len(), func(ix, iy int) diff.Result { + es := diff.Difference(vx.Len(), vy.Len(), func(ix, iy int) diff.Result { step.xkey, step.ykey = ix, iy return s.statelessCompare(vx.Index(ix), vy.Index(iy)) }) - // Equal or no edit-script, so report entire slices as is. - if eq || es == nil { + // Report the entire slice as is if the arrays are of primitive kind, + // and the arrays are different enough. + isPrimitive := false + switch t.Elem().Kind() { + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, + reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, + reflect.Bool, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128: + isPrimitive = true + } + if isPrimitive && es.Dist() > (vx.Len()+vy.Len())/4 { s.curPath.pop() // Pop first since we are reporting the whole slice - s.report(eq, vx, vy) + s.report(false, vx, vy) return } diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/debug_enable.go b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/debug_enable.go index ba46c62e1c..fd9f7f1773 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/debug_enable.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/debug_enable.go @@ -50,7 +50,7 @@ import ( // // The series of '.', 'X', 'Y', and 'M' characters at the bottom represents // the currently established path from the forward and reverse searches, -// seperated by a '|' character. +// separated by a '|' character. const ( updateDelay = 100 * time.Millisecond diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go index baa41fd23c..260befea2f 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go @@ -106,9 +106,9 @@ func (r Result) Similar() bool { // Difference reports whether two lists of lengths nx and ny are equal // given the definition of equality provided as f. // -// This function may return a edit-script, which is a sequence of operations -// needed to convert one list into the other. If non-nil, the following -// invariants for the edit-script are maintained: +// This function returns an edit-script, which is a sequence of operations +// needed to convert one list into the other. The following invariants for +// the edit-script are maintained: // • eq == (es.Dist()==0) // • nx == es.LenX() // • ny == es.LenY() @@ -117,17 +117,7 @@ func (r Result) Similar() bool { // produces an edit-script with a minimal Levenshtein distance). This algorithm // favors performance over optimality. The exact output is not guaranteed to // be stable and may change over time. -func Difference(nx, ny int, f EqualFunc) (eq bool, es EditScript) { - es = searchGraph(nx, ny, f) - st := es.stats() - eq = len(es) == st.NI - if !eq && st.NI < (nx+ny)/4 { - return eq, nil // Edit-script more distracting than helpful - } - return eq, es -} - -func searchGraph(nx, ny int, f EqualFunc) EditScript { +func Difference(nx, ny int, f EqualFunc) (es EditScript) { // This algorithm is based on traversing what is known as an "edit-graph". // See Figure 1 from "An O(ND) Difference Algorithm and Its Variations" // by Eugene W. Myers. Since D can be as large as N itself, this is diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/format.go b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/format.go index abaeca89e7..657e508779 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/format.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/format.go @@ -8,15 +8,11 @@ package value import ( "fmt" "reflect" + "strconv" "strings" "unicode" - "unicode/utf8" ) -// formatFakePointers controls whether to substitute pointer addresses with nil. -// This is used for deterministic testing. -var formatFakePointers = false - var stringerIface = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() // Format formats the value v as a string. @@ -26,28 +22,35 @@ var stringerIface = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() // * Avoids printing struct fields that are zero // * Prints a nil-slice as being nil, not empty // * Prints map entries in deterministic order -func Format(v reflect.Value, useStringer bool) string { - return formatAny(v, formatConfig{useStringer, true, true, !formatFakePointers}, nil) +func Format(v reflect.Value, conf FormatConfig) string { + conf.printType = true + conf.followPointers = true + conf.realPointers = true + return formatAny(v, conf, nil) } -type formatConfig struct { - useStringer bool // Should the String method be used if available? - printType bool // Should we print the type before the value? - followPointers bool // Should we recursively follow pointers? - realPointers bool // Should we print the real address of pointers? +type FormatConfig struct { + UseStringer bool // Should the String method be used if available? + printType bool // Should we print the type before the value? + PrintPrimitiveType bool // Should we print the type of primitives? + followPointers bool // Should we recursively follow pointers? + realPointers bool // Should we print the real address of pointers? } -func formatAny(v reflect.Value, conf formatConfig, visited map[uintptr]bool) string { +func formatAny(v reflect.Value, conf FormatConfig, visited map[uintptr]bool) string { // TODO: Should this be a multi-line printout in certain situations? if !v.IsValid() { return "" } - if conf.useStringer && v.Type().Implements(stringerIface) && v.CanInterface() { + if conf.UseStringer && v.Type().Implements(stringerIface) && v.CanInterface() { if (v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface) && v.IsNil() { return "" } - return fmt.Sprintf("%q", v.Interface().(fmt.Stringer).String()) + + const stringerPrefix = "s" // Indicates that the String method was used + s := v.Interface().(fmt.Stringer).String() + return stringerPrefix + formatString(s) } switch v.Kind() { @@ -66,7 +69,7 @@ func formatAny(v reflect.Value, conf formatConfig, visited map[uintptr]bool) str case reflect.Complex64, reflect.Complex128: return formatPrimitive(v.Type(), v.Complex(), conf) case reflect.String: - return formatPrimitive(v.Type(), fmt.Sprintf("%q", v), conf) + return formatPrimitive(v.Type(), formatString(v.String()), conf) case reflect.UnsafePointer, reflect.Chan, reflect.Func: return formatPointer(v, conf) case reflect.Ptr: @@ -127,11 +130,13 @@ func formatAny(v reflect.Value, conf formatConfig, visited map[uintptr]bool) str visited = insertPointer(visited, v.Pointer()) var ss []string - subConf := conf - subConf.printType = v.Type().Elem().Kind() == reflect.Interface + keyConf, valConf := conf, conf + keyConf.printType = v.Type().Key().Kind() == reflect.Interface + keyConf.followPointers = false + valConf.printType = v.Type().Elem().Kind() == reflect.Interface for _, k := range SortKeys(v.MapKeys()) { - sk := formatAny(k, formatConfig{realPointers: conf.realPointers}, visited) - sv := formatAny(v.MapIndex(k), subConf, visited) + sk := formatAny(k, keyConf, visited) + sv := formatAny(v.MapIndex(k), valConf, visited) ss = append(ss, fmt.Sprintf("%s: %s", sk, sv)) } s := fmt.Sprintf("{%s}", strings.Join(ss, ", ")) @@ -149,7 +154,7 @@ func formatAny(v reflect.Value, conf formatConfig, visited map[uintptr]bool) str continue // Elide zero value fields } name := v.Type().Field(i).Name - subConf.useStringer = conf.useStringer && isExported(name) + subConf.UseStringer = conf.UseStringer s := formatAny(vv, subConf, visited) ss = append(ss, fmt.Sprintf("%s: %s", name, s)) } @@ -163,14 +168,33 @@ func formatAny(v reflect.Value, conf formatConfig, visited map[uintptr]bool) str } } -func formatPrimitive(t reflect.Type, v interface{}, conf formatConfig) string { - if conf.printType && t.PkgPath() != "" { +func formatString(s string) string { + // Use quoted string if it the same length as a raw string literal. + // Otherwise, attempt to use the raw string form. + qs := strconv.Quote(s) + if len(qs) == 1+len(s)+1 { + return qs + } + + // Disallow newlines to ensure output is a single line. + // Only allow printable runes for readability purposes. + rawInvalid := func(r rune) bool { + return r == '`' || r == '\n' || !unicode.IsPrint(r) + } + if strings.IndexFunc(s, rawInvalid) < 0 { + return "`" + s + "`" + } + return qs +} + +func formatPrimitive(t reflect.Type, v interface{}, conf FormatConfig) string { + if conf.printType && (conf.PrintPrimitiveType || t.PkgPath() != "") { return fmt.Sprintf("%v(%v)", t, v) } return fmt.Sprintf("%v", v) } -func formatPointer(v reflect.Value, conf formatConfig) string { +func formatPointer(v reflect.Value, conf FormatConfig) string { p := v.Pointer() if !conf.realPointers { p = 0 // For deterministic printing purposes @@ -251,9 +275,3 @@ func isZero(v reflect.Value) bool { } return false } - -// isExported reports whether the identifier is exported. -func isExported(id string) bool { - r, _ := utf8.DecodeRuneInString(id) - return unicode.IsUpper(r) -} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go index ea73cf1439..fe8aa27a07 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/internal/value/sort.go @@ -24,7 +24,7 @@ func SortKeys(vs []reflect.Value) []reflect.Value { // Deduplicate keys (fails for NaNs). vs2 := vs[:1] for _, v := range vs[1:] { - if v.Interface() != vs2[len(vs2)-1].Interface() { + if isLess(vs2[len(vs2)-1], v) { vs2 = append(vs2, v) } } diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/options.go b/components/engine/vendor/github.com/google/go-cmp/cmp/options.go index a4e159ac48..91d4b066e0 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/options.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/options.go @@ -38,9 +38,8 @@ type Option interface { type applicableOption interface { Option - // apply executes the option and reports whether the option was applied. - // Each option may mutate s. - apply(s *state, vx, vy reflect.Value) bool + // apply executes the option, which may mutate s or panic. + apply(s *state, vx, vy reflect.Value) } // coreOption represents the following types: @@ -85,7 +84,7 @@ func (opts Options) filter(s *state, vx, vy reflect.Value, t reflect.Type) (out return out } -func (opts Options) apply(s *state, _, _ reflect.Value) bool { +func (opts Options) apply(s *state, _, _ reflect.Value) { const warning = "ambiguous set of applicable options" const help = "consider using filters to ensure at most one Comparer or Transformer may apply" var ss []string @@ -196,7 +195,7 @@ type ignore struct{ core } func (ignore) isFiltered() bool { return false } func (ignore) filter(_ *state, _, _ reflect.Value, _ reflect.Type) applicableOption { return ignore{} } -func (ignore) apply(_ *state, _, _ reflect.Value) bool { return true } +func (ignore) apply(_ *state, _, _ reflect.Value) { return } func (ignore) String() string { return "Ignore()" } // invalid is a sentinel Option type to indicate that some options could not @@ -204,7 +203,7 @@ func (ignore) String() string type invalid struct{ core } func (invalid) filter(_ *state, _, _ reflect.Value, _ reflect.Type) applicableOption { return invalid{} } -func (invalid) apply(s *state, _, _ reflect.Value) bool { +func (invalid) apply(s *state, _, _ reflect.Value) { const help = "consider using AllowUnexported or cmpopts.IgnoreUnexported" panic(fmt.Sprintf("cannot handle unexported field: %#v\n%s", s.curPath, help)) } @@ -215,9 +214,12 @@ func (invalid) apply(s *state, _, _ reflect.Value) bool { // The transformer f must be a function "func(T) R" that converts values of // type T to those of type R and is implicitly filtered to input values // assignable to T. The transformer must not mutate T in any way. -// If T and R are the same type, an additional filter must be applied to -// act as the base case to prevent an infinite recursion applying the same -// transform to itself (see the SortedSlice example). +// +// To help prevent some cases of infinite recursive cycles applying the +// same transform to the output of itself (e.g., in the case where the +// input and output types are the same), an implicit filter is added such that +// a transformer is applicable only if that exact transformer is not already +// in the tail of the Path since the last non-Transform step. // // The name is a user provided label that is used as the Transform.Name in the // transformation PathStep. If empty, an arbitrary name is used. @@ -248,14 +250,21 @@ type transformer struct { func (tr *transformer) isFiltered() bool { return tr.typ != nil } -func (tr *transformer) filter(_ *state, _, _ reflect.Value, t reflect.Type) applicableOption { +func (tr *transformer) filter(s *state, _, _ reflect.Value, t reflect.Type) applicableOption { + for i := len(s.curPath) - 1; i >= 0; i-- { + if t, ok := s.curPath[i].(*transform); !ok { + break // Hit most recent non-Transform step + } else if tr == t.trans { + return nil // Cannot directly use same Transform + } + } if tr.typ == nil || t.AssignableTo(tr.typ) { return tr } return nil } -func (tr *transformer) apply(s *state, vx, vy reflect.Value) bool { +func (tr *transformer) apply(s *state, vx, vy reflect.Value) { // Update path before calling the Transformer so that dynamic checks // will use the updated path. s.curPath.push(&transform{pathStep{tr.fnc.Type().Out(0)}, tr}) @@ -264,7 +273,6 @@ func (tr *transformer) apply(s *state, vx, vy reflect.Value) bool { vx = s.callTRFunc(tr.fnc, vx) vy = s.callTRFunc(tr.fnc, vy) s.compareAny(vx, vy) - return true } func (tr transformer) String() string { @@ -310,10 +318,9 @@ func (cm *comparer) filter(_ *state, _, _ reflect.Value, t reflect.Type) applica return nil } -func (cm *comparer) apply(s *state, vx, vy reflect.Value) bool { +func (cm *comparer) apply(s *state, vx, vy reflect.Value) { eq := s.callTTBFunc(cm.fnc, vx, vy) s.report(eq, vx, vy) - return true } func (cm comparer) String() string { @@ -348,7 +355,7 @@ func (cm comparer) String() string { // all unexported fields on specified struct types. func AllowUnexported(types ...interface{}) Option { if !supportAllowUnexported { - panic("AllowUnexported is not supported on App Engine Classic or GopherJS") + panic("AllowUnexported is not supported on purego builds, Google App Engine Standard, or GopherJS") } m := make(map[reflect.Type]bool) for _, typ := range types { diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/path.go b/components/engine/vendor/github.com/google/go-cmp/cmp/path.go index 0c2eb333ff..c08a3cf80d 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/path.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/path.go @@ -79,6 +79,11 @@ type ( PathStep Name() string Func() reflect.Value + + // Option returns the originally constructed Transformer option. + // The == operator can be used to detect the exact option used. + Option() Option + isTransform() } ) @@ -94,10 +99,21 @@ func (pa *Path) pop() { // Last returns the last PathStep in the Path. // If the path is empty, this returns a non-nil PathStep that reports a nil Type. func (pa Path) Last() PathStep { - if len(pa) > 0 { - return pa[len(pa)-1] + return pa.Index(-1) +} + +// Index returns the ith step in the Path and supports negative indexing. +// A negative index starts counting from the tail of the Path such that -1 +// refers to the last step, -2 refers to the second-to-last step, and so on. +// If index is invalid, this returns a non-nil PathStep that reports a nil Type. +func (pa Path) Index(i int) PathStep { + if i < 0 { + i = len(pa) + i } - return pathStep{} + if i < 0 || i >= len(pa) { + return pathStep{} + } + return pa[i] } // String returns the simplified path to a node. @@ -150,13 +166,12 @@ func (pa Path) GoString() string { ssPost = append(ssPost, ")") continue case *typeAssertion: - // Elide type assertions immediately following a transform to - // prevent overly verbose path printouts. - // Some transforms return interface{} because of Go's lack of - // generics, but typically take in and return the exact same - // concrete type. Other times, the transform creates an anonymous - // struct, which will be very verbose to print. - if _, ok := nextStep.(*transform); ok { + // As a special-case, elide type assertions on anonymous types + // since they are typically generated dynamically and can be very + // verbose. For example, some transforms return interface{} because + // of Go's lack of generics, but typically take in and return the + // exact same concrete type. + if s.Type().PkgPath() == "" { continue } } @@ -250,6 +265,7 @@ func (sf structField) Name() string { return sf.name } func (sf structField) Index() int { return sf.idx } func (tf transform) Name() string { return tf.trans.name } func (tf transform) Func() reflect.Value { return tf.trans.fnc } +func (tf transform) Option() Option { return tf.trans } func (pathStep) isPathStep() {} func (sliceIndex) isSliceIndex() {} diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/reporter.go b/components/engine/vendor/github.com/google/go-cmp/cmp/reporter.go index a21d0cded2..20e9f18e0d 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/reporter.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/reporter.go @@ -30,12 +30,12 @@ func (r *defaultReporter) Report(x, y reflect.Value, eq bool, p Path) { const maxLines = 256 r.ndiffs++ if r.nbytes < maxBytes && r.nlines < maxLines { - sx := value.Format(x, true) - sy := value.Format(y, true) + sx := value.Format(x, value.FormatConfig{UseStringer: true}) + sy := value.Format(y, value.FormatConfig{UseStringer: true}) if sx == sy { - // Stringer is not helpful, so rely on more exact formatting. - sx = value.Format(x, false) - sy = value.Format(y, false) + // Unhelpful output, so use more exact formatting. + sx = value.Format(x, value.FormatConfig{PrintPrimitiveType: true}) + sy = value.Format(y, value.FormatConfig{PrintPrimitiveType: true}) } s := fmt.Sprintf("%#v:\n\t-: %s\n\t+: %s\n", p, sx, sy) r.diffs = append(r.diffs, s) @@ -49,5 +49,5 @@ func (r *defaultReporter) String() string { if r.ndiffs == len(r.diffs) { return s } - return fmt.Sprintf("%s... %d more differences ...", s, len(r.diffs)-r.ndiffs) + return fmt.Sprintf("%s... %d more differences ...", s, r.ndiffs-len(r.diffs)) } diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_panic.go b/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_panic.go index 0d44987f5b..d1518eb3a8 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_panic.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_panic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE.md file. -// +build appengine js +// +build purego appengine js package cmp diff --git a/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_reflect.go b/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_reflect.go index 81fb82632e..579b65507f 100644 --- a/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_reflect.go +++ b/components/engine/vendor/github.com/google/go-cmp/cmp/unsafe_reflect.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE.md file. -// +build !appengine,!js +// +build !purego,!appengine,!js package cmp diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/README.md b/components/engine/vendor/github.com/gotestyourself/gotestyourself/README.md index f2b68b4a23..aad893ae03 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/README.md +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/README.md @@ -30,3 +30,4 @@ patterns. ## Related * [maxbrunsfeld/counterfeiter](https://github.com/maxbrunsfeld/counterfeiter) - generate fakes for interfaces +* [jonboulle/clockwork](https://github.com/jonboulle/clockwork) - a fake clock for testing code that uses `time` diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/assert.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/assert.go index 139ea855cb..d2b05f4165 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/assert.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/assert.go @@ -1,6 +1,5 @@ -/*Package assert provides assertions and checks for comparing expected values to -actual values. When an assertion or check fails a helpful error message is -printed. +/*Package assert provides assertions for comparing expected values to actual +values. When an assertion fails a helpful error message is printed. Assert and Check @@ -23,7 +22,7 @@ The example below shows assert used with some common types. func TestEverything(t *testing.T) { // booleans - assert.Assert(t, isOk) + assert.Assert(t, ok) assert.Assert(t, !missing) // primitives @@ -33,14 +32,15 @@ The example below shows assert used with some common types. // errors assert.NilError(t, closer.Close()) - assert.Assert(t, is.Error(err, "the exact error message")) - assert.Assert(t, is.ErrorContains(err, "includes this")) + assert.Error(t, err, "the exact error message") + assert.ErrorContains(t, err, "includes this") + assert.ErrorType(t, err, os.IsNotExist) // complex types + assert.DeepEqual(t, result, myStruct{Name: "title"}) assert.Assert(t, is.Len(items, 3)) assert.Assert(t, len(sequence) != 0) // NotEmpty assert.Assert(t, is.Contains(mapping, "key")) - assert.Assert(t, is.Compare(result, myStruct{Name: "title"})) // pointers and interface assert.Assert(t, is.Nil(ref)) @@ -51,40 +51,25 @@ Comparisons https://godoc.org/github.com/gotestyourself/gotestyourself/assert/cmp provides many common comparisons. Additional comparisons can be written to compare -values in other ways. - -Below is an example of a custom comparison using a regex pattern: - - func RegexP(value string, pattern string) func() (bool, string) { - return func() (bool, string) { - re := regexp.MustCompile(pattern) - msg := fmt.Sprintf("%q did not match pattern %q", value, pattern) - return re.MatchString(value), msg - } - } +values in other ways. See the example Assert (CustomComparison). */ package assert import ( "fmt" + "go/ast" + "go/token" + gocmp "github.com/google/go-cmp/cmp" "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/internal/format" "github.com/gotestyourself/gotestyourself/internal/source" ) -// BoolOrComparison can be a bool, or Comparison. Other types will panic. +// BoolOrComparison can be a bool, or cmp.Comparison. See Assert() for usage. type BoolOrComparison interface{} -// Comparison is a function which compares values and returns true if the actual -// value matches the expected value. If the values do not match it returns a message -// with details about why it failed. -// -// https://godoc.org/github.com/gotestyourself/gotestyourself/assert/cmp -// provides many general purpose Comparisons. -type Comparison func() (success bool, message string) - // TestingT is the subset of testing.T used by the assert package. type TestingT interface { FailNow() @@ -96,84 +81,156 @@ type helperT interface { Helper() } -// stackIndex = Assert()/Check(), assert() -const stackIndex = 2 -const comparisonArgPos = 1 - const failureMessage = "assertion failed: " +// nolint: gocyclo func assert( t TestingT, failer func(), + argSelector argSelector, comparison BoolOrComparison, msgAndArgs ...interface{}, ) bool { if ht, ok := t.(helperT); ok { ht.Helper() } + var success bool switch check := comparison.(type) { case bool: if check { return true } - source, err := source.GetCondition(stackIndex, comparisonArgPos) - if err != nil { - t.Log(err.Error()) - } - - msg := " is false" - t.Log(format.WithCustomMessage(failureMessage+source+msg, msgAndArgs...)) - failer() - return false - - case Comparison: - return runCompareFunc(failer, t, check, msgAndArgs...) + logFailureFromBool(t, msgAndArgs...) + // Undocumented legacy comparison without Result type case func() (success bool, message string): - return runCompareFunc(failer, t, check, msgAndArgs...) + success = runCompareFunc(t, check, msgAndArgs...) + + case nil: + return true + + case error: + msg := "error is not nil: " + t.Log(format.WithCustomMessage(failureMessage+msg+check.Error(), msgAndArgs...)) + + case cmp.Comparison: + success = runComparison(t, argSelector, check, msgAndArgs...) + + case func() cmp.Result: + success = runComparison(t, argSelector, check, msgAndArgs...) default: - panic(fmt.Sprintf("comparison arg must be bool or Comparison, not %T", comparison)) + t.Log(fmt.Sprintf("invalid Comparison: %v (%T)", check, check)) } + + if success { + return true + } + failer() + return false } -func runCompareFunc(failer func(), t TestingT, f Comparison, msgAndArgs ...interface{}) bool { +func runCompareFunc( + t TestingT, + f func() (success bool, message string), + msgAndArgs ...interface{}, +) bool { if ht, ok := t.(helperT); ok { ht.Helper() } if success, message := f(); !success { t.Log(format.WithCustomMessage(failureMessage+message, msgAndArgs...)) - failer() return false } return true } -// Assert performs a comparison, marks the test as having failed if the comparison -// returns false, and stops execution immediately. +func logFailureFromBool(t TestingT, msgAndArgs ...interface{}) { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + const stackIndex = 3 // Assert()/Check(), assert(), formatFailureFromBool() + const comparisonArgPos = 1 + args, err := source.CallExprArgs(stackIndex) + if err != nil { + t.Log(err.Error()) + return + } + + msg, err := boolFailureMessage(args[comparisonArgPos]) + if err != nil { + t.Log(err.Error()) + msg = "expression is false" + } + + t.Log(format.WithCustomMessage(failureMessage+msg, msgAndArgs...)) +} + +func boolFailureMessage(expr ast.Expr) (string, error) { + if binaryExpr, ok := expr.(*ast.BinaryExpr); ok && binaryExpr.Op == token.NEQ { + x, err := source.FormatNode(binaryExpr.X) + if err != nil { + return "", err + } + y, err := source.FormatNode(binaryExpr.Y) + if err != nil { + return "", err + } + return x + " is " + y, nil + } + + if unaryExpr, ok := expr.(*ast.UnaryExpr); ok && unaryExpr.Op == token.NOT { + x, err := source.FormatNode(unaryExpr.X) + if err != nil { + return "", err + } + return x + " is true", nil + } + + formatted, err := source.FormatNode(expr) + if err != nil { + return "", err + } + return "expression is false: " + formatted, nil +} + +// Assert performs a comparison. If the comparison fails the test is marked as +// failed, a failure message is logged, and execution is stopped immediately. +// +// The comparison argument may be one of three types: bool, cmp.Comparison or +// error. +// When called with a bool the failure message will contain the literal source +// code of the expression. +// When called with a cmp.Comparison the comparison is responsible for producing +// a helpful failure message. +// When called with an error a nil value is considered success. A non-nil error +// is a failure, and Error() is used as the failure message. func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) { if ht, ok := t.(helperT); ok { ht.Helper() } - assert(t, t.FailNow, comparison, msgAndArgs...) + assert(t, t.FailNow, argsFromComparisonCall, comparison, msgAndArgs...) } -// Check performs a comparison and marks the test as having failed if the comparison -// returns false. Returns the result of the comparison. +// Check performs a comparison. If the comparison fails the test is marked as +// failed, a failure message is logged, and Check returns false. Otherwise returns +// true. +// +// See Assert for details about the comparison arg and failure messages. func Check(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) bool { if ht, ok := t.(helperT); ok { ht.Helper() } - return assert(t, t.Fail, comparison, msgAndArgs...) + return assert(t, t.Fail, argsFromComparisonCall, comparison, msgAndArgs...) } -// NilError fails the test immediately if the last arg is a non-nil error. -// This is equivalent to Assert(t, cmp.NilError(err)). +// NilError fails the test immediately if err is not nil. +// This is equivalent to Assert(t, err) func NilError(t TestingT, err error, msgAndArgs ...interface{}) { if ht, ok := t.(helperT); ok { ht.Helper() } - assert(t, t.FailNow, cmp.NilError(err), msgAndArgs...) + assert(t, t.FailNow, argsAfterT, err, msgAndArgs...) } // Equal uses the == operator to assert two values are equal and fails the test @@ -182,5 +239,51 @@ func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) { if ht, ok := t.(helperT); ok { ht.Helper() } - assert(t, t.FailNow, cmp.Equal(x, y), msgAndArgs...) + assert(t, t.FailNow, argsAfterT, cmp.Equal(x, y), msgAndArgs...) +} + +// DeepEqual uses https://github.com/google/go-cmp/cmp to assert two values +// are equal and fails the test if they are not equal. +// This is equivalent to Assert(t, cmp.DeepEqual(x, y)). +func DeepEqual(t TestingT, x, y interface{}, opts ...gocmp.Option) { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + assert(t, t.FailNow, argsAfterT, cmp.DeepEqual(x, y, opts...)) +} + +// Error fails the test if err is nil, or the error message is not the expected +// message. +// Equivalent to Assert(t, cmp.Error(err, message)). +func Error(t TestingT, err error, message string, msgAndArgs ...interface{}) { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + assert(t, t.FailNow, argsAfterT, cmp.Error(err, message), msgAndArgs...) +} + +// ErrorContains fails the test if err is nil, or the error message does not +// contain the expected substring. +// Equivalent to Assert(t, cmp.ErrorContains(err, substring)). +func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interface{}) { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + assert(t, t.FailNow, argsAfterT, cmp.ErrorContains(err, substring), msgAndArgs...) +} + +// ErrorType fails the test if err is nil, or err is not the expected type. +// +// Expected can be one of: +// a func(error) bool which returns true if the error is the expected type, +// an instance of a struct of the expected type, +// a pointer to an interface the error is expected to implement, +// a reflect.Type of the expected struct or interface. +// +// Equivalent to Assert(t, cmp.ErrorType(err, expected)). +func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + assert(t, t.FailNow, argsAfterT, cmp.ErrorType(err, expected), msgAndArgs...) } diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/compare.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/compare.go index c30b28b9f0..64a25f00b3 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/compare.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/compare.go @@ -10,53 +10,113 @@ import ( "github.com/pmezard/go-difflib/difflib" ) -// Compare two complex values using https://godoc.org/github.com/google/go-cmp/cmp +// Comparison is a function which compares values and returns ResultSuccess if +// the actual value matches the expected value. If the values do not match the +// Result will contain a message about why it failed. +type Comparison func() Result + +// DeepEqual compares two values using https://godoc.org/github.com/google/go-cmp/cmp // and succeeds if the values are equal. // // The comparison can be customized using comparison Options. -func Compare(x, y interface{}, opts ...cmp.Option) func() (bool, string) { - return func() (bool, string) { +func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison { + return func() (result Result) { + defer func() { + if panicmsg, handled := handleCmpPanic(recover()); handled { + result = ResultFailure(panicmsg) + } + }() diff := cmp.Diff(x, y, opts...) - return diff == "", "\n" + diff + return toResult(diff == "", "\n"+diff) } } +func handleCmpPanic(r interface{}) (string, bool) { + if r == nil { + return "", false + } + panicmsg, ok := r.(string) + if !ok { + panic(r) + } + switch { + case strings.HasPrefix(panicmsg, "cannot handle unexported field"): + return panicmsg, true + } + panic(r) +} + +func toResult(success bool, msg string) Result { + if success { + return ResultSuccess + } + return ResultFailure(msg) +} + // Equal succeeds if x == y. -func Equal(x, y interface{}) func() (success bool, message string) { - return func() (bool, string) { - return x == y, fmt.Sprintf("%v (%T) != %v (%T)", x, x, y, y) +func Equal(x, y interface{}) Comparison { + return func() Result { + switch { + case x == y: + return ResultSuccess + case isMultiLineStringCompare(x, y): + return multiLineStringDiffResult(x.(string), y.(string)) + } + return ResultFailureTemplate(` + {{- .Data.x}} ( + {{- with callArg 0 }}{{ formatNode . }} {{end -}} + {{- printf "%T" .Data.x -}} + ) != {{ .Data.y}} ( + {{- with callArg 1 }}{{ formatNode . }} {{end -}} + {{- printf "%T" .Data.y -}} + )`, + map[string]interface{}{"x": x, "y": y}) } } +func isMultiLineStringCompare(x, y interface{}) bool { + strX, ok := x.(string) + if !ok { + return false + } + strY, ok := y.(string) + if !ok { + return false + } + return strings.Contains(strX, "\n") || strings.Contains(strY, "\n") +} + +func multiLineStringDiffResult(x, y string) Result { + diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ + A: difflib.SplitLines(x), + B: difflib.SplitLines(y), + Context: 3, + }) + if err != nil { + return ResultFailure(fmt.Sprintf("failed to diff: %s", err)) + } + return ResultFailureTemplate(` +--- {{ with callArg 0 }}{{ formatNode . }}{{else}}←{{end}} ++++ {{ with callArg 1 }}{{ formatNode . }}{{else}}→{{end}} +{{ .Data.diff }}`, + map[string]interface{}{"diff": diff}) +} + // Len succeeds if the sequence has the expected length. -func Len(seq interface{}, expected int) func() (bool, string) { - return func() (success bool, message string) { +func Len(seq interface{}, expected int) Comparison { + return func() (result Result) { defer func() { if e := recover(); e != nil { - success = false - message = fmt.Sprintf("type %T does not have a length", seq) + result = ResultFailure(fmt.Sprintf("type %T does not have a length", seq)) } }() value := reflect.ValueOf(seq) length := value.Len() if length == expected { - return true, "" + return ResultSuccess } msg := fmt.Sprintf("expected %s (length %d) to have length %d", seq, length, expected) - return false, msg - } -} - -// NilError succeeds if the last argument is a nil error. -func NilError(arg interface{}, args ...interface{}) func() (bool, string) { - return func() (bool, string) { - msgFunc := func(value reflect.Value) string { - return fmt.Sprintf("error is not nil: %s", value.Interface().(error).Error()) - } - if len(args) == 0 { - return isNil(arg, msgFunc)() - } - return isNil(args[len(args)-1], msgFunc)() + return ResultFailure(msg) } } @@ -68,11 +128,11 @@ func NilError(arg interface{}, args ...interface{}) func() (bool, string) { // If collection is a Map, contains will succeed if item is a key in the map. // If collection is a slice or array, item is compared to each item in the // sequence using reflect.DeepEqual(). -func Contains(collection interface{}, item interface{}) func() (bool, string) { - return func() (bool, string) { +func Contains(collection interface{}, item interface{}) Comparison { + return func() Result { colValue := reflect.ValueOf(collection) if !colValue.IsValid() { - return false, fmt.Sprintf("nil does not contain items") + return ResultFailure(fmt.Sprintf("nil does not contain items")) } msg := fmt.Sprintf("%v does not contain %v", collection, item) @@ -80,94 +140,72 @@ func Contains(collection interface{}, item interface{}) func() (bool, string) { switch colValue.Type().Kind() { case reflect.String: if itemValue.Type().Kind() != reflect.String { - return false, "string may only contain strings" + return ResultFailure("string may only contain strings") } - success := strings.Contains(colValue.String(), itemValue.String()) - return success, fmt.Sprintf("string %q does not contain %q", collection, item) + return toResult( + strings.Contains(colValue.String(), itemValue.String()), + fmt.Sprintf("string %q does not contain %q", collection, item)) case reflect.Map: if itemValue.Type() != colValue.Type().Key() { - return false, fmt.Sprintf( - "%v can not contain a %v key", colValue.Type(), itemValue.Type()) + return ResultFailure(fmt.Sprintf( + "%v can not contain a %v key", colValue.Type(), itemValue.Type())) } - index := colValue.MapIndex(itemValue) - return index.IsValid(), msg + return toResult(colValue.MapIndex(itemValue).IsValid(), msg) case reflect.Slice, reflect.Array: for i := 0; i < colValue.Len(); i++ { if reflect.DeepEqual(colValue.Index(i).Interface(), item) { - return true, "" + return ResultSuccess } } - return false, msg + return ResultFailure(msg) default: - return false, fmt.Sprintf("type %T does not contain items", collection) + return ResultFailure(fmt.Sprintf("type %T does not contain items", collection)) } } } // Panics succeeds if f() panics. -func Panics(f func()) func() (bool, string) { - return func() (success bool, message string) { +func Panics(f func()) Comparison { + return func() (result Result) { defer func() { if err := recover(); err != nil { - success = true + result = ResultSuccess } }() f() - return false, "did not panic" - } -} - -// EqualMultiLine succeeds if the two strings are equal. If they are not equal -// the failure message will be the difference between the two strings. -func EqualMultiLine(x, y string) func() (bool, string) { - return func() (bool, string) { - if x == y { - return true, "" - } - - diff, err := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ - A: difflib.SplitLines(x), - B: difflib.SplitLines(y), - FromFile: "left", - ToFile: "right", - Context: 3, - }) - if err != nil { - return false, fmt.Sprintf("failed to produce diff: %s", err) - } - return false, "\n" + diff + return ResultFailure("did not panic") } } // Error succeeds if err is a non-nil error, and the error message equals the // expected message. -func Error(err error, message string) func() (bool, string) { - return func() (bool, string) { +func Error(err error, message string) Comparison { + return func() Result { switch { case err == nil: - return false, "expected an error, got nil" + return ResultFailure("expected an error, got nil") case err.Error() != message: - return false, fmt.Sprintf( - "expected error message %q, got %q", message, err.Error()) + return ResultFailure(fmt.Sprintf( + "expected error %q, got %+v", message, err)) } - return true, "" + return ResultSuccess } } // ErrorContains succeeds if err is a non-nil error, and the error message contains // the expected substring. -func ErrorContains(err error, substring string) func() (bool, string) { - return func() (bool, string) { +func ErrorContains(err error, substring string) Comparison { + return func() Result { switch { case err == nil: - return false, "expected an error, got nil" + return ResultFailure("expected an error, got nil") case !strings.Contains(err.Error(), substring): - return false, fmt.Sprintf( - "expected error message to contain %q, got %q", substring, err.Error()) + return ResultFailure(fmt.Sprintf( + "expected error to contain %q, got %+v", substring, err)) } - return true, "" + return ResultSuccess } } @@ -175,27 +213,98 @@ func ErrorContains(err error, substring string) func() (bool, string) { // // Use NilError() for comparing errors. Use Len(obj, 0) for comparing slices, // maps, and channels. -func Nil(obj interface{}) func() (bool, string) { +func Nil(obj interface{}) Comparison { msgFunc := func(value reflect.Value) string { return fmt.Sprintf("%v (type %s) is not nil", reflect.Indirect(value), value.Type()) } return isNil(obj, msgFunc) } -func isNil(obj interface{}, msgFunc func(reflect.Value) string) func() (bool, string) { - return func() (bool, string) { +func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison { + return func() Result { if obj == nil { - return true, "" + return ResultSuccess } value := reflect.ValueOf(obj) kind := value.Type().Kind() if kind >= reflect.Chan && kind <= reflect.Slice { if value.IsNil() { - return true, "" + return ResultSuccess } - return false, msgFunc(value) + return ResultFailure(msgFunc(value)) } - return false, fmt.Sprintf("%v (type %s) can not be nil", value, value.Type()) + return ResultFailure(fmt.Sprintf("%v (type %s) can not be nil", value, value.Type())) } } + +// ErrorType succeeds if err is not nil and is of the expected type. +// +// Expected can be one of: +// a func(error) bool which returns true if the error is the expected type, +// an instance of a struct of the expected type, +// a pointer to an interface the error is expected to implement, +// a reflect.Type of the expected struct or interface. +func ErrorType(err error, expected interface{}) Comparison { + return func() Result { + switch expectedType := expected.(type) { + case func(error) bool: + return cmpErrorTypeFunc(err, expectedType) + case reflect.Type: + if expectedType.Kind() == reflect.Interface { + return cmpErrorTypeImplementsType(err, expectedType) + } + return cmpErrorTypeEqualType(err, expectedType) + case nil: + return ResultFailure(fmt.Sprintf("invalid type for expected: nil")) + } + + expectedType := reflect.TypeOf(expected) + switch { + case expectedType.Kind() == reflect.Struct: + return cmpErrorTypeEqualType(err, expectedType) + case isPtrToInterface(expectedType): + return cmpErrorTypeImplementsType(err, expectedType.Elem()) + } + return ResultFailure(fmt.Sprintf("invalid type for expected: %T", expected)) + } +} + +func cmpErrorTypeFunc(err error, f func(error) bool) Result { + if f(err) { + return ResultSuccess + } + actual := "nil" + if err != nil { + actual = fmt.Sprintf("%s (%T)", err, err) + } + return ResultFailureTemplate(`error is {{ .Data.actual }} + {{- with callArg 1 }}, not {{ formatNode . }}{{end -}}`, + map[string]interface{}{"actual": actual}) +} + +func cmpErrorTypeEqualType(err error, expectedType reflect.Type) Result { + if err == nil { + return ResultFailure(fmt.Sprintf("error is nil, not %s", expectedType)) + } + errValue := reflect.ValueOf(err) + if errValue.Type() == expectedType { + return ResultSuccess + } + return ResultFailure(fmt.Sprintf("error is %s (%T), not %s", err, err, expectedType)) +} + +func cmpErrorTypeImplementsType(err error, expectedType reflect.Type) Result { + if err == nil { + return ResultFailure(fmt.Sprintf("error is nil, not %s", expectedType)) + } + errValue := reflect.ValueOf(err) + if errValue.Type().Implements(expectedType) { + return ResultSuccess + } + return ResultFailure(fmt.Sprintf("error is %s (%T), not %s", err, err, expectedType)) +} + +func isPtrToInterface(typ reflect.Type) bool { + return typ.Kind() == reflect.Ptr && typ.Elem().Kind() == reflect.Interface +} diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/result.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/result.go new file mode 100644 index 0000000000..99f39eeb27 --- /dev/null +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/cmp/result.go @@ -0,0 +1,94 @@ +package cmp + +import ( + "bytes" + "fmt" + "go/ast" + "text/template" + + "github.com/gotestyourself/gotestyourself/internal/source" +) + +// Result of a Comparison. +type Result interface { + Success() bool +} + +type result struct { + success bool + message string +} + +func (r result) Success() bool { + return r.success +} + +func (r result) FailureMessage() string { + return r.message +} + +// ResultSuccess is a constant which is returned by a ComparisonWithResult to +// indicate success. +var ResultSuccess = result{success: true} + +// ResultFailure returns a failed Result with a failure message. +func ResultFailure(message string) Result { + return result{message: message} +} + +// ResultFromError returns ResultSuccess if err is nil. Otherwise ResultFailure +// is returned with the error message as the failure message. +func ResultFromError(err error) Result { + if err == nil { + return ResultSuccess + } + return ResultFailure(err.Error()) +} + +type templatedResult struct { + success bool + template string + data map[string]interface{} +} + +func (r templatedResult) Success() bool { + return r.success +} + +func (r templatedResult) FailureMessage(args []ast.Expr) string { + msg, err := renderMessage(r, args) + if err != nil { + return fmt.Sprintf("failed to render failure message: %s", err) + } + return msg +} + +// ResultFailureTemplate returns a Result with a template string and data which +// can be used to format a failure message. The template may access data from .Data, +// the comparison args with the callArg function, and the formatNode function may +// be used to format the call args. +func ResultFailureTemplate(template string, data map[string]interface{}) Result { + return templatedResult{template: template, data: data} +} + +func renderMessage(result templatedResult, args []ast.Expr) (string, error) { + tmpl := template.New("failure").Funcs(template.FuncMap{ + "formatNode": source.FormatNode, + "callArg": func(index int) ast.Expr { + if index >= len(args) { + return nil + } + return args[index] + }, + }) + var err error + tmpl, err = tmpl.Parse(result.template) + if err != nil { + return "", err + } + buf := new(bytes.Buffer) + err = tmpl.Execute(buf, map[string]interface{}{ + "Data": result.data, + }) + return buf.String(), err +} diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/result.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/result.go new file mode 100644 index 0000000000..b685b7f3e5 --- /dev/null +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/assert/result.go @@ -0,0 +1,107 @@ +package assert + +import ( + "fmt" + "go/ast" + + "github.com/gotestyourself/gotestyourself/assert/cmp" + "github.com/gotestyourself/gotestyourself/internal/format" + "github.com/gotestyourself/gotestyourself/internal/source" +) + +func runComparison( + t TestingT, + argSelector argSelector, + f cmp.Comparison, + msgAndArgs ...interface{}, +) bool { + if ht, ok := t.(helperT); ok { + ht.Helper() + } + result := f() + if result.Success() { + return true + } + + var message string + switch typed := result.(type) { + case resultWithComparisonArgs: + const stackIndex = 3 // Assert/Check, assert, runComparison + args, err := source.CallExprArgs(stackIndex) + if err != nil { + t.Log(err.Error()) + } + message = typed.FailureMessage(filterPrintableExpr(argSelector(args))) + case resultBasic: + message = typed.FailureMessage() + default: + message = fmt.Sprintf("comparison returned invalid Result type: %T", result) + } + + t.Log(format.WithCustomMessage(failureMessage+message, msgAndArgs...)) + return false +} + +type resultWithComparisonArgs interface { + FailureMessage(args []ast.Expr) string +} + +type resultBasic interface { + FailureMessage() string +} + +// filterPrintableExpr filters the ast.Expr slice to only include Expr that are +// easy to read when printed and contain relevant information to an assertion. +// +// Ident and SelectorExpr are included because they print nicely and the variable +// names may provide additional context to their values. +// BasicLit and CompositeLit are excluded because their source is equivalent to +// their value, which is already available. +// Other types are ignored for now, but could be added if they are relevant. +func filterPrintableExpr(args []ast.Expr) []ast.Expr { + result := make([]ast.Expr, len(args)) + for i, arg := range args { + if isShortPrintableExpr(arg) { + result[i] = arg + continue + } + + if starExpr, ok := arg.(*ast.StarExpr); ok { + result[i] = starExpr.X + continue + } + result[i] = nil + } + return result +} + +func isShortPrintableExpr(expr ast.Expr) bool { + switch expr.(type) { + case *ast.Ident, *ast.SelectorExpr, *ast.IndexExpr, *ast.SliceExpr: + return true + case *ast.BinaryExpr, *ast.UnaryExpr: + return true + default: + // CallExpr, ParenExpr, TypeAssertExpr, KeyValueExpr, StarExpr + return false + } +} + +type argSelector func([]ast.Expr) []ast.Expr + +func argsAfterT(args []ast.Expr) []ast.Expr { + if len(args) < 1 { + return nil + } + return args[1:] +} + +func argsFromComparisonCall(args []ast.Expr) []ast.Expr { + if len(args) < 1 { + return nil + } + if callExpr, ok := args[1].(*ast.CallExpr); ok { + return callExpr.Args + } + return nil +} diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/env/env.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/env/env.go index 95a53bee9c..700430f1dd 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/env/env.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/env/env.go @@ -45,7 +45,7 @@ func PatchAll(t assert.TestingT, env map[string]string) func() { os.Clearenv() for key, value := range env { - assert.NilError(t, os.Setenv(key, value)) + assert.NilError(t, os.Setenv(key, value), "setenv %s=%s", key, value) } return func() { if ht, ok := t.(helperT); ok { @@ -53,7 +53,7 @@ func PatchAll(t assert.TestingT, env map[string]string) func() { } os.Clearenv() for key, oldVal := range ToMap(oldEnv) { - assert.NilError(t, os.Setenv(key, oldVal)) + assert.NilError(t, os.Setenv(key, oldVal), "setenv %s=%s", key, oldVal) } } } @@ -63,17 +63,23 @@ func PatchAll(t assert.TestingT, env map[string]string) func() { func ToMap(env []string) map[string]string { result := map[string]string{} for _, raw := range env { - parts := strings.SplitN(raw, "=", 2) - switch len(parts) { - case 1: - result[raw] = "" - case 2: - result[parts[0]] = parts[1] - } + key, value := getParts(raw) + result[key] = value } return result } +func getParts(raw string) (string, string) { + // Environment variables on windows can begin with = + // http://blogs.msdn.com/b/oldnewthing/archive/2010/05/06/10008132.aspx + parts := strings.SplitN(raw[1:], "=", 2) + key := raw[:1] + parts[0] + if len(parts) == 1 { + return key, "" + } + return key, parts[1] +} + // ChangeWorkingDir to the directory, and return a function which restores the // previous working directory. func ChangeWorkingDir(t assert.TestingT, dir string) func() { diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/fs/ops.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/fs/ops.go index 7cc63994c8..bf9d2150b3 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/fs/ops.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/fs/ops.go @@ -4,6 +4,7 @@ import ( "io/ioutil" "os" "path/filepath" + "time" ) // PathOp is a function which accepts a Path to perform some operation @@ -125,3 +126,33 @@ func copyFile(source, dest string) error { } return ioutil.WriteFile(dest, content, 0644) } + +// WithSymlink creates a symlink in the directory which links to target. +// Target must be a path relative to the directory. +// +// Note: the argument order is the inverse of os.Symlink to be consistent with +// the other functions in this package. +func WithSymlink(path, target string) PathOp { + return func(root Path) error { + return os.Symlink(filepath.Join(root.Path(), target), filepath.Join(root.Path(), path)) + } +} + +// WithHardlink creates a link in the directory which links to target. +// Target must be a path relative to the directory. +// +// Note: the argument order is the inverse of os.Link to be consistent with +// the other functions in this package. +func WithHardlink(path, target string) PathOp { + return func(root Path) error { + return os.Link(filepath.Join(root.Path(), target), filepath.Join(root.Path(), path)) + } +} + +// WithTimestamps sets the access and modification times of the file system object +// at path. +func WithTimestamps(atime, mtime time.Time) PathOp { + return func(root Path) error { + return os.Chtimes(root.Path(), atime, mtime) + } +} diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/icmd/command.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/icmd/command.go index 379f13c815..0066c51514 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/icmd/command.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/icmd/command.go @@ -10,11 +10,10 @@ import ( "strings" "sync" "time" -) -type testingT interface { - Fatalf(string, ...interface{}) -} + "github.com/gotestyourself/gotestyourself/assert" + "github.com/gotestyourself/gotestyourself/assert/cmp" +) type helperT interface { Helper() @@ -53,23 +52,32 @@ type Result struct { // Assert compares the Result against the Expected struct, and fails the test if // any of the expectations are not met. -// TODO: deprecate and replace with assert.CompareFunc -func (r *Result) Assert(t testingT, exp Expected) *Result { +// +// This function is equivalent to assert.Assert(t, result.Equal(exp)). +func (r *Result) Assert(t assert.TestingT, exp Expected) *Result { if ht, ok := t.(helperT); ok { ht.Helper() } - err := r.Compare(exp) - if err == nil { - return r - } - t.Fatalf(err.Error() + "\n") - return nil + assert.Assert(t, r.Equal(exp)) + return r } -// Compare returns a formatted error with the command, stdout, stderr, exit -// code, and any failed expectations -// nolint: gocyclo +// Equal compares the result to Expected. If the result doesn't match expected +// returns a formatted failure message with the command, stdout, stderr, exit code, +// and any failed expectations. +func (r *Result) Equal(exp Expected) cmp.Comparison { + return func() cmp.Result { + return cmp.ResultFromError(r.match(exp)) + } +} + +// Compare the result to Expected and return an error if they do not match. func (r *Result) Compare(exp Expected) error { + return r.match(exp) +} + +// nolint: gocyclo +func (r *Result) match(exp Expected) error { errors := []string{} add := func(format string, args ...interface{}) { errors = append(errors, fmt.Sprintf(format, args...)) diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/internal/source/source.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/internal/source/source.go index 46f484bc82..f71c5129b8 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/internal/source/source.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/internal/source/source.go @@ -2,31 +2,29 @@ package source import ( "bytes" + "fmt" "go/ast" "go/format" "go/parser" "go/token" + "os" "runtime" + "strconv" + "strings" "github.com/pkg/errors" ) const baseStackIndex = 1 -// GetCondition returns the condition string by reading it from the file -// identified in the callstack. In golang 1.9 the line number changed from -// being the line where the statement ended to the line where the statement began. -func GetCondition(stackIndex int, argPos int) (string, error) { - _, filename, lineNum, ok := runtime.Caller(baseStackIndex + stackIndex) - if !ok { - return "", errors.New("failed to get caller info") - } - - node, err := getNodeAtLine(filename, lineNum) +// FormattedCallExprArg returns the argument from an ast.CallExpr at the +// index in the call stack. The argument is formatted using FormatNode. +func FormattedCallExprArg(stackIndex int, argPos int) (string, error) { + args, err := CallExprArgs(stackIndex + 1) if err != nil { return "", err } - return getArgSourceFromAST(node, argPos) + return FormatNode(args[argPos]) } func getNodeAtLine(filename string, lineNum int) (ast.Node, error) { @@ -38,7 +36,7 @@ func getNodeAtLine(filename string, lineNum int) (ast.Node, error) { node := scanToLine(fileset, astFile, lineNum) if node == nil { - return nil, errors.Wrapf(err, + return nil, errors.Errorf( "failed to find an expression on line %d in %s", lineNum, filename) } return node, nil @@ -60,32 +58,46 @@ func (v *scanToLineVisitor) Visit(node ast.Node) ast.Visitor { if node == nil || v.matchedNode != nil { return nil } - - var position token.Position - switch { - case runtime.Version() < "go1.9": - position = v.fileset.Position(node.End()) - default: - position = v.fileset.Position(node.Pos()) - } - - if position.Line == v.lineNum { + if v.nodePosition(node).Line == v.lineNum { v.matchedNode = node return nil } return v } -func getArgSourceFromAST(node ast.Node, argPos int) (string, error) { +// In golang 1.9 the line number changed from being the line where the statement +// ended to the line where the statement began. +func (v *scanToLineVisitor) nodePosition(node ast.Node) token.Position { + if goVersionBefore19 { + return v.fileset.Position(node.End()) + } + return v.fileset.Position(node.Pos()) +} + +var goVersionBefore19 = isGOVersionBefore19() + +func isGOVersionBefore19() bool { + version := runtime.Version() + // not a release version + if !strings.HasPrefix(version, "go") { + return false + } + version = strings.TrimPrefix(version, "go") + parts := strings.Split(version, ".") + if len(parts) < 2 { + return false + } + minor, err := strconv.ParseInt(parts[1], 10, 32) + return err == nil && parts[0] == "1" && minor < 9 +} + +func getCallExprArgs(node ast.Node) ([]ast.Expr, error) { visitor := &callExprVisitor{} ast.Walk(visitor, node) if visitor.expr == nil { - return "", errors.Errorf("unexpected ast") + return nil, errors.New("failed to find call expression") } - - buf := new(bytes.Buffer) - err := format.Node(buf, token.NewFileSet(), visitor.expr.Args[argPos]) - return buf.String(), err + return visitor.expr.Args, nil } type callExprVisitor struct { @@ -93,17 +105,59 @@ type callExprVisitor struct { } func (v *callExprVisitor) Visit(node ast.Node) ast.Visitor { - switch typed := node.(type) { - case nil: + if v.expr != nil || node == nil { return nil - case *ast.IfStmt: - ast.Walk(v, typed.Cond) - case *ast.CallExpr: - v.expr = typed } + debug("visit (%T): %s", node, debugFormatNode{node}) - if v.expr != nil { + if callExpr, ok := node.(*ast.CallExpr); ok { + v.expr = callExpr return nil } return v } + +// FormatNode using go/format.Node and return the result as a string +func FormatNode(node ast.Node) (string, error) { + buf := new(bytes.Buffer) + err := format.Node(buf, token.NewFileSet(), node) + return buf.String(), err +} + +// CallExprArgs returns the ast.Expr slice for the args of an ast.CallExpr at +// the index in the call stack. +func CallExprArgs(stackIndex int) ([]ast.Expr, error) { + _, filename, lineNum, ok := runtime.Caller(baseStackIndex + stackIndex) + if !ok { + return nil, errors.New("failed to get call stack") + } + debug("call stack position: %s:%d", filename, lineNum) + + node, err := getNodeAtLine(filename, lineNum) + if err != nil { + return nil, err + } + debug("found node (%T): %s", node, debugFormatNode{node}) + + return getCallExprArgs(node) +} + +var debugEnabled = os.Getenv("GOTESTYOURSELF_DEBUG") != "" + +func debug(format string, args ...interface{}) { + if debugEnabled { + fmt.Fprintf(os.Stderr, "DEBUG: "+format+"\n", args...) + } +} + +type debugFormatNode struct { + ast.Node +} + +func (n debugFormatNode) String() string { + out, err := FormatNode(n.Node) + if err != nil { + return fmt.Sprintf("failed to format %s: %s", n.Node, err) + } + return out +} diff --git a/components/engine/vendor/github.com/gotestyourself/gotestyourself/skip/skip.go b/components/engine/vendor/github.com/gotestyourself/gotestyourself/skip/skip.go index 3891112fa9..46ab288819 100644 --- a/components/engine/vendor/github.com/gotestyourself/gotestyourself/skip/skip.go +++ b/components/engine/vendor/github.com/gotestyourself/gotestyourself/skip/skip.go @@ -72,7 +72,7 @@ func ifCondition(t skipT, condition bool, msgAndArgs ...interface{}) { stackIndex = 2 argPos = 1 ) - source, err := source.GetCondition(stackIndex, argPos) + source, err := source.FormattedCallExprArg(stackIndex, argPos) if err != nil { t.Log(err.Error()) t.Skip(format.Message(msgAndArgs...)) diff --git a/components/engine/vendor/github.com/stretchr/testify/LICENSE b/components/engine/vendor/github.com/stretchr/testify/LICENSE deleted file mode 100644 index 473b670a7c..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell - -Please consider promoting this project if you find it useful. - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without restriction, -including without limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of the Software, -and to permit persons to whom the Software is furnished to do so, -subject to the following conditions: - -The above copyright notice and this permission notice shall be included -in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT -OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE -OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/components/engine/vendor/github.com/stretchr/testify/README.md b/components/engine/vendor/github.com/stretchr/testify/README.md deleted file mode 100644 index e57b1811f0..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/README.md +++ /dev/null @@ -1,332 +0,0 @@ -Testify - Thou Shalt Write Tests -================================ - -[![Build Status](https://travis-ci.org/stretchr/testify.svg)](https://travis-ci.org/stretchr/testify) [![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/testify)](https://goreportcard.com/report/github.com/stretchr/testify) [![GoDoc](https://godoc.org/github.com/stretchr/testify?status.svg)](https://godoc.org/github.com/stretchr/testify) - -Go code (golang) set of packages that provide many tools for testifying that your code will behave as you intend. - -Features include: - - * [Easy assertions](#assert-package) - * [Mocking](#mock-package) - * [HTTP response trapping](#http-package) - * [Testing suite interfaces and functions](#suite-package) - -Get started: - - * Install testify with [one line of code](#installation), or [update it with another](#staying-up-to-date) - * For an introduction to writing test code in Go, see http://golang.org/doc/code.html#Testing - * Check out the API Documentation http://godoc.org/github.com/stretchr/testify - * To make your testing life easier, check out our other project, [gorc](http://github.com/stretchr/gorc) - * A little about [Test-Driven Development (TDD)](http://en.wikipedia.org/wiki/Test-driven_development) - - - -[`assert`](http://godoc.org/github.com/stretchr/testify/assert "API documentation") package -------------------------------------------------------------------------------------------- - -The `assert` package provides some helpful methods that allow you to write better test code in Go. - - * Prints friendly, easy to read failure descriptions - * Allows for very readable code - * Optionally annotate each assertion with a message - -See it in action: - -```go -package yours - -import ( - "testing" - "github.com/stretchr/testify/assert" -) - -func TestSomething(t *testing.T) { - - // assert equality - assert.Equal(t, 123, 123, "they should be equal") - - // assert inequality - assert.NotEqual(t, 123, 456, "they should not be equal") - - // assert for nil (good for errors) - assert.Nil(t, object) - - // assert for not nil (good when you expect something) - if assert.NotNil(t, object) { - - // now we know that object isn't nil, we are safe to make - // further assertions without causing any errors - assert.Equal(t, "Something", object.Value) - - } - -} -``` - - * Every assert func takes the `testing.T` object as the first argument. This is how it writes the errors out through the normal `go test` capabilities. - * Every assert func returns a bool indicating whether the assertion was successful or not, this is useful for if you want to go on making further assertions under certain conditions. - -if you assert many times, use the below: - -```go -package yours - -import ( - "testing" - "github.com/stretchr/testify/assert" -) - -func TestSomething(t *testing.T) { - assert := assert.New(t) - - // assert equality - assert.Equal(123, 123, "they should be equal") - - // assert inequality - assert.NotEqual(123, 456, "they should not be equal") - - // assert for nil (good for errors) - assert.Nil(object) - - // assert for not nil (good when you expect something) - if assert.NotNil(object) { - - // now we know that object isn't nil, we are safe to make - // further assertions without causing any errors - assert.Equal("Something", object.Value) - } -} -``` - -[`require`](http://godoc.org/github.com/stretchr/testify/require "API documentation") package ---------------------------------------------------------------------------------------------- - -The `require` package provides same global functions as the `assert` package, but instead of returning a boolean result they terminate current test. - -See [t.FailNow](http://golang.org/pkg/testing/#T.FailNow) for details. - - -[`http`](http://godoc.org/github.com/stretchr/testify/http "API documentation") package ---------------------------------------------------------------------------------------- - -The `http` package contains test objects useful for testing code that relies on the `net/http` package. Check out the [(deprecated) API documentation for the `http` package](http://godoc.org/github.com/stretchr/testify/http). - -We recommend you use [httptest](http://golang.org/pkg/net/http/httptest) instead. - -[`mock`](http://godoc.org/github.com/stretchr/testify/mock "API documentation") package ----------------------------------------------------------------------------------------- - -The `mock` package provides a mechanism for easily writing mock objects that can be used in place of real objects when writing test code. - -An example test function that tests a piece of code that relies on an external object `testObj`, can setup expectations (testify) and assert that they indeed happened: - -```go -package yours - -import ( - "testing" - "github.com/stretchr/testify/mock" -) - -/* - Test objects -*/ - -// MyMockedObject is a mocked object that implements an interface -// that describes an object that the code I am testing relies on. -type MyMockedObject struct{ - mock.Mock -} - -// DoSomething is a method on MyMockedObject that implements some interface -// and just records the activity, and returns what the Mock object tells it to. -// -// In the real object, this method would do something useful, but since this -// is a mocked object - we're just going to stub it out. -// -// NOTE: This method is not being tested here, code that uses this object is. -func (m *MyMockedObject) DoSomething(number int) (bool, error) { - - args := m.Called(number) - return args.Bool(0), args.Error(1) - -} - -/* - Actual test functions -*/ - -// TestSomething is an example of how to use our test object to -// make assertions about some target code we are testing. -func TestSomething(t *testing.T) { - - // create an instance of our test object - testObj := new(MyMockedObject) - - // setup expectations - testObj.On("DoSomething", 123).Return(true, nil) - - // call the code we are testing - targetFuncThatDoesSomethingWithObj(testObj) - - // assert that the expectations were met - testObj.AssertExpectations(t) - -} -``` - -For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/stretchr/testify/mock). - -You can use the [mockery tool](http://github.com/vektra/mockery) to autogenerate the mock code against an interface as well, making using mocks much quicker. - -[`suite`](http://godoc.org/github.com/stretchr/testify/suite "API documentation") package ------------------------------------------------------------------------------------------ - -The `suite` package provides functionality that you might be used to from more common object oriented languages. With it, you can build a testing suite as a struct, build setup/teardown methods and testing methods on your struct, and run them with 'go test' as per normal. - -An example suite is shown below: - -```go -// Basic imports -import ( - "testing" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/suite" -) - -// Define the suite, and absorb the built-in basic suite -// functionality from testify - including a T() method which -// returns the current testing context -type ExampleTestSuite struct { - suite.Suite - VariableThatShouldStartAtFive int -} - -// Make sure that VariableThatShouldStartAtFive is set to five -// before each test -func (suite *ExampleTestSuite) SetupTest() { - suite.VariableThatShouldStartAtFive = 5 -} - -// All methods that begin with "Test" are run as tests within a -// suite. -func (suite *ExampleTestSuite) TestExample() { - assert.Equal(suite.T(), 5, suite.VariableThatShouldStartAtFive) -} - -// In order for 'go test' to run this suite, we need to create -// a normal test function and pass our suite to suite.Run -func TestExampleTestSuite(t *testing.T) { - suite.Run(t, new(ExampleTestSuite)) -} -``` - -For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/stretchr/testify/blob/master/suite/suite_test.go) - -For more information on writing suites, check out the [API documentation for the `suite` package](http://godoc.org/github.com/stretchr/testify/suite). - -`Suite` object has assertion methods: - -```go -// Basic imports -import ( - "testing" - "github.com/stretchr/testify/suite" -) - -// Define the suite, and absorb the built-in basic suite -// functionality from testify - including assertion methods. -type ExampleTestSuite struct { - suite.Suite - VariableThatShouldStartAtFive int -} - -// Make sure that VariableThatShouldStartAtFive is set to five -// before each test -func (suite *ExampleTestSuite) SetupTest() { - suite.VariableThatShouldStartAtFive = 5 -} - -// All methods that begin with "Test" are run as tests within a -// suite. -func (suite *ExampleTestSuite) TestExample() { - suite.Equal(suite.VariableThatShouldStartAtFive, 5) -} - -// In order for 'go test' to run this suite, we need to create -// a normal test function and pass our suite to suite.Run -func TestExampleTestSuite(t *testing.T) { - suite.Run(t, new(ExampleTestSuite)) -} -``` - ------- - -Installation -============ - -To install Testify, use `go get`: - - * Latest version: go get github.com/stretchr/testify - * Specific version: go get gopkg.in/stretchr/testify.v1 - -This will then make the following packages available to you: - - github.com/stretchr/testify/assert - github.com/stretchr/testify/mock - github.com/stretchr/testify/http - -Import the `testify/assert` package into your code using this template: - -```go -package yours - -import ( - "testing" - "github.com/stretchr/testify/assert" -) - -func TestSomething(t *testing.T) { - - assert.True(t, true, "True is true!") - -} -``` - ------- - -Staying up to date -================== - -To update Testify to the latest version, use `go get -u github.com/stretchr/testify`. - ------- - -Version History -=============== - - * 1.0 - New package versioning strategy adopted. - ------- - -Contributing -============ - -Please feel free to submit issues, fork the repository and send pull requests! - -When submitting an issue, we ask that you please include a complete test function that demonstrates the issue. Extra credit for those using Testify to write the test code that demonstrates it. - ------- - -Licence -======= -Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell - -Please consider promoting this project if you find it useful. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/components/engine/vendor/github.com/stretchr/testify/assert/assertion_forward.go b/components/engine/vendor/github.com/stretchr/testify/assert/assertion_forward.go deleted file mode 100644 index aa4311ff84..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/assert/assertion_forward.go +++ /dev/null @@ -1,352 +0,0 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ - -package assert - -import ( - http "net/http" - url "net/url" - time "time" -) - -// Condition uses a Comparison to assert a complex condition. -func (a *Assertions) Condition(comp Comparison, msgAndArgs ...interface{}) bool { - return Condition(a.t, comp, msgAndArgs...) -} - -// Contains asserts that the specified string, list(array, slice...) or map contains the -// specified substring or element. -// -// a.Contains("Hello World", "World", "But 'Hello World' does contain 'World'") -// a.Contains(["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'") -// a.Contains({"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool { - return Contains(a.t, s, contains, msgAndArgs...) -} - -// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// a.Empty(obj) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) bool { - return Empty(a.t, object, msgAndArgs...) -} - -// Equal asserts that two objects are equal. -// -// a.Equal(123, 123, "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { - return Equal(a.t, expected, actual, msgAndArgs...) -} - -// EqualError asserts that a function returned an error (i.e. not `nil`) -// and that it is equal to the provided error. -// -// actualObj, err := SomeFunction() -// a.EqualError(err, expectedErrorString, "An error was expected") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) bool { - return EqualError(a.t, theError, errString, msgAndArgs...) -} - -// EqualValues asserts that two objects are equal or convertable to the same types -// and equal. -// -// a.EqualValues(uint32(123), int32(123), "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { - return EqualValues(a.t, expected, actual, msgAndArgs...) -} - -// Error asserts that a function returned an error (i.e. not `nil`). -// -// actualObj, err := SomeFunction() -// if a.Error(err, "An error was expected") { -// assert.Equal(t, err, expectedError) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Error(err error, msgAndArgs ...interface{}) bool { - return Error(a.t, err, msgAndArgs...) -} - -// Exactly asserts that two objects are equal is value and type. -// -// a.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { - return Exactly(a.t, expected, actual, msgAndArgs...) -} - -// Fail reports a failure through -func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) bool { - return Fail(a.t, failureMessage, msgAndArgs...) -} - -// FailNow fails test -func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) bool { - return FailNow(a.t, failureMessage, msgAndArgs...) -} - -// False asserts that the specified value is false. -// -// a.False(myBool, "myBool should be false") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) False(value bool, msgAndArgs ...interface{}) bool { - return False(a.t, value, msgAndArgs...) -} - -// HTTPBodyContains asserts that a specified handler returns a -// body that contains a string. -// -// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool { - return HTTPBodyContains(a.t, handler, method, url, values, str) -} - -// HTTPBodyNotContains asserts that a specified handler returns a -// body that does not contain a string. -// -// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) bool { - return HTTPBodyNotContains(a.t, handler, method, url, values, str) -} - -// HTTPError asserts that a specified handler returns an error status code. -// -// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values) bool { - return HTTPError(a.t, handler, method, url, values) -} - -// HTTPRedirect asserts that a specified handler returns a redirect status code. -// -// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values) bool { - return HTTPRedirect(a.t, handler, method, url, values) -} - -// HTTPSuccess asserts that a specified handler returns a success status code. -// -// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values) bool { - return HTTPSuccess(a.t, handler, method, url, values) -} - -// Implements asserts that an object is implemented by the specified interface. -// -// a.Implements((*MyInterface)(nil), new(MyObject), "MyObject") -func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool { - return Implements(a.t, interfaceObject, object, msgAndArgs...) -} - -// InDelta asserts that the two numerals are within delta of each other. -// -// a.InDelta(math.Pi, (22 / 7.0), 0.01) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { - return InDelta(a.t, expected, actual, delta, msgAndArgs...) -} - -// InDeltaSlice is the same as InDelta, except it compares two slices. -func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { - return InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...) -} - -// InEpsilon asserts that expected and actual have a relative error less than epsilon -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { - return InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) -} - -// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. -func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { - return InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...) -} - -// IsType asserts that the specified objects are of the same type. -func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool { - return IsType(a.t, expectedType, object, msgAndArgs...) -} - -// JSONEq asserts that two JSON strings are equivalent. -// -// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) bool { - return JSONEq(a.t, expected, actual, msgAndArgs...) -} - -// Len asserts that the specified object has specific length. -// Len also fails if the object has a type that len() not accept. -// -// a.Len(mySlice, 3, "The size of slice is not 3") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) bool { - return Len(a.t, object, length, msgAndArgs...) -} - -// Nil asserts that the specified object is nil. -// -// a.Nil(err, "err should be nothing") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) bool { - return Nil(a.t, object, msgAndArgs...) -} - -// NoError asserts that a function returned no error (i.e. `nil`). -// -// actualObj, err := SomeFunction() -// if a.NoError(err) { -// assert.Equal(t, actualObj, expectedObj) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) bool { - return NoError(a.t, err, msgAndArgs...) -} - -// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the -// specified substring or element. -// -// a.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'") -// a.NotContains(["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'") -// a.NotContains({"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) bool { - return NotContains(a.t, s, contains, msgAndArgs...) -} - -// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// if a.NotEmpty(obj) { -// assert.Equal(t, "two", obj[1]) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) bool { - return NotEmpty(a.t, object, msgAndArgs...) -} - -// NotEqual asserts that the specified values are NOT equal. -// -// a.NotEqual(obj1, obj2, "two objects shouldn't be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) bool { - return NotEqual(a.t, expected, actual, msgAndArgs...) -} - -// NotNil asserts that the specified object is not nil. -// -// a.NotNil(err, "err should be something") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) bool { - return NotNil(a.t, object, msgAndArgs...) -} - -// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. -// -// a.NotPanics(func(){ -// RemainCalm() -// }, "Calling RemainCalm() should NOT panic") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotPanics(f PanicTestFunc, msgAndArgs ...interface{}) bool { - return NotPanics(a.t, f, msgAndArgs...) -} - -// NotRegexp asserts that a specified regexp does not match a string. -// -// a.NotRegexp(regexp.MustCompile("starts"), "it's starting") -// a.NotRegexp("^start", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { - return NotRegexp(a.t, rx, str, msgAndArgs...) -} - -// NotZero asserts that i is not the zero value for its type and returns the truth. -func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) bool { - return NotZero(a.t, i, msgAndArgs...) -} - -// Panics asserts that the code inside the specified PanicTestFunc panics. -// -// a.Panics(func(){ -// GoCrazy() -// }, "Calling GoCrazy() should panic") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Panics(f PanicTestFunc, msgAndArgs ...interface{}) bool { - return Panics(a.t, f, msgAndArgs...) -} - -// Regexp asserts that a specified regexp matches a string. -// -// a.Regexp(regexp.MustCompile("start"), "it's starting") -// a.Regexp("start...$", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { - return Regexp(a.t, rx, str, msgAndArgs...) -} - -// True asserts that the specified value is true. -// -// a.True(myBool, "myBool should be true") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) True(value bool, msgAndArgs ...interface{}) bool { - return True(a.t, value, msgAndArgs...) -} - -// WithinDuration asserts that the two times are within duration delta of each other. -// -// a.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool { - return WithinDuration(a.t, expected, actual, delta, msgAndArgs...) -} - -// Zero asserts that i is the zero value for its type and returns the truth. -func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) bool { - return Zero(a.t, i, msgAndArgs...) -} diff --git a/components/engine/vendor/github.com/stretchr/testify/assert/assertions.go b/components/engine/vendor/github.com/stretchr/testify/assert/assertions.go deleted file mode 100644 index d1552e5e3f..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/assert/assertions.go +++ /dev/null @@ -1,1069 +0,0 @@ -package assert - -import ( - "bufio" - "bytes" - "encoding/json" - "fmt" - "math" - "reflect" - "regexp" - "runtime" - "strings" - "time" - "unicode" - "unicode/utf8" - - "github.com/davecgh/go-spew/spew" - "github.com/pmezard/go-difflib/difflib" -) - -// TestingT is an interface wrapper around *testing.T -type TestingT interface { - Errorf(format string, args ...interface{}) -} - -// Comparison a custom function that returns true on success and false on failure -type Comparison func() (success bool) - -/* - Helper functions -*/ - -// ObjectsAreEqual determines if two objects are considered equal. -// -// This function does no assertion of any kind. -func ObjectsAreEqual(expected, actual interface{}) bool { - - if expected == nil || actual == nil { - return expected == actual - } - - return reflect.DeepEqual(expected, actual) - -} - -// ObjectsAreEqualValues gets whether two objects are equal, or if their -// values are equal. -func ObjectsAreEqualValues(expected, actual interface{}) bool { - if ObjectsAreEqual(expected, actual) { - return true - } - - actualType := reflect.TypeOf(actual) - if actualType == nil { - return false - } - expectedValue := reflect.ValueOf(expected) - if expectedValue.IsValid() && expectedValue.Type().ConvertibleTo(actualType) { - // Attempt comparison after type conversion - return reflect.DeepEqual(expectedValue.Convert(actualType).Interface(), actual) - } - - return false -} - -/* CallerInfo is necessary because the assert functions use the testing object -internally, causing it to print the file:line of the assert method, rather than where -the problem actually occurred in calling code.*/ - -// CallerInfo returns an array of strings containing the file and line number -// of each stack frame leading from the current test to the assert call that -// failed. -func CallerInfo() []string { - - pc := uintptr(0) - file := "" - line := 0 - ok := false - name := "" - - callers := []string{} - for i := 0; ; i++ { - pc, file, line, ok = runtime.Caller(i) - if !ok { - // The breaks below failed to terminate the loop, and we ran off the - // end of the call stack. - break - } - - // This is a huge edge case, but it will panic if this is the case, see #180 - if file == "" { - break - } - - f := runtime.FuncForPC(pc) - if f == nil { - break - } - name = f.Name() - - // testing.tRunner is the standard library function that calls - // tests. Subtests are called directly by tRunner, without going through - // the Test/Benchmark/Example function that contains the t.Run calls, so - // with subtests we should break when we hit tRunner, without adding it - // to the list of callers. - if name == "testing.tRunner" { - break - } - - parts := strings.Split(file, "/") - dir := parts[len(parts)-2] - file = parts[len(parts)-1] - if (dir != "assert" && dir != "mock" && dir != "require") || file == "mock_test.go" { - callers = append(callers, fmt.Sprintf("%s:%d", file, line)) - } - - // Drop the package - segments := strings.Split(name, ".") - name = segments[len(segments)-1] - if isTest(name, "Test") || - isTest(name, "Benchmark") || - isTest(name, "Example") { - break - } - } - - return callers -} - -// Stolen from the `go test` tool. -// isTest tells whether name looks like a test (or benchmark, according to prefix). -// It is a Test (say) if there is a character after Test that is not a lower-case letter. -// We don't want TesticularCancer. -func isTest(name, prefix string) bool { - if !strings.HasPrefix(name, prefix) { - return false - } - if len(name) == len(prefix) { // "Test" is ok - return true - } - rune, _ := utf8.DecodeRuneInString(name[len(prefix):]) - return !unicode.IsLower(rune) -} - -// getWhitespaceString returns a string that is long enough to overwrite the default -// output from the go testing framework. -func getWhitespaceString() string { - - _, file, line, ok := runtime.Caller(1) - if !ok { - return "" - } - parts := strings.Split(file, "/") - file = parts[len(parts)-1] - - return strings.Repeat(" ", len(fmt.Sprintf("%s:%d: ", file, line))) - -} - -func messageFromMsgAndArgs(msgAndArgs ...interface{}) string { - if len(msgAndArgs) == 0 || msgAndArgs == nil { - return "" - } - if len(msgAndArgs) == 1 { - return msgAndArgs[0].(string) - } - if len(msgAndArgs) > 1 { - return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...) - } - return "" -} - -// Aligns the provided message so that all lines after the first line start at the same location as the first line. -// Assumes that the first line starts at the correct location (after carriage return, tab, label, spacer and tab). -// The longestLabelLen parameter specifies the length of the longest label in the output (required becaues this is the -// basis on which the alignment occurs). -func indentMessageLines(message string, longestLabelLen int) string { - outBuf := new(bytes.Buffer) - - for i, scanner := 0, bufio.NewScanner(strings.NewReader(message)); scanner.Scan(); i++ { - // no need to align first line because it starts at the correct location (after the label) - if i != 0 { - // append alignLen+1 spaces to align with "{{longestLabel}}:" before adding tab - outBuf.WriteString("\n\r\t" + strings.Repeat(" ", longestLabelLen +1) + "\t") - } - outBuf.WriteString(scanner.Text()) - } - - return outBuf.String() -} - -type failNower interface { - FailNow() -} - -// FailNow fails test -func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { - Fail(t, failureMessage, msgAndArgs...) - - // We cannot extend TestingT with FailNow() and - // maintain backwards compatibility, so we fallback - // to panicking when FailNow is not available in - // TestingT. - // See issue #263 - - if t, ok := t.(failNower); ok { - t.FailNow() - } else { - panic("test failed and t is missing `FailNow()`") - } - return false -} - -// Fail reports a failure through -func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) bool { - content := []labeledContent{ - {"Error Trace", strings.Join(CallerInfo(), "\n\r\t\t\t")}, - {"Error", failureMessage}, - } - - message := messageFromMsgAndArgs(msgAndArgs...) - if len(message) > 0 { - content = append(content, labeledContent{"Messages", message}) - } - - t.Errorf("\r" + getWhitespaceString() + labeledOutput(content...)) - - return false -} - -type labeledContent struct { - label string - content string -} - -// labeledOutput returns a string consisting of the provided labeledContent. Each labeled output is appended in the following manner: -// -// \r\t{{label}}:{{align_spaces}}\t{{content}}\n -// -// The initial carriage return is required to undo/erase any padding added by testing.T.Errorf. The "\t{{label}}:" is for the label. -// If a label is shorter than the longest label provided, padding spaces are added to make all the labels match in length. Once this -// alignment is achieved, "\t{{content}}\n" is added for the output. -// -// If the content of the labeledOutput contains line breaks, the subsequent lines are aligned so that they start at the same location as the first line. -func labeledOutput(content ...labeledContent) string { - longestLabel := 0 - for _, v := range content { - if len(v.label) > longestLabel { - longestLabel = len(v.label) - } - } - var output string - for _, v := range content { - output += "\r\t" + v.label + ":" + strings.Repeat(" ", longestLabel-len(v.label)) + "\t" + indentMessageLines(v.content, longestLabel) + "\n" - } - return output -} - -// Implements asserts that an object is implemented by the specified interface. -// -// assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject") -func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) bool { - - interfaceType := reflect.TypeOf(interfaceObject).Elem() - - if !reflect.TypeOf(object).Implements(interfaceType) { - return Fail(t, fmt.Sprintf("%T must implement %v", object, interfaceType), msgAndArgs...) - } - - return true - -} - -// IsType asserts that the specified objects are of the same type. -func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) bool { - - if !ObjectsAreEqual(reflect.TypeOf(object), reflect.TypeOf(expectedType)) { - return Fail(t, fmt.Sprintf("Object expected to be of type %v, but was %v", reflect.TypeOf(expectedType), reflect.TypeOf(object)), msgAndArgs...) - } - - return true -} - -// Equal asserts that two objects are equal. -// -// assert.Equal(t, 123, 123, "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func Equal(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { - - if !ObjectsAreEqual(expected, actual) { - diff := diff(expected, actual) - expected, actual = formatUnequalValues(expected, actual) - return Fail(t, fmt.Sprintf("Not equal: \n"+ - "expected: %s\n"+ - "received: %s%s", expected, actual, diff), msgAndArgs...) - } - - return true - -} - -// formatUnequalValues takes two values of arbitrary types and returns string -// representations appropriate to be presented to the user. -// -// If the values are not of like type, the returned strings will be prefixed -// with the type name, and the value will be enclosed in parenthesis similar -// to a type conversion in the Go grammar. -func formatUnequalValues(expected, actual interface{}) (e string, a string) { - if reflect.TypeOf(expected) != reflect.TypeOf(actual) { - return fmt.Sprintf("%T(%#v)", expected, expected), - fmt.Sprintf("%T(%#v)", actual, actual) - } - - return fmt.Sprintf("%#v", expected), - fmt.Sprintf("%#v", actual) -} - -// EqualValues asserts that two objects are equal or convertable to the same types -// and equal. -// -// assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func EqualValues(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { - - if !ObjectsAreEqualValues(expected, actual) { - diff := diff(expected, actual) - expected, actual = formatUnequalValues(expected, actual) - return Fail(t, fmt.Sprintf("Not equal: \n"+ - "expected: %s\n"+ - "received: %s%s", expected, actual, diff), msgAndArgs...) - } - - return true - -} - -// Exactly asserts that two objects are equal is value and type. -// -// assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func Exactly(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { - - aType := reflect.TypeOf(expected) - bType := reflect.TypeOf(actual) - - if aType != bType { - return Fail(t, fmt.Sprintf("Types expected to match exactly\n\r\t%v != %v", aType, bType), msgAndArgs...) - } - - return Equal(t, expected, actual, msgAndArgs...) - -} - -// NotNil asserts that the specified object is not nil. -// -// assert.NotNil(t, err, "err should be something") -// -// Returns whether the assertion was successful (true) or not (false). -func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { - if !isNil(object) { - return true - } - return Fail(t, "Expected value not to be nil.", msgAndArgs...) -} - -// isNil checks if a specified object is nil or not, without Failing. -func isNil(object interface{}) bool { - if object == nil { - return true - } - - value := reflect.ValueOf(object) - kind := value.Kind() - if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() { - return true - } - - return false -} - -// Nil asserts that the specified object is nil. -// -// assert.Nil(t, err, "err should be nothing") -// -// Returns whether the assertion was successful (true) or not (false). -func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { - if isNil(object) { - return true - } - return Fail(t, fmt.Sprintf("Expected nil, but got: %#v", object), msgAndArgs...) -} - -var numericZeros = []interface{}{ - int(0), - int8(0), - int16(0), - int32(0), - int64(0), - uint(0), - uint8(0), - uint16(0), - uint32(0), - uint64(0), - float32(0), - float64(0), -} - -// isEmpty gets whether the specified object is considered empty or not. -func isEmpty(object interface{}) bool { - - if object == nil { - return true - } else if object == "" { - return true - } else if object == false { - return true - } - - for _, v := range numericZeros { - if object == v { - return true - } - } - - objValue := reflect.ValueOf(object) - - switch objValue.Kind() { - case reflect.Map: - fallthrough - case reflect.Slice, reflect.Chan: - { - return (objValue.Len() == 0) - } - case reflect.Struct: - switch object.(type) { - case time.Time: - return object.(time.Time).IsZero() - } - case reflect.Ptr: - { - if objValue.IsNil() { - return true - } - switch object.(type) { - case *time.Time: - return object.(*time.Time).IsZero() - default: - return false - } - } - } - return false -} - -// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// assert.Empty(t, obj) -// -// Returns whether the assertion was successful (true) or not (false). -func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { - - pass := isEmpty(object) - if !pass { - Fail(t, fmt.Sprintf("Should be empty, but was %v", object), msgAndArgs...) - } - - return pass - -} - -// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// if assert.NotEmpty(t, obj) { -// assert.Equal(t, "two", obj[1]) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) bool { - - pass := !isEmpty(object) - if !pass { - Fail(t, fmt.Sprintf("Should NOT be empty, but was %v", object), msgAndArgs...) - } - - return pass - -} - -// getLen try to get length of object. -// return (false, 0) if impossible. -func getLen(x interface{}) (ok bool, length int) { - v := reflect.ValueOf(x) - defer func() { - if e := recover(); e != nil { - ok = false - } - }() - return true, v.Len() -} - -// Len asserts that the specified object has specific length. -// Len also fails if the object has a type that len() not accept. -// -// assert.Len(t, mySlice, 3, "The size of slice is not 3") -// -// Returns whether the assertion was successful (true) or not (false). -func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) bool { - ok, l := getLen(object) - if !ok { - return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", object), msgAndArgs...) - } - - if l != length { - return Fail(t, fmt.Sprintf("\"%s\" should have %d item(s), but has %d", object, length, l), msgAndArgs...) - } - return true -} - -// True asserts that the specified value is true. -// -// assert.True(t, myBool, "myBool should be true") -// -// Returns whether the assertion was successful (true) or not (false). -func True(t TestingT, value bool, msgAndArgs ...interface{}) bool { - - if value != true { - return Fail(t, "Should be true", msgAndArgs...) - } - - return true - -} - -// False asserts that the specified value is false. -// -// assert.False(t, myBool, "myBool should be false") -// -// Returns whether the assertion was successful (true) or not (false). -func False(t TestingT, value bool, msgAndArgs ...interface{}) bool { - - if value != false { - return Fail(t, "Should be false", msgAndArgs...) - } - - return true - -} - -// NotEqual asserts that the specified values are NOT equal. -// -// assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func NotEqual(t TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool { - - if ObjectsAreEqual(expected, actual) { - return Fail(t, fmt.Sprintf("Should not be: %#v\n", actual), msgAndArgs...) - } - - return true - -} - -// containsElement try loop over the list check if the list includes the element. -// return (false, false) if impossible. -// return (true, false) if element was not found. -// return (true, true) if element was found. -func includeElement(list interface{}, element interface{}) (ok, found bool) { - - listValue := reflect.ValueOf(list) - elementValue := reflect.ValueOf(element) - defer func() { - if e := recover(); e != nil { - ok = false - found = false - } - }() - - if reflect.TypeOf(list).Kind() == reflect.String { - return true, strings.Contains(listValue.String(), elementValue.String()) - } - - if reflect.TypeOf(list).Kind() == reflect.Map { - mapKeys := listValue.MapKeys() - for i := 0; i < len(mapKeys); i++ { - if ObjectsAreEqual(mapKeys[i].Interface(), element) { - return true, true - } - } - return true, false - } - - for i := 0; i < listValue.Len(); i++ { - if ObjectsAreEqual(listValue.Index(i).Interface(), element) { - return true, true - } - } - return true, false - -} - -// Contains asserts that the specified string, list(array, slice...) or map contains the -// specified substring or element. -// -// assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'") -// assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'") -// assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'") -// -// Returns whether the assertion was successful (true) or not (false). -func Contains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool { - - ok, found := includeElement(s, contains) - if !ok { - return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", s), msgAndArgs...) - } - if !found { - return Fail(t, fmt.Sprintf("\"%s\" does not contain \"%s\"", s, contains), msgAndArgs...) - } - - return true - -} - -// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the -// specified substring or element. -// -// assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'") -// assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'") -// assert.NotContains(t, {"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'") -// -// Returns whether the assertion was successful (true) or not (false). -func NotContains(t TestingT, s, contains interface{}, msgAndArgs ...interface{}) bool { - - ok, found := includeElement(s, contains) - if !ok { - return Fail(t, fmt.Sprintf("\"%s\" could not be applied builtin len()", s), msgAndArgs...) - } - if found { - return Fail(t, fmt.Sprintf("\"%s\" should not contain \"%s\"", s, contains), msgAndArgs...) - } - - return true - -} - -// Condition uses a Comparison to assert a complex condition. -func Condition(t TestingT, comp Comparison, msgAndArgs ...interface{}) bool { - result := comp() - if !result { - Fail(t, "Condition failed!", msgAndArgs...) - } - return result -} - -// PanicTestFunc defines a func that should be passed to the assert.Panics and assert.NotPanics -// methods, and represents a simple func that takes no arguments, and returns nothing. -type PanicTestFunc func() - -// didPanic returns true if the function passed to it panics. Otherwise, it returns false. -func didPanic(f PanicTestFunc) (bool, interface{}) { - - didPanic := false - var message interface{} - func() { - - defer func() { - if message = recover(); message != nil { - didPanic = true - } - }() - - // call the target function - f() - - }() - - return didPanic, message - -} - -// Panics asserts that the code inside the specified PanicTestFunc panics. -// -// assert.Panics(t, func(){ -// GoCrazy() -// }, "Calling GoCrazy() should panic") -// -// Returns whether the assertion was successful (true) or not (false). -func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool { - - if funcDidPanic, panicValue := didPanic(f); !funcDidPanic { - return Fail(t, fmt.Sprintf("func %#v should panic\n\r\tPanic value:\t%v", f, panicValue), msgAndArgs...) - } - - return true -} - -// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. -// -// assert.NotPanics(t, func(){ -// RemainCalm() -// }, "Calling RemainCalm() should NOT panic") -// -// Returns whether the assertion was successful (true) or not (false). -func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool { - - if funcDidPanic, panicValue := didPanic(f); funcDidPanic { - return Fail(t, fmt.Sprintf("func %#v should not panic\n\r\tPanic value:\t%v", f, panicValue), msgAndArgs...) - } - - return true -} - -// WithinDuration asserts that the two times are within duration delta of each other. -// -// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s") -// -// Returns whether the assertion was successful (true) or not (false). -func WithinDuration(t TestingT, expected, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) bool { - - dt := expected.Sub(actual) - if dt < -delta || dt > delta { - return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) - } - - return true -} - -func toFloat(x interface{}) (float64, bool) { - var xf float64 - xok := true - - switch xn := x.(type) { - case uint8: - xf = float64(xn) - case uint16: - xf = float64(xn) - case uint32: - xf = float64(xn) - case uint64: - xf = float64(xn) - case int: - xf = float64(xn) - case int8: - xf = float64(xn) - case int16: - xf = float64(xn) - case int32: - xf = float64(xn) - case int64: - xf = float64(xn) - case float32: - xf = float64(xn) - case float64: - xf = float64(xn) - default: - xok = false - } - - return xf, xok -} - -// InDelta asserts that the two numerals are within delta of each other. -// -// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01) -// -// Returns whether the assertion was successful (true) or not (false). -func InDelta(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { - - af, aok := toFloat(expected) - bf, bok := toFloat(actual) - - if !aok || !bok { - return Fail(t, fmt.Sprintf("Parameters must be numerical"), msgAndArgs...) - } - - if math.IsNaN(af) { - return Fail(t, fmt.Sprintf("Actual must not be NaN"), msgAndArgs...) - } - - if math.IsNaN(bf) { - return Fail(t, fmt.Sprintf("Expected %v with delta %v, but was NaN", expected, delta), msgAndArgs...) - } - - dt := af - bf - if dt < -delta || dt > delta { - return Fail(t, fmt.Sprintf("Max difference between %v and %v allowed is %v, but difference was %v", expected, actual, delta, dt), msgAndArgs...) - } - - return true -} - -// InDeltaSlice is the same as InDelta, except it compares two slices. -func InDeltaSlice(t TestingT, expected, actual interface{}, delta float64, msgAndArgs ...interface{}) bool { - if expected == nil || actual == nil || - reflect.TypeOf(actual).Kind() != reflect.Slice || - reflect.TypeOf(expected).Kind() != reflect.Slice { - return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...) - } - - actualSlice := reflect.ValueOf(actual) - expectedSlice := reflect.ValueOf(expected) - - for i := 0; i < actualSlice.Len(); i++ { - result := InDelta(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), delta) - if !result { - return result - } - } - - return true -} - -func calcRelativeError(expected, actual interface{}) (float64, error) { - af, aok := toFloat(expected) - if !aok { - return 0, fmt.Errorf("expected value %q cannot be converted to float", expected) - } - if af == 0 { - return 0, fmt.Errorf("expected value must have a value other than zero to calculate the relative error") - } - bf, bok := toFloat(actual) - if !bok { - return 0, fmt.Errorf("expected value %q cannot be converted to float", actual) - } - - return math.Abs(af-bf) / math.Abs(af), nil -} - -// InEpsilon asserts that expected and actual have a relative error less than epsilon -// -// Returns whether the assertion was successful (true) or not (false). -func InEpsilon(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { - actualEpsilon, err := calcRelativeError(expected, actual) - if err != nil { - return Fail(t, err.Error(), msgAndArgs...) - } - if actualEpsilon > epsilon { - return Fail(t, fmt.Sprintf("Relative error is too high: %#v (expected)\n"+ - " < %#v (actual)", actualEpsilon, epsilon), msgAndArgs...) - } - - return true -} - -// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. -func InEpsilonSlice(t TestingT, expected, actual interface{}, epsilon float64, msgAndArgs ...interface{}) bool { - if expected == nil || actual == nil || - reflect.TypeOf(actual).Kind() != reflect.Slice || - reflect.TypeOf(expected).Kind() != reflect.Slice { - return Fail(t, fmt.Sprintf("Parameters must be slice"), msgAndArgs...) - } - - actualSlice := reflect.ValueOf(actual) - expectedSlice := reflect.ValueOf(expected) - - for i := 0; i < actualSlice.Len(); i++ { - result := InEpsilon(t, actualSlice.Index(i).Interface(), expectedSlice.Index(i).Interface(), epsilon) - if !result { - return result - } - } - - return true -} - -/* - Errors -*/ - -// NoError asserts that a function returned no error (i.e. `nil`). -// -// actualObj, err := SomeFunction() -// if assert.NoError(t, err) { -// assert.Equal(t, actualObj, expectedObj) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func NoError(t TestingT, err error, msgAndArgs ...interface{}) bool { - if err != nil { - return Fail(t, fmt.Sprintf("Received unexpected error:\n%+v", err), msgAndArgs...) - } - - return true -} - -// Error asserts that a function returned an error (i.e. not `nil`). -// -// actualObj, err := SomeFunction() -// if assert.Error(t, err, "An error was expected") { -// assert.Equal(t, err, expectedError) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func Error(t TestingT, err error, msgAndArgs ...interface{}) bool { - - if err == nil { - return Fail(t, "An error is expected but got nil.", msgAndArgs...) - } - - return true -} - -// EqualError asserts that a function returned an error (i.e. not `nil`) -// and that it is equal to the provided error. -// -// actualObj, err := SomeFunction() -// assert.EqualError(t, err, expectedErrorString, "An error was expected") -// -// Returns whether the assertion was successful (true) or not (false). -func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) bool { - if !Error(t, theError, msgAndArgs...) { - return false - } - expected := errString - actual := theError.Error() - // don't need to use deep equals here, we know they are both strings - if expected != actual { - return Fail(t, fmt.Sprintf("Error message not equal:\n"+ - "expected: %q\n"+ - "received: %q", expected, actual), msgAndArgs...) - } - return true -} - -// matchRegexp return true if a specified regexp matches a string. -func matchRegexp(rx interface{}, str interface{}) bool { - - var r *regexp.Regexp - if rr, ok := rx.(*regexp.Regexp); ok { - r = rr - } else { - r = regexp.MustCompile(fmt.Sprint(rx)) - } - - return (r.FindStringIndex(fmt.Sprint(str)) != nil) - -} - -// Regexp asserts that a specified regexp matches a string. -// -// assert.Regexp(t, regexp.MustCompile("start"), "it's starting") -// assert.Regexp(t, "start...$", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { - - match := matchRegexp(rx, str) - - if !match { - Fail(t, fmt.Sprintf("Expect \"%v\" to match \"%v\"", str, rx), msgAndArgs...) - } - - return match -} - -// NotRegexp asserts that a specified regexp does not match a string. -// -// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") -// assert.NotRegexp(t, "^start", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) bool { - match := matchRegexp(rx, str) - - if match { - Fail(t, fmt.Sprintf("Expect \"%v\" to NOT match \"%v\"", str, rx), msgAndArgs...) - } - - return !match - -} - -// Zero asserts that i is the zero value for its type and returns the truth. -func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool { - if i != nil && !reflect.DeepEqual(i, reflect.Zero(reflect.TypeOf(i)).Interface()) { - return Fail(t, fmt.Sprintf("Should be zero, but was %v", i), msgAndArgs...) - } - return true -} - -// NotZero asserts that i is not the zero value for its type and returns the truth. -func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool { - if i == nil || reflect.DeepEqual(i, reflect.Zero(reflect.TypeOf(i)).Interface()) { - return Fail(t, fmt.Sprintf("Should not be zero, but was %v", i), msgAndArgs...) - } - return true -} - -// JSONEq asserts that two JSON strings are equivalent. -// -// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) -// -// Returns whether the assertion was successful (true) or not (false). -func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) bool { - var expectedJSONAsInterface, actualJSONAsInterface interface{} - - if err := json.Unmarshal([]byte(expected), &expectedJSONAsInterface); err != nil { - return Fail(t, fmt.Sprintf("Expected value ('%s') is not valid json.\nJSON parsing error: '%s'", expected, err.Error()), msgAndArgs...) - } - - if err := json.Unmarshal([]byte(actual), &actualJSONAsInterface); err != nil { - return Fail(t, fmt.Sprintf("Input ('%s') needs to be valid json.\nJSON parsing error: '%s'", actual, err.Error()), msgAndArgs...) - } - - return Equal(t, expectedJSONAsInterface, actualJSONAsInterface, msgAndArgs...) -} - -func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) { - t := reflect.TypeOf(v) - k := t.Kind() - - if k == reflect.Ptr { - t = t.Elem() - k = t.Kind() - } - return t, k -} - -// diff returns a diff of both values as long as both are of the same type and -// are a struct, map, slice or array. Otherwise it returns an empty string. -func diff(expected interface{}, actual interface{}) string { - if expected == nil || actual == nil { - return "" - } - - et, ek := typeAndKind(expected) - at, _ := typeAndKind(actual) - - if et != at { - return "" - } - - if ek != reflect.Struct && ek != reflect.Map && ek != reflect.Slice && ek != reflect.Array { - return "" - } - - e := spewConfig.Sdump(expected) - a := spewConfig.Sdump(actual) - - diff, _ := difflib.GetUnifiedDiffString(difflib.UnifiedDiff{ - A: difflib.SplitLines(e), - B: difflib.SplitLines(a), - FromFile: "Expected", - FromDate: "", - ToFile: "Actual", - ToDate: "", - Context: 1, - }) - - return "\n\nDiff:\n" + diff -} - -var spewConfig = spew.ConfigState{ - Indent: " ", - DisablePointerAddresses: true, - DisableCapacities: true, - SortKeys: true, -} diff --git a/components/engine/vendor/github.com/stretchr/testify/assert/doc.go b/components/engine/vendor/github.com/stretchr/testify/assert/doc.go deleted file mode 100644 index c9dccc4d6c..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/assert/doc.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. -// -// Example Usage -// -// The following is a complete example using assert in a standard test function: -// import ( -// "testing" -// "github.com/stretchr/testify/assert" -// ) -// -// func TestSomething(t *testing.T) { -// -// var a string = "Hello" -// var b string = "Hello" -// -// assert.Equal(t, a, b, "The two words should be the same.") -// -// } -// -// if you assert many times, use the format below: -// -// import ( -// "testing" -// "github.com/stretchr/testify/assert" -// ) -// -// func TestSomething(t *testing.T) { -// assert := assert.New(t) -// -// var a string = "Hello" -// var b string = "Hello" -// -// assert.Equal(a, b, "The two words should be the same.") -// } -// -// Assertions -// -// Assertions allow you to easily write test code, and are global funcs in the `assert` package. -// All assertion functions take, as the first argument, the `*testing.T` object provided by the -// testing framework. This allows the assertion funcs to write the failings and other details to -// the correct place. -// -// Every assertion function also takes an optional string message as the final argument, -// allowing custom error messages to be appended to the message the assertion method outputs. -package assert diff --git a/components/engine/vendor/github.com/stretchr/testify/assert/errors.go b/components/engine/vendor/github.com/stretchr/testify/assert/errors.go deleted file mode 100644 index ac9dc9d1d6..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/assert/errors.go +++ /dev/null @@ -1,10 +0,0 @@ -package assert - -import ( - "errors" -) - -// AnError is an error instance useful for testing. If the code does not care -// about error specifics, and only needs to return the error for example, this -// error should be used to make the test code more readable. -var AnError = errors.New("assert.AnError general error for testing") diff --git a/components/engine/vendor/github.com/stretchr/testify/assert/forward_assertions.go b/components/engine/vendor/github.com/stretchr/testify/assert/forward_assertions.go deleted file mode 100644 index b867e95ea5..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/assert/forward_assertions.go +++ /dev/null @@ -1,16 +0,0 @@ -package assert - -// Assertions provides assertion methods around the -// TestingT interface. -type Assertions struct { - t TestingT -} - -// New makes a new Assertions object for the specified TestingT. -func New(t TestingT) *Assertions { - return &Assertions{ - t: t, - } -} - -//go:generate go run ../_codegen/main.go -output-package=assert -template=assertion_forward.go.tmpl diff --git a/components/engine/vendor/github.com/stretchr/testify/assert/http_assertions.go b/components/engine/vendor/github.com/stretchr/testify/assert/http_assertions.go deleted file mode 100644 index fa7ab89b18..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/assert/http_assertions.go +++ /dev/null @@ -1,106 +0,0 @@ -package assert - -import ( - "fmt" - "net/http" - "net/http/httptest" - "net/url" - "strings" -) - -// httpCode is a helper that returns HTTP code of the response. It returns -1 -// if building a new request fails. -func httpCode(handler http.HandlerFunc, method, url string, values url.Values) int { - w := httptest.NewRecorder() - req, err := http.NewRequest(method, url+"?"+values.Encode(), nil) - if err != nil { - return -1 - } - handler(w, req) - return w.Code -} - -// HTTPSuccess asserts that a specified handler returns a success status code. -// -// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPSuccess(t TestingT, handler http.HandlerFunc, method, url string, values url.Values) bool { - code := httpCode(handler, method, url, values) - if code == -1 { - return false - } - return code >= http.StatusOK && code <= http.StatusPartialContent -} - -// HTTPRedirect asserts that a specified handler returns a redirect status code. -// -// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPRedirect(t TestingT, handler http.HandlerFunc, method, url string, values url.Values) bool { - code := httpCode(handler, method, url, values) - if code == -1 { - return false - } - return code >= http.StatusMultipleChoices && code <= http.StatusTemporaryRedirect -} - -// HTTPError asserts that a specified handler returns an error status code. -// -// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPError(t TestingT, handler http.HandlerFunc, method, url string, values url.Values) bool { - code := httpCode(handler, method, url, values) - if code == -1 { - return false - } - return code >= http.StatusBadRequest -} - -// HTTPBody is a helper that returns HTTP body of the response. It returns -// empty string if building a new request fails. -func HTTPBody(handler http.HandlerFunc, method, url string, values url.Values) string { - w := httptest.NewRecorder() - req, err := http.NewRequest(method, url+"?"+values.Encode(), nil) - if err != nil { - return "" - } - handler(w, req) - return w.Body.String() -} - -// HTTPBodyContains asserts that a specified handler returns a -// body that contains a string. -// -// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}) bool { - body := HTTPBody(handler, method, url, values) - - contains := strings.Contains(body, fmt.Sprint(str)) - if !contains { - Fail(t, fmt.Sprintf("Expected response body for \"%s\" to contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) - } - - return contains -} - -// HTTPBodyNotContains asserts that a specified handler returns a -// body that does not contain a string. -// -// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method, url string, values url.Values, str interface{}) bool { - body := HTTPBody(handler, method, url, values) - - contains := strings.Contains(body, fmt.Sprint(str)) - if contains { - Fail(t, fmt.Sprintf("Expected response body for \"%s\" to NOT contain \"%s\" but found \"%s\"", url+"?"+values.Encode(), str, body)) - } - - return !contains -} diff --git a/components/engine/vendor/github.com/stretchr/testify/require/doc.go b/components/engine/vendor/github.com/stretchr/testify/require/doc.go deleted file mode 100644 index 169de39221..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/require/doc.go +++ /dev/null @@ -1,28 +0,0 @@ -// Package require implements the same assertions as the `assert` package but -// stops test execution when a test fails. -// -// Example Usage -// -// The following is a complete example using require in a standard test function: -// import ( -// "testing" -// "github.com/stretchr/testify/require" -// ) -// -// func TestSomething(t *testing.T) { -// -// var a string = "Hello" -// var b string = "Hello" -// -// require.Equal(t, a, b, "The two words should be the same.") -// -// } -// -// Assertions -// -// The `require` package have same global functions as in the `assert` package, -// but instead of returning a boolean result they call `t.FailNow()`. -// -// Every assertion function also takes an optional string message as the final argument, -// allowing custom error messages to be appended to the message the assertion method outputs. -package require diff --git a/components/engine/vendor/github.com/stretchr/testify/require/forward_requirements.go b/components/engine/vendor/github.com/stretchr/testify/require/forward_requirements.go deleted file mode 100644 index d3c2ab9bc7..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/require/forward_requirements.go +++ /dev/null @@ -1,16 +0,0 @@ -package require - -// Assertions provides assertion methods around the -// TestingT interface. -type Assertions struct { - t TestingT -} - -// New makes a new Assertions object for the specified TestingT. -func New(t TestingT) *Assertions { - return &Assertions{ - t: t, - } -} - -//go:generate go run ../_codegen/main.go -output-package=require -template=require_forward.go.tmpl diff --git a/components/engine/vendor/github.com/stretchr/testify/require/require.go b/components/engine/vendor/github.com/stretchr/testify/require/require.go deleted file mode 100644 index fc567f140a..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/require/require.go +++ /dev/null @@ -1,429 +0,0 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ - -package require - -import ( - assert "github.com/stretchr/testify/assert" - http "net/http" - url "net/url" - time "time" -) - -// Condition uses a Comparison to assert a complex condition. -func Condition(t TestingT, comp assert.Comparison, msgAndArgs ...interface{}) { - if !assert.Condition(t, comp, msgAndArgs...) { - t.FailNow() - } -} - -// Contains asserts that the specified string, list(array, slice...) or map contains the -// specified substring or element. -// -// assert.Contains(t, "Hello World", "World", "But 'Hello World' does contain 'World'") -// assert.Contains(t, ["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'") -// assert.Contains(t, {"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'") -// -// Returns whether the assertion was successful (true) or not (false). -func Contains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { - if !assert.Contains(t, s, contains, msgAndArgs...) { - t.FailNow() - } -} - -// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// assert.Empty(t, obj) -// -// Returns whether the assertion was successful (true) or not (false). -func Empty(t TestingT, object interface{}, msgAndArgs ...interface{}) { - if !assert.Empty(t, object, msgAndArgs...) { - t.FailNow() - } -} - -// Equal asserts that two objects are equal. -// -// assert.Equal(t, 123, 123, "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func Equal(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - if !assert.Equal(t, expected, actual, msgAndArgs...) { - t.FailNow() - } -} - -// EqualError asserts that a function returned an error (i.e. not `nil`) -// and that it is equal to the provided error. -// -// actualObj, err := SomeFunction() -// assert.EqualError(t, err, expectedErrorString, "An error was expected") -// -// Returns whether the assertion was successful (true) or not (false). -func EqualError(t TestingT, theError error, errString string, msgAndArgs ...interface{}) { - if !assert.EqualError(t, theError, errString, msgAndArgs...) { - t.FailNow() - } -} - -// EqualValues asserts that two objects are equal or convertable to the same types -// and equal. -// -// assert.EqualValues(t, uint32(123), int32(123), "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func EqualValues(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - if !assert.EqualValues(t, expected, actual, msgAndArgs...) { - t.FailNow() - } -} - -// Error asserts that a function returned an error (i.e. not `nil`). -// -// actualObj, err := SomeFunction() -// if assert.Error(t, err, "An error was expected") { -// assert.Equal(t, err, expectedError) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func Error(t TestingT, err error, msgAndArgs ...interface{}) { - if !assert.Error(t, err, msgAndArgs...) { - t.FailNow() - } -} - -// Exactly asserts that two objects are equal is value and type. -// -// assert.Exactly(t, int32(123), int64(123), "123 and 123 should NOT be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func Exactly(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - if !assert.Exactly(t, expected, actual, msgAndArgs...) { - t.FailNow() - } -} - -// Fail reports a failure through -func Fail(t TestingT, failureMessage string, msgAndArgs ...interface{}) { - if !assert.Fail(t, failureMessage, msgAndArgs...) { - t.FailNow() - } -} - -// FailNow fails test -func FailNow(t TestingT, failureMessage string, msgAndArgs ...interface{}) { - if !assert.FailNow(t, failureMessage, msgAndArgs...) { - t.FailNow() - } -} - -// False asserts that the specified value is false. -// -// assert.False(t, myBool, "myBool should be false") -// -// Returns whether the assertion was successful (true) or not (false). -func False(t TestingT, value bool, msgAndArgs ...interface{}) { - if !assert.False(t, value, msgAndArgs...) { - t.FailNow() - } -} - -// HTTPBodyContains asserts that a specified handler returns a -// body that contains a string. -// -// assert.HTTPBodyContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPBodyContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) { - if !assert.HTTPBodyContains(t, handler, method, url, values, str) { - t.FailNow() - } -} - -// HTTPBodyNotContains asserts that a specified handler returns a -// body that does not contain a string. -// -// assert.HTTPBodyNotContains(t, myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPBodyNotContains(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) { - if !assert.HTTPBodyNotContains(t, handler, method, url, values, str) { - t.FailNow() - } -} - -// HTTPError asserts that a specified handler returns an error status code. -// -// assert.HTTPError(t, myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPError(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) { - if !assert.HTTPError(t, handler, method, url, values) { - t.FailNow() - } -} - -// HTTPRedirect asserts that a specified handler returns a redirect status code. -// -// assert.HTTPRedirect(t, myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPRedirect(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) { - if !assert.HTTPRedirect(t, handler, method, url, values) { - t.FailNow() - } -} - -// HTTPSuccess asserts that a specified handler returns a success status code. -// -// assert.HTTPSuccess(t, myHandler, "POST", "http://www.google.com", nil) -// -// Returns whether the assertion was successful (true) or not (false). -func HTTPSuccess(t TestingT, handler http.HandlerFunc, method string, url string, values url.Values) { - if !assert.HTTPSuccess(t, handler, method, url, values) { - t.FailNow() - } -} - -// Implements asserts that an object is implemented by the specified interface. -// -// assert.Implements(t, (*MyInterface)(nil), new(MyObject), "MyObject") -func Implements(t TestingT, interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { - if !assert.Implements(t, interfaceObject, object, msgAndArgs...) { - t.FailNow() - } -} - -// InDelta asserts that the two numerals are within delta of each other. -// -// assert.InDelta(t, math.Pi, (22 / 7.0), 0.01) -// -// Returns whether the assertion was successful (true) or not (false). -func InDelta(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { - if !assert.InDelta(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() - } -} - -// InDeltaSlice is the same as InDelta, except it compares two slices. -func InDeltaSlice(t TestingT, expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { - if !assert.InDeltaSlice(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() - } -} - -// InEpsilon asserts that expected and actual have a relative error less than epsilon -// -// Returns whether the assertion was successful (true) or not (false). -func InEpsilon(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { - if !assert.InEpsilon(t, expected, actual, epsilon, msgAndArgs...) { - t.FailNow() - } -} - -// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. -func InEpsilonSlice(t TestingT, expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { - if !assert.InEpsilonSlice(t, expected, actual, epsilon, msgAndArgs...) { - t.FailNow() - } -} - -// IsType asserts that the specified objects are of the same type. -func IsType(t TestingT, expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { - if !assert.IsType(t, expectedType, object, msgAndArgs...) { - t.FailNow() - } -} - -// JSONEq asserts that two JSON strings are equivalent. -// -// assert.JSONEq(t, `{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) -// -// Returns whether the assertion was successful (true) or not (false). -func JSONEq(t TestingT, expected string, actual string, msgAndArgs ...interface{}) { - if !assert.JSONEq(t, expected, actual, msgAndArgs...) { - t.FailNow() - } -} - -// Len asserts that the specified object has specific length. -// Len also fails if the object has a type that len() not accept. -// -// assert.Len(t, mySlice, 3, "The size of slice is not 3") -// -// Returns whether the assertion was successful (true) or not (false). -func Len(t TestingT, object interface{}, length int, msgAndArgs ...interface{}) { - if !assert.Len(t, object, length, msgAndArgs...) { - t.FailNow() - } -} - -// Nil asserts that the specified object is nil. -// -// assert.Nil(t, err, "err should be nothing") -// -// Returns whether the assertion was successful (true) or not (false). -func Nil(t TestingT, object interface{}, msgAndArgs ...interface{}) { - if !assert.Nil(t, object, msgAndArgs...) { - t.FailNow() - } -} - -// NoError asserts that a function returned no error (i.e. `nil`). -// -// actualObj, err := SomeFunction() -// if assert.NoError(t, err) { -// assert.Equal(t, actualObj, expectedObj) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func NoError(t TestingT, err error, msgAndArgs ...interface{}) { - if !assert.NoError(t, err, msgAndArgs...) { - t.FailNow() - } -} - -// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the -// specified substring or element. -// -// assert.NotContains(t, "Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'") -// assert.NotContains(t, ["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'") -// assert.NotContains(t, {"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'") -// -// Returns whether the assertion was successful (true) or not (false). -func NotContains(t TestingT, s interface{}, contains interface{}, msgAndArgs ...interface{}) { - if !assert.NotContains(t, s, contains, msgAndArgs...) { - t.FailNow() - } -} - -// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// if assert.NotEmpty(t, obj) { -// assert.Equal(t, "two", obj[1]) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func NotEmpty(t TestingT, object interface{}, msgAndArgs ...interface{}) { - if !assert.NotEmpty(t, object, msgAndArgs...) { - t.FailNow() - } -} - -// NotEqual asserts that the specified values are NOT equal. -// -// assert.NotEqual(t, obj1, obj2, "two objects shouldn't be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func NotEqual(t TestingT, expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - if !assert.NotEqual(t, expected, actual, msgAndArgs...) { - t.FailNow() - } -} - -// NotNil asserts that the specified object is not nil. -// -// assert.NotNil(t, err, "err should be something") -// -// Returns whether the assertion was successful (true) or not (false). -func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) { - if !assert.NotNil(t, object, msgAndArgs...) { - t.FailNow() - } -} - -// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. -// -// assert.NotPanics(t, func(){ -// RemainCalm() -// }, "Calling RemainCalm() should NOT panic") -// -// Returns whether the assertion was successful (true) or not (false). -func NotPanics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { - if !assert.NotPanics(t, f, msgAndArgs...) { - t.FailNow() - } -} - -// NotRegexp asserts that a specified regexp does not match a string. -// -// assert.NotRegexp(t, regexp.MustCompile("starts"), "it's starting") -// assert.NotRegexp(t, "^start", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func NotRegexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { - if !assert.NotRegexp(t, rx, str, msgAndArgs...) { - t.FailNow() - } -} - -// NotZero asserts that i is not the zero value for its type and returns the truth. -func NotZero(t TestingT, i interface{}, msgAndArgs ...interface{}) { - if !assert.NotZero(t, i, msgAndArgs...) { - t.FailNow() - } -} - -// Panics asserts that the code inside the specified PanicTestFunc panics. -// -// assert.Panics(t, func(){ -// GoCrazy() -// }, "Calling GoCrazy() should panic") -// -// Returns whether the assertion was successful (true) or not (false). -func Panics(t TestingT, f assert.PanicTestFunc, msgAndArgs ...interface{}) { - if !assert.Panics(t, f, msgAndArgs...) { - t.FailNow() - } -} - -// Regexp asserts that a specified regexp matches a string. -// -// assert.Regexp(t, regexp.MustCompile("start"), "it's starting") -// assert.Regexp(t, "start...$", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func Regexp(t TestingT, rx interface{}, str interface{}, msgAndArgs ...interface{}) { - if !assert.Regexp(t, rx, str, msgAndArgs...) { - t.FailNow() - } -} - -// True asserts that the specified value is true. -// -// assert.True(t, myBool, "myBool should be true") -// -// Returns whether the assertion was successful (true) or not (false). -func True(t TestingT, value bool, msgAndArgs ...interface{}) { - if !assert.True(t, value, msgAndArgs...) { - t.FailNow() - } -} - -// WithinDuration asserts that the two times are within duration delta of each other. -// -// assert.WithinDuration(t, time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s") -// -// Returns whether the assertion was successful (true) or not (false). -func WithinDuration(t TestingT, expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { - if !assert.WithinDuration(t, expected, actual, delta, msgAndArgs...) { - t.FailNow() - } -} - -// Zero asserts that i is the zero value for its type and returns the truth. -func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) { - if !assert.Zero(t, i, msgAndArgs...) { - t.FailNow() - } -} diff --git a/components/engine/vendor/github.com/stretchr/testify/require/require_forward.go b/components/engine/vendor/github.com/stretchr/testify/require/require_forward.go deleted file mode 100644 index caa18793df..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/require/require_forward.go +++ /dev/null @@ -1,353 +0,0 @@ -/* -* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen -* THIS FILE MUST NOT BE EDITED BY HAND - */ - -package require - -import ( - assert "github.com/stretchr/testify/assert" - http "net/http" - url "net/url" - time "time" -) - -// Condition uses a Comparison to assert a complex condition. -func (a *Assertions) Condition(comp assert.Comparison, msgAndArgs ...interface{}) { - Condition(a.t, comp, msgAndArgs...) -} - -// Contains asserts that the specified string, list(array, slice...) or map contains the -// specified substring or element. -// -// a.Contains("Hello World", "World", "But 'Hello World' does contain 'World'") -// a.Contains(["Hello", "World"], "World", "But ["Hello", "World"] does contain 'World'") -// a.Contains({"Hello": "World"}, "Hello", "But {'Hello': 'World'} does contain 'Hello'") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Contains(s interface{}, contains interface{}, msgAndArgs ...interface{}) { - Contains(a.t, s, contains, msgAndArgs...) -} - -// Empty asserts that the specified object is empty. I.e. nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// a.Empty(obj) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Empty(object interface{}, msgAndArgs ...interface{}) { - Empty(a.t, object, msgAndArgs...) -} - -// Equal asserts that two objects are equal. -// -// a.Equal(123, 123, "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func (a *Assertions) Equal(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - Equal(a.t, expected, actual, msgAndArgs...) -} - -// EqualError asserts that a function returned an error (i.e. not `nil`) -// and that it is equal to the provided error. -// -// actualObj, err := SomeFunction() -// a.EqualError(err, expectedErrorString, "An error was expected") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) EqualError(theError error, errString string, msgAndArgs ...interface{}) { - EqualError(a.t, theError, errString, msgAndArgs...) -} - -// EqualValues asserts that two objects are equal or convertable to the same types -// and equal. -// -// a.EqualValues(uint32(123), int32(123), "123 and 123 should be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) EqualValues(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - EqualValues(a.t, expected, actual, msgAndArgs...) -} - -// Error asserts that a function returned an error (i.e. not `nil`). -// -// actualObj, err := SomeFunction() -// if a.Error(err, "An error was expected") { -// assert.Equal(t, err, expectedError) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Error(err error, msgAndArgs ...interface{}) { - Error(a.t, err, msgAndArgs...) -} - -// Exactly asserts that two objects are equal is value and type. -// -// a.Exactly(int32(123), int64(123), "123 and 123 should NOT be equal") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Exactly(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - Exactly(a.t, expected, actual, msgAndArgs...) -} - -// Fail reports a failure through -func (a *Assertions) Fail(failureMessage string, msgAndArgs ...interface{}) { - Fail(a.t, failureMessage, msgAndArgs...) -} - -// FailNow fails test -func (a *Assertions) FailNow(failureMessage string, msgAndArgs ...interface{}) { - FailNow(a.t, failureMessage, msgAndArgs...) -} - -// False asserts that the specified value is false. -// -// a.False(myBool, "myBool should be false") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) False(value bool, msgAndArgs ...interface{}) { - False(a.t, value, msgAndArgs...) -} - -// HTTPBodyContains asserts that a specified handler returns a -// body that contains a string. -// -// a.HTTPBodyContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPBodyContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) { - HTTPBodyContains(a.t, handler, method, url, values, str) -} - -// HTTPBodyNotContains asserts that a specified handler returns a -// body that does not contain a string. -// -// a.HTTPBodyNotContains(myHandler, "www.google.com", nil, "I'm Feeling Lucky") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPBodyNotContains(handler http.HandlerFunc, method string, url string, values url.Values, str interface{}) { - HTTPBodyNotContains(a.t, handler, method, url, values, str) -} - -// HTTPError asserts that a specified handler returns an error status code. -// -// a.HTTPError(myHandler, "POST", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPError(handler http.HandlerFunc, method string, url string, values url.Values) { - HTTPError(a.t, handler, method, url, values) -} - -// HTTPRedirect asserts that a specified handler returns a redirect status code. -// -// a.HTTPRedirect(myHandler, "GET", "/a/b/c", url.Values{"a": []string{"b", "c"}} -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPRedirect(handler http.HandlerFunc, method string, url string, values url.Values) { - HTTPRedirect(a.t, handler, method, url, values) -} - -// HTTPSuccess asserts that a specified handler returns a success status code. -// -// a.HTTPSuccess(myHandler, "POST", "http://www.google.com", nil) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) HTTPSuccess(handler http.HandlerFunc, method string, url string, values url.Values) { - HTTPSuccess(a.t, handler, method, url, values) -} - -// Implements asserts that an object is implemented by the specified interface. -// -// a.Implements((*MyInterface)(nil), new(MyObject), "MyObject") -func (a *Assertions) Implements(interfaceObject interface{}, object interface{}, msgAndArgs ...interface{}) { - Implements(a.t, interfaceObject, object, msgAndArgs...) -} - -// InDelta asserts that the two numerals are within delta of each other. -// -// a.InDelta(math.Pi, (22 / 7.0), 0.01) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) InDelta(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { - InDelta(a.t, expected, actual, delta, msgAndArgs...) -} - -// InDeltaSlice is the same as InDelta, except it compares two slices. -func (a *Assertions) InDeltaSlice(expected interface{}, actual interface{}, delta float64, msgAndArgs ...interface{}) { - InDeltaSlice(a.t, expected, actual, delta, msgAndArgs...) -} - -// InEpsilon asserts that expected and actual have a relative error less than epsilon -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) InEpsilon(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { - InEpsilon(a.t, expected, actual, epsilon, msgAndArgs...) -} - -// InEpsilonSlice is the same as InEpsilon, except it compares each value from two slices. -func (a *Assertions) InEpsilonSlice(expected interface{}, actual interface{}, epsilon float64, msgAndArgs ...interface{}) { - InEpsilonSlice(a.t, expected, actual, epsilon, msgAndArgs...) -} - -// IsType asserts that the specified objects are of the same type. -func (a *Assertions) IsType(expectedType interface{}, object interface{}, msgAndArgs ...interface{}) { - IsType(a.t, expectedType, object, msgAndArgs...) -} - -// JSONEq asserts that two JSON strings are equivalent. -// -// a.JSONEq(`{"hello": "world", "foo": "bar"}`, `{"foo": "bar", "hello": "world"}`) -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) JSONEq(expected string, actual string, msgAndArgs ...interface{}) { - JSONEq(a.t, expected, actual, msgAndArgs...) -} - -// Len asserts that the specified object has specific length. -// Len also fails if the object has a type that len() not accept. -// -// a.Len(mySlice, 3, "The size of slice is not 3") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Len(object interface{}, length int, msgAndArgs ...interface{}) { - Len(a.t, object, length, msgAndArgs...) -} - -// Nil asserts that the specified object is nil. -// -// a.Nil(err, "err should be nothing") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Nil(object interface{}, msgAndArgs ...interface{}) { - Nil(a.t, object, msgAndArgs...) -} - -// NoError asserts that a function returned no error (i.e. `nil`). -// -// actualObj, err := SomeFunction() -// if a.NoError(err) { -// assert.Equal(t, actualObj, expectedObj) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NoError(err error, msgAndArgs ...interface{}) { - NoError(a.t, err, msgAndArgs...) -} - -// NotContains asserts that the specified string, list(array, slice...) or map does NOT contain the -// specified substring or element. -// -// a.NotContains("Hello World", "Earth", "But 'Hello World' does NOT contain 'Earth'") -// a.NotContains(["Hello", "World"], "Earth", "But ['Hello', 'World'] does NOT contain 'Earth'") -// a.NotContains({"Hello": "World"}, "Earth", "But {'Hello': 'World'} does NOT contain 'Earth'") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotContains(s interface{}, contains interface{}, msgAndArgs ...interface{}) { - NotContains(a.t, s, contains, msgAndArgs...) -} - -// NotEmpty asserts that the specified object is NOT empty. I.e. not nil, "", false, 0 or either -// a slice or a channel with len == 0. -// -// if a.NotEmpty(obj) { -// assert.Equal(t, "two", obj[1]) -// } -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotEmpty(object interface{}, msgAndArgs ...interface{}) { - NotEmpty(a.t, object, msgAndArgs...) -} - -// NotEqual asserts that the specified values are NOT equal. -// -// a.NotEqual(obj1, obj2, "two objects shouldn't be equal") -// -// Returns whether the assertion was successful (true) or not (false). -// -// Pointer variable equality is determined based on the equality of the -// referenced values (as opposed to the memory addresses). -func (a *Assertions) NotEqual(expected interface{}, actual interface{}, msgAndArgs ...interface{}) { - NotEqual(a.t, expected, actual, msgAndArgs...) -} - -// NotNil asserts that the specified object is not nil. -// -// a.NotNil(err, "err should be something") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotNil(object interface{}, msgAndArgs ...interface{}) { - NotNil(a.t, object, msgAndArgs...) -} - -// NotPanics asserts that the code inside the specified PanicTestFunc does NOT panic. -// -// a.NotPanics(func(){ -// RemainCalm() -// }, "Calling RemainCalm() should NOT panic") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotPanics(f assert.PanicTestFunc, msgAndArgs ...interface{}) { - NotPanics(a.t, f, msgAndArgs...) -} - -// NotRegexp asserts that a specified regexp does not match a string. -// -// a.NotRegexp(regexp.MustCompile("starts"), "it's starting") -// a.NotRegexp("^start", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) NotRegexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { - NotRegexp(a.t, rx, str, msgAndArgs...) -} - -// NotZero asserts that i is not the zero value for its type and returns the truth. -func (a *Assertions) NotZero(i interface{}, msgAndArgs ...interface{}) { - NotZero(a.t, i, msgAndArgs...) -} - -// Panics asserts that the code inside the specified PanicTestFunc panics. -// -// a.Panics(func(){ -// GoCrazy() -// }, "Calling GoCrazy() should panic") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Panics(f assert.PanicTestFunc, msgAndArgs ...interface{}) { - Panics(a.t, f, msgAndArgs...) -} - -// Regexp asserts that a specified regexp matches a string. -// -// a.Regexp(regexp.MustCompile("start"), "it's starting") -// a.Regexp("start...$", "it's not starting") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) Regexp(rx interface{}, str interface{}, msgAndArgs ...interface{}) { - Regexp(a.t, rx, str, msgAndArgs...) -} - -// True asserts that the specified value is true. -// -// a.True(myBool, "myBool should be true") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) True(value bool, msgAndArgs ...interface{}) { - True(a.t, value, msgAndArgs...) -} - -// WithinDuration asserts that the two times are within duration delta of each other. -// -// a.WithinDuration(time.Now(), time.Now(), 10*time.Second, "The difference should not be more than 10s") -// -// Returns whether the assertion was successful (true) or not (false). -func (a *Assertions) WithinDuration(expected time.Time, actual time.Time, delta time.Duration, msgAndArgs ...interface{}) { - WithinDuration(a.t, expected, actual, delta, msgAndArgs...) -} - -// Zero asserts that i is the zero value for its type and returns the truth. -func (a *Assertions) Zero(i interface{}, msgAndArgs ...interface{}) { - Zero(a.t, i, msgAndArgs...) -} diff --git a/components/engine/vendor/github.com/stretchr/testify/require/requirements.go b/components/engine/vendor/github.com/stretchr/testify/require/requirements.go deleted file mode 100644 index 41147562d8..0000000000 --- a/components/engine/vendor/github.com/stretchr/testify/require/requirements.go +++ /dev/null @@ -1,9 +0,0 @@ -package require - -// TestingT is an interface wrapper around *testing.T -type TestingT interface { - Errorf(format string, args ...interface{}) - FailNow() -} - -//go:generate go run ../_codegen/main.go -output-package=require -template=require.go.tmpl diff --git a/components/engine/volume/store/db_test.go b/components/engine/volume/store/db_test.go index 9c45cd13ba..0a2727e749 100644 --- a/components/engine/volume/store/db_test.go +++ b/components/engine/volume/store/db_test.go @@ -8,33 +8,34 @@ import ( "time" "github.com/boltdb/bolt" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestSetGetMeta(t *testing.T) { t.Parallel() dir, err := ioutil.TempDir("", "test-set-get") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dir) db, err := bolt.Open(filepath.Join(dir, "db"), 0600, &bolt.Options{Timeout: 1 * time.Second}) - require.NoError(t, err) + assert.NilError(t, err) store := &VolumeStore{db: db} _, err = store.getMeta("test") - require.Error(t, err) + assert.Assert(t, is.ErrorContains(err, "")) err = db.Update(func(tx *bolt.Tx) error { _, err := tx.CreateBucket(volumeBucketName) return err }) - require.NoError(t, err) + assert.NilError(t, err) meta, err := store.getMeta("test") - require.NoError(t, err) - require.Equal(t, volumeMetadata{}, meta) + assert.NilError(t, err) + assert.DeepEqual(t, volumeMetadata{}, meta) testMeta := volumeMetadata{ Name: "test", @@ -43,9 +44,9 @@ func TestSetGetMeta(t *testing.T) { Options: map[string]string{"foo": "bar"}, } err = store.setMeta("test", testMeta) - require.NoError(t, err) + assert.NilError(t, err) meta, err = store.getMeta("test") - require.NoError(t, err) - require.Equal(t, testMeta, meta) + assert.NilError(t, err) + assert.DeepEqual(t, testMeta, meta) } diff --git a/components/engine/volume/store/restore_test.go b/components/engine/volume/store/restore_test.go index 83efd36b63..680735a384 100644 --- a/components/engine/volume/store/restore_test.go +++ b/components/engine/volume/store/restore_test.go @@ -8,14 +8,14 @@ import ( "github.com/docker/docker/volume" volumedrivers "github.com/docker/docker/volume/drivers" volumetestutils "github.com/docker/docker/volume/testutils" - "github.com/stretchr/testify/require" + "github.com/gotestyourself/gotestyourself/assert" ) func TestRestore(t *testing.T) { t.Parallel() dir, err := ioutil.TempDir("", "test-restore") - require.NoError(t, err) + assert.NilError(t, err) defer os.RemoveAll(dir) driverName := "test-restore" @@ -23,33 +23,33 @@ func TestRestore(t *testing.T) { defer volumedrivers.Unregister("test-restore") s, err := New(dir) - require.NoError(t, err) + assert.NilError(t, err) defer s.Shutdown() _, err = s.Create("test1", driverName, nil, nil) - require.NoError(t, err) + assert.NilError(t, err) testLabels := map[string]string{"a": "1"} testOpts := map[string]string{"foo": "bar"} _, err = s.Create("test2", driverName, testOpts, testLabels) - require.NoError(t, err) + assert.NilError(t, err) s.Shutdown() s, err = New(dir) - require.NoError(t, err) + assert.NilError(t, err) v, err := s.Get("test1") - require.NoError(t, err) + assert.NilError(t, err) dv := v.(volume.DetailedVolume) var nilMap map[string]string - require.Equal(t, nilMap, dv.Options()) - require.Equal(t, nilMap, dv.Labels()) + assert.DeepEqual(t, nilMap, dv.Options()) + assert.DeepEqual(t, nilMap, dv.Labels()) v, err = s.Get("test2") - require.NoError(t, err) + assert.NilError(t, err) dv = v.(volume.DetailedVolume) - require.Equal(t, testOpts, dv.Options()) - require.Equal(t, testLabels, dv.Labels()) + assert.DeepEqual(t, testOpts, dv.Options()) + assert.DeepEqual(t, testLabels, dv.Labels()) } diff --git a/components/engine/volume/store/store_test.go b/components/engine/volume/store/store_test.go index e53c728dd0..faf4035e29 100644 --- a/components/engine/volume/store/store_test.go +++ b/components/engine/volume/store/store_test.go @@ -12,8 +12,9 @@ import ( "github.com/docker/docker/volume" "github.com/docker/docker/volume/drivers" volumetestutils "github.com/docker/docker/volume/testutils" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" + "github.com/google/go-cmp/cmp" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestCreate(t *testing.T) { @@ -332,15 +333,15 @@ func TestRefDerefRemove(t *testing.T) { defer cleanup(t) v, err := s.CreateWithRef("test", driverName, "test-ref", nil, nil) - require.NoError(t, err) + assert.NilError(t, err) err = s.Remove(v) - require.Error(t, err) - require.Equal(t, errVolumeInUse, err.(*OpErr).Err) + assert.Assert(t, is.ErrorContains(err, "")) + assert.Equal(t, errVolumeInUse, err.(*OpErr).Err) s.Dereference(v, "test-ref") err = s.Remove(v) - require.NoError(t, err) + assert.NilError(t, err) } func TestGet(t *testing.T) { @@ -351,21 +352,21 @@ func TestGet(t *testing.T) { defer cleanup(t) _, err := s.Get("not-exist") - require.Error(t, err) - require.Equal(t, errNoSuchVolume, err.(*OpErr).Err) + assert.Assert(t, is.ErrorContains(err, "")) + assert.Equal(t, errNoSuchVolume, err.(*OpErr).Err) v1, err := s.Create("test", driverName, nil, map[string]string{"a": "1"}) - require.NoError(t, err) + assert.NilError(t, err) v2, err := s.Get("test") - require.NoError(t, err) - require.Equal(t, v1, v2) + assert.NilError(t, err) + assert.DeepEqual(t, v1, v2, cmpVolume) dv := v2.(volume.DetailedVolume) - require.Equal(t, "1", dv.Labels()["a"]) + assert.Equal(t, "1", dv.Labels()["a"]) err = s.Remove(v1) - require.NoError(t, err) + assert.NilError(t, err) } func TestGetWithRef(t *testing.T) { @@ -376,24 +377,26 @@ func TestGetWithRef(t *testing.T) { defer cleanup(t) _, err := s.GetWithRef("not-exist", driverName, "test-ref") - require.Error(t, err) + assert.Assert(t, is.ErrorContains(err, "")) v1, err := s.Create("test", driverName, nil, map[string]string{"a": "1"}) - require.NoError(t, err) + assert.NilError(t, err) v2, err := s.GetWithRef("test", driverName, "test-ref") - require.NoError(t, err) - require.Equal(t, v1, v2) + assert.NilError(t, err) + assert.DeepEqual(t, v1, v2, cmpVolume) err = s.Remove(v2) - require.Error(t, err) - require.Equal(t, errVolumeInUse, err.(*OpErr).Err) + assert.Assert(t, is.ErrorContains(err, "")) + assert.Equal(t, errVolumeInUse, err.(*OpErr).Err) s.Dereference(v2, "test-ref") err = s.Remove(v2) - require.NoError(t, err) + assert.NilError(t, err) } +var cmpVolume = cmp.AllowUnexported(volumetestutils.FakeVolume{}, volumeWrapper{}) + func setupTest(t *testing.T, name string) (*VolumeStore, func(*testing.T)) { t.Helper() s, cleanup := newTestStore(t) @@ -409,15 +412,15 @@ func newTestStore(t *testing.T) (*VolumeStore, func(*testing.T)) { t.Helper() dir, err := ioutil.TempDir("", "store-root") - require.NoError(t, err) + assert.NilError(t, err) cleanup := func(t *testing.T) { err := os.RemoveAll(dir) - assert.NoError(t, err) + assert.Check(t, err) } s, err := New(dir) - assert.NoError(t, err) + assert.Check(t, err) return s, func(t *testing.T) { s.Shutdown() cleanup(t)