From 55bebbaecf5e40db9d83b28080ce08dc8642f407 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Mon, 21 May 2018 00:06:50 +0200 Subject: [PATCH] Replace deprecated testutil.ErrorContains() Signed-off-by: Sebastiaan van Stijn --- builder/dockerfile/evaluator_test.go | 5 +-- builder/dockerfile/instructions/parse_test.go | 31 +++++++++---------- builder/dockerfile/internals_windows_test.go | 3 +- builder/remotecontext/remote_test.go | 3 +- client/client_test.go | 3 +- client/container_logs_test.go | 10 +++--- client/swarm_get_unlock_key_test.go | 3 +- client/volume_inspect_test.go | 3 +- cmd/dockerd/daemon_test.go | 5 ++- daemon/config/config_test.go | 17 +++------- daemon/delete_test.go | 9 +++--- .../jsonlog/time_marshalling_test.go | 5 ++- daemon/trustkey_test.go | 3 +- distribution/pull_v2_test.go | 5 +-- image/fs_test.go | 25 +++++++-------- integration/config/config_test.go | 5 ++- integration/container/copy_test.go | 13 ++++---- integration/container/create_test.go | 9 +++--- integration/container/pause_test.go | 3 +- integration/container/remove_test.go | 7 ++--- integration/container/rename_test.go | 9 +++--- integration/container/resize_test.go | 3 +- integration/container/update_test.go | 3 +- integration/image/remove_test.go | 3 +- integration/image/tag_test.go | 17 +++++----- integration/secret/secret_test.go | 9 +++--- integration/volume/volume_test.go | 3 +- internal/testutil/helpers.go | 16 ---------- 28 files changed, 95 insertions(+), 135 deletions(-) diff --git a/builder/dockerfile/evaluator_test.go b/builder/dockerfile/evaluator_test.go index 4d0f6c30ec..0a64b9fdd6 100644 --- a/builder/dockerfile/evaluator_test.go +++ b/builder/dockerfile/evaluator_test.go @@ -6,9 +6,10 @@ import ( "github.com/docker/docker/builder/dockerfile/instructions" "github.com/docker/docker/builder/remotecontext" - "github.com/docker/docker/internal/testutil" "github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/reexec" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" ) @@ -139,5 +140,5 @@ func executeTestCase(t *testing.T, testCase dispatchTestCase) { b := newBuilderWithMockBackend() sb := newDispatchRequest(b, '`', context, NewBuildArgs(make(map[string]*string)), newStagesBuildResults()) err = dispatch(sb, testCase.cmd) - testutil.ErrorContains(t, err, testCase.expectedError) + assert.Check(t, is.ErrorContains(err, testCase.expectedError)) } diff --git a/builder/dockerfile/instructions/parse_test.go b/builder/dockerfile/instructions/parse_test.go index 242630f72a..f5eeea5719 100644 --- a/builder/dockerfile/instructions/parse_test.go +++ b/builder/dockerfile/instructions/parse_test.go @@ -6,7 +6,6 @@ import ( "github.com/docker/docker/builder/dockerfile/command" "github.com/docker/docker/builder/dockerfile/parser" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" ) @@ -19,11 +18,11 @@ func TestCommandsExactlyOneArgument(t *testing.T) { "STOPSIGNAL", } - for _, command := range commands { - ast, err := parser.Parse(strings.NewReader(command)) + for _, cmd := range commands { + ast, err := parser.Parse(strings.NewReader(cmd)) assert.NilError(t, err) _, err = ParseInstruction(ast.AST.Children[0]) - assert.Check(t, is.Error(err, errExactlyOneArgument(command).Error())) + assert.Check(t, is.Error(err, errExactlyOneArgument(cmd).Error())) } } @@ -37,11 +36,11 @@ func TestCommandsAtLeastOneArgument(t *testing.T) { "VOLUME", } - for _, command := range commands { - ast, err := parser.Parse(strings.NewReader(command)) + for _, cmd := range commands { + ast, err := parser.Parse(strings.NewReader(cmd)) assert.NilError(t, err) _, err = ParseInstruction(ast.AST.Children[0]) - assert.Check(t, is.Error(err, errAtLeastOneArgument(command).Error())) + assert.Check(t, is.Error(err, errAtLeastOneArgument(cmd).Error())) } } @@ -51,11 +50,11 @@ func TestCommandsNoDestinationArgument(t *testing.T) { "COPY", } - for _, command := range commands { - ast, err := parser.Parse(strings.NewReader(command + " arg1")) + for _, cmd := range commands { + ast, err := parser.Parse(strings.NewReader(cmd + " arg1")) assert.NilError(t, err) _, err = ParseInstruction(ast.AST.Children[0]) - assert.Check(t, is.Error(err, errNoDestinationArgument(command).Error())) + assert.Check(t, is.Error(err, errNoDestinationArgument(cmd).Error())) } } @@ -90,10 +89,10 @@ func TestCommandsBlankNames(t *testing.T) { "LABEL", } - for _, command := range commands { + for _, cmd := range commands { node := &parser.Node{ - Original: command + " =arg2", - Value: strings.ToLower(command), + Original: cmd + " =arg2", + Value: strings.ToLower(cmd), Next: &parser.Node{ Value: "", Next: &parser.Node{ @@ -102,7 +101,7 @@ func TestCommandsBlankNames(t *testing.T) { }, } _, err := ParseInstruction(node) - assert.Check(t, is.Error(err, errBlankCommandNames(command).Error())) + assert.Check(t, is.Error(err, errBlankCommandNames(cmd).Error())) } } @@ -134,7 +133,7 @@ func TestParseOptInterval(t *testing.T) { Value: "50ns", } _, err := parseOptInterval(flInterval) - testutil.ErrorContains(t, err, "cannot be less than 1ms") + assert.Check(t, is.ErrorContains(err, "cannot be less than 1ms")) flInterval.Value = "1ms" _, err = parseOptInterval(flInterval) @@ -194,6 +193,6 @@ func TestErrorCases(t *testing.T) { } n := ast.AST.Children[0] _, err = ParseInstruction(n) - testutil.ErrorContains(t, err, c.expectedError) + assert.Check(t, is.ErrorContains(err, c.expectedError)) } } diff --git a/builder/dockerfile/internals_windows_test.go b/builder/dockerfile/internals_windows_test.go index 1fc55c0752..ffe52fb132 100644 --- a/builder/dockerfile/internals_windows_test.go +++ b/builder/dockerfile/internals_windows_test.go @@ -6,7 +6,6 @@ import ( "fmt" "testing" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" ) @@ -48,7 +47,7 @@ func TestNormalizeDest(t *testing.T) { } assert.Check(t, is.Equal(testcase.expected, actual), msg) } else { - testutil.ErrorContains(t, err, testcase.etext) + assert.Check(t, is.ErrorContains(err, testcase.etext)) } } } diff --git a/builder/remotecontext/remote_test.go b/builder/remotecontext/remote_test.go index 5267d23969..64442d5107 100644 --- a/builder/remotecontext/remote_test.go +++ b/builder/remotecontext/remote_test.go @@ -10,7 +10,6 @@ import ( "testing" "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" @@ -232,7 +231,7 @@ func TestGetWithStatusError(t *testing.T) { assert.NilError(t, err) assert.Check(t, is.Contains(string(body), testcase.expectedBody)) } else { - testutil.ErrorContains(t, err, testcase.expectedErr) + assert.Check(t, is.ErrorContains(err, testcase.expectedErr)) } } } diff --git a/client/client_test.go b/client/client_test.go index 7cca04ac72..fbf29d5639 100644 --- a/client/client_test.go +++ b/client/client_test.go @@ -10,7 +10,6 @@ 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" @@ -162,7 +161,7 @@ func TestParseHostURL(t *testing.T) { for _, testcase := range testcases { actual, err := ParseHostURL(testcase.host) if testcase.expectedErr != "" { - testutil.ErrorContains(t, err, testcase.expectedErr) + assert.Check(t, is.ErrorContains(err, testcase.expectedErr)) } assert.Check(t, is.DeepEqual(testcase.expected, actual)) } diff --git a/client/container_logs_test.go b/client/container_logs_test.go index b1f5c8ddba..cbdab168f6 100644 --- a/client/container_logs_test.go +++ b/client/container_logs_test.go @@ -2,6 +2,7 @@ package client // import "github.com/docker/docker/client" import ( "bytes" + "context" "fmt" "io" "io/ioutil" @@ -12,10 +13,9 @@ import ( "testing" "time" - "context" - "github.com/docker/docker/api/types" - "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func TestContainerLogsNotFoundError(t *testing.T) { @@ -39,11 +39,11 @@ func TestContainerLogsError(t *testing.T) { _, err = client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{ Since: "2006-01-02TZ", }) - testutil.ErrorContains(t, err, `parsing time "2006-01-02TZ"`) + assert.Check(t, is.ErrorContains(err, `parsing time "2006-01-02TZ"`)) _, err = client.ContainerLogs(context.Background(), "container_id", types.ContainerLogsOptions{ Until: "2006-01-02TZ", }) - testutil.ErrorContains(t, err, `parsing time "2006-01-02TZ"`) + assert.Check(t, is.ErrorContains(err, `parsing time "2006-01-02TZ"`)) } func TestContainerLogs(t *testing.T) { diff --git a/client/swarm_get_unlock_key_test.go b/client/swarm_get_unlock_key_test.go index 41b067affd..be822cb8aa 100644 --- a/client/swarm_get_unlock_key_test.go +++ b/client/swarm_get_unlock_key_test.go @@ -11,7 +11,6 @@ import ( "testing" "github.com/docker/docker/api/types" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" ) @@ -22,7 +21,7 @@ func TestSwarmGetUnlockKeyError(t *testing.T) { } _, err := client.SwarmGetUnlockKey(context.Background()) - testutil.ErrorContains(t, err, "Error response from daemon: Server error") + assert.Check(t, is.ErrorContains(err, "Error response from daemon: Server error")) } func TestSwarmGetUnlockKey(t *testing.T) { diff --git a/client/volume_inspect_test.go b/client/volume_inspect_test.go index 8c18bca07b..d0a3246689 100644 --- a/client/volume_inspect_test.go +++ b/client/volume_inspect_test.go @@ -11,7 +11,6 @@ import ( "testing" "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" @@ -23,7 +22,7 @@ func TestVolumeInspectError(t *testing.T) { } _, err := client.VolumeInspect(context.Background(), "nothing") - testutil.ErrorContains(t, err, "Error response from daemon: Server error") + assert.Check(t, is.ErrorContains(err, "Error response from daemon: Server error")) } func TestVolumeInspectNotFound(t *testing.T) { diff --git a/cmd/dockerd/daemon_test.go b/cmd/dockerd/daemon_test.go index e5c2c2ec7c..539b442cbd 100644 --- a/cmd/dockerd/daemon_test.go +++ b/cmd/dockerd/daemon_test.go @@ -4,7 +4,6 @@ import ( "testing" "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" @@ -58,7 +57,7 @@ func TestLoadDaemonCliConfigWithConflicts(t *testing.T) { assert.Check(t, flags.Set("label", "l2=baz")) _, err := loadDaemonCliConfig(opts) - testutil.ErrorContains(t, err, "as a flag and in the configuration file: labels") + assert.Check(t, is.ErrorContains(err, "as a flag and in the configuration file: labels")) } func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) { @@ -74,7 +73,7 @@ func TestLoadDaemonCliWithConflictingNodeGenericResources(t *testing.T) { 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") + assert.Check(t, is.ErrorContains(err, "as a flag and in the configuration file: node-generic-resources")) } func TestLoadDaemonCliWithConflictingLabels(t *testing.T) { diff --git a/daemon/config/config_test.go b/daemon/config/config_test.go index a18b84da97..cb7aa74071 100644 --- a/daemon/config/config_test.go +++ b/daemon/config/config_test.go @@ -7,7 +7,6 @@ import ( "testing" "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" @@ -62,10 +61,7 @@ func TestFindConfigurationConflicts(t *testing.T) { flags.String("authorization-plugins", "", "") assert.Check(t, flags.Set("authorization-plugins", "asdf")) - - testutil.ErrorContains(t, - findConfigurationConflicts(config, flags), - "authorization-plugins: (from flag: asdf, from file: foobar)") + assert.Check(t, is.ErrorContains(findConfigurationConflicts(config, flags), "authorization-plugins: (from flag: asdf, from file: foobar)")) } func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) { @@ -76,8 +72,7 @@ func TestFindConfigurationConflictsWithNamedOptions(t *testing.T) { flags.VarP(opts.NewNamedListOptsRef("hosts", &hosts, opts.ValidateHost), "host", "H", "Daemon socket(s) to connect to") 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") + assert.Check(t, is.ErrorContains(findConfigurationConflicts(config, flags), "hosts")) } func TestDaemonConfigurationMergeConflicts(t *testing.T) { @@ -460,8 +455,7 @@ func TestReloadSetConfigFileNotExist(t *testing.T) { flags.Set("config-file", configFile) err := Reload(configFile, flags, func(c *Config) {}) - assert.Check(t, is.ErrorContains(err, "")) - testutil.ErrorContains(t, err, "unable to configure the Docker daemon with file") + assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file")) } // TestReloadDefaultConfigNotExist tests that if the default configuration file @@ -494,8 +488,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.Check(t, is.ErrorContains(err, "")) - testutil.ErrorContains(t, err, "unable to configure the Docker daemon with file") + assert.Check(t, is.ErrorContains(err, "unable to configure the Docker daemon with file")) } func TestReloadWithConflictingLabels(t *testing.T) { @@ -508,7 +501,7 @@ func TestReloadWithConflictingLabels(t *testing.T) { flags.String("config-file", configFile, "") flags.StringSlice("labels", lbls, "") err := Reload(configFile, flags, func(c *Config) {}) - testutil.ErrorContains(t, err, "conflict labels for foo=baz and foo=bar") + assert.Check(t, is.ErrorContains(err, "conflict labels for foo=baz and foo=bar")) } func TestReloadWithDuplicateLabels(t *testing.T) { diff --git a/daemon/delete_test.go b/daemon/delete_test.go index 8bfa5d8170..4af206d9c6 100644 --- a/daemon/delete_test.go +++ b/daemon/delete_test.go @@ -9,8 +9,8 @@ import ( "github.com/docker/docker/api/types" containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/container" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" ) func newDaemonWithTmpRoot(t *testing.T) (*Daemon, func()) { @@ -30,7 +30,6 @@ func newContainerWithState(state *container.State) *container.Container { State: state, Config: &containertypes.Config{}, } - } // TestContainerDelete tests that a useful error message and instructions is @@ -74,8 +73,8 @@ func TestContainerDelete(t *testing.T) { d.containers.Add(c.ID, c) err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: false}) - testutil.ErrorContains(t, err, te.errMsg) - testutil.ErrorContains(t, err, te.fixMsg) + assert.Check(t, is.ErrorContains(err, te.errMsg)) + assert.Check(t, is.ErrorContains(err, te.fixMsg)) } } @@ -92,5 +91,5 @@ func TestContainerDoubleDelete(t *testing.T) { // Try to remove the container when its state is removalInProgress. // It should return an error indicating it is under removal progress. err := d.ContainerRm(c.ID, &types.ContainerRmConfig{ForceRemove: true}) - testutil.ErrorContains(t, err, fmt.Sprintf("removal of container %s is already in progress", c.ID)) + assert.Check(t, is.ErrorContains(err, fmt.Sprintf("removal of container %s is already in progress", c.ID))) } diff --git a/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go b/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go index 76f299a0f6..3cfdcc33db 100644 --- a/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go +++ b/daemon/logger/jsonfilelog/jsonlog/time_marshalling_test.go @@ -4,7 +4,6 @@ import ( "testing" "time" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" ) @@ -12,11 +11,11 @@ import ( func TestFastTimeMarshalJSONWithInvalidYear(t *testing.T) { aTime := time.Date(-1, 1, 1, 0, 0, 0, 0, time.Local) _, err := fastTimeMarshalJSON(aTime) - testutil.ErrorContains(t, err, "year outside of range") + assert.Check(t, is.ErrorContains(err, "year outside of range")) anotherTime := time.Date(10000, 1, 1, 0, 0, 0, 0, time.Local) _, err = fastTimeMarshalJSON(anotherTime) - testutil.ErrorContains(t, err, "year outside of range") + assert.Check(t, is.ErrorContains(err, "year outside of range")) } func TestFastTimeMarshalJSON(t *testing.T) { diff --git a/daemon/trustkey_test.go b/daemon/trustkey_test.go index ebc7e28ee3..e13129e467 100644 --- a/daemon/trustkey_test.go +++ b/daemon/trustkey_test.go @@ -6,7 +6,6 @@ import ( "path/filepath" "testing" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" @@ -22,7 +21,7 @@ func TestLoadOrCreateTrustKeyInvalidKeyFile(t *testing.T) { assert.NilError(t, err) _, err = loadOrCreateTrustKey(tmpKeyFile.Name()) - testutil.ErrorContains(t, err, "Error loading key file") + assert.Check(t, is.ErrorContains(err, "Error loading key file")) } func TestLoadOrCreateTrustKeyCreateKeyWhenFileDoesNotExist(t *testing.T) { diff --git a/distribution/pull_v2_test.go b/distribution/pull_v2_test.go index 28cbb3e9d3..1079b5fe53 100644 --- a/distribution/pull_v2_test.go +++ b/distribution/pull_v2_test.go @@ -10,7 +10,8 @@ import ( "github.com/docker/distribution/manifest/schema1" "github.com/docker/distribution/reference" - "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/opencontainers/go-digest" ) @@ -104,7 +105,7 @@ func TestFixManifestLayersBadParent(t *testing.T) { } err := fixManifestLayers(&duplicateLayerManifest) - testutil.ErrorContains(t, err, "invalid parent ID") + assert.Check(t, is.ErrorContains(err, "invalid parent ID")) } // TestValidateManifest verifies the validateManifest function diff --git a/image/fs_test.go b/image/fs_test.go index dcf4da75f8..e8c120a003 100644 --- a/image/fs_test.go +++ b/image/fs_test.go @@ -10,10 +10,9 @@ import ( "path/filepath" "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/opencontainers/go-digest" ) func defaultFSStoreBackend(t *testing.T) (StoreBackend, func()) { @@ -39,7 +38,7 @@ func TestFSGetInvalidData(t *testing.T) { assert.Check(t, err) _, err = store.Get(id) - testutil.ErrorContains(t, err, "failed to verify") + assert.Check(t, is.ErrorContains(err, "failed to verify")) } func TestFSInvalidSet(t *testing.T) { @@ -51,7 +50,7 @@ func TestFSInvalidSet(t *testing.T) { assert.Check(t, err) _, err = store.Set([]byte("foobar")) - testutil.ErrorContains(t, err, "failed to write digest data") + assert.Check(t, is.ErrorContains(err, "failed to write digest data")) } func TestFSInvalidRoot(t *testing.T) { @@ -78,7 +77,7 @@ func TestFSInvalidRoot(t *testing.T) { f.Close() _, err = NewFSStoreBackend(root) - testutil.ErrorContains(t, err, "failed to create storage backend") + assert.Check(t, is.ErrorContains(err, "failed to create storage backend")) os.RemoveAll(root) } @@ -116,14 +115,14 @@ func TestFSMetadataGetSet(t *testing.T) { } _, err = store.GetMetadata(id2, "tkey2") - testutil.ErrorContains(t, err, "failed to read metadata") + assert.Check(t, is.ErrorContains(err, "failed to read metadata")) id3 := digest.FromBytes([]byte("baz")) err = store.SetMetadata(id3, "tkey", []byte("tval")) - testutil.ErrorContains(t, err, "failed to get digest") + assert.Check(t, is.ErrorContains(err, "failed to get digest")) _, err = store.GetMetadata(id3, "tkey") - testutil.ErrorContains(t, err, "failed to get digest") + assert.Check(t, is.ErrorContains(err, "failed to get digest")) } func TestFSInvalidWalker(t *testing.T) { @@ -191,7 +190,7 @@ func TestFSGetUnsetKey(t *testing.T) { for _, key := range []digest.Digest{"foobar:abc", "sha256:abc", "sha256:c3ab8ff13720e8ad9047dd39466b3c8974e592c2fa383d4a3960714caef0c4f2a"} { _, err := store.Get(key) - testutil.ErrorContains(t, err, "failed to get digest") + assert.Check(t, is.ErrorContains(err, "failed to get digest")) } } @@ -201,7 +200,7 @@ func TestFSGetEmptyData(t *testing.T) { for _, emptyData := range [][]byte{nil, {}} { _, err := store.Set(emptyData) - testutil.ErrorContains(t, err, "invalid empty data") + assert.Check(t, is.ErrorContains(err, "invalid empty data")) } } @@ -219,7 +218,7 @@ func TestFSDelete(t *testing.T) { assert.Check(t, err) _, err = store.Get(id) - testutil.ErrorContains(t, err, "failed to get digest") + assert.Check(t, is.ErrorContains(err, "failed to get digest")) _, err = store.Get(id2) assert.Check(t, err) @@ -228,7 +227,7 @@ func TestFSDelete(t *testing.T) { assert.Check(t, err) _, err = store.Get(id2) - testutil.ErrorContains(t, err, "failed to get digest") + assert.Check(t, is.ErrorContains(err, "failed to get digest")) } func TestFSWalker(t *testing.T) { @@ -267,5 +266,5 @@ func TestFSWalkerStopOnError(t *testing.T) { err = store.Walk(func(id digest.Digest) error { return errors.New("what") }) - testutil.ErrorContains(t, err, "what") + assert.Check(t, is.ErrorContains(err, "what")) } diff --git a/integration/config/config_test.go b/integration/config/config_test.go index 949c3ae004..d698445f2b 100644 --- a/integration/config/config_test.go +++ b/integration/config/config_test.go @@ -13,7 +13,6 @@ import ( swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "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" @@ -136,7 +135,7 @@ func TestConfigsCreateAndDelete(t *testing.T) { assert.NilError(t, err) insp, _, err = client.ConfigInspectWithRaw(ctx, configID) - testutil.ErrorContains(t, err, "No such config") + assert.Check(t, is.ErrorContains(err, "No such config")) } func TestConfigsUpdate(t *testing.T) { @@ -190,7 +189,7 @@ func TestConfigsUpdate(t *testing.T) { // this test will produce an error in func UpdateConfig insp.Spec.Data = []byte("TESTINGDATA2") err = client.ConfigUpdate(ctx, configID, insp.Version, insp.Spec) - testutil.ErrorContains(t, err, "only updates to Labels are allowed") + assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed")) } func TestTemplatedConfig(t *testing.T) { diff --git a/integration/container/copy_test.go b/integration/container/copy_test.go index 766c0a1762..6794f98555 100644 --- a/integration/container/copy_test.go +++ b/integration/container/copy_test.go @@ -8,7 +8,6 @@ import ( "github.com/docker/docker/api/types" "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" @@ -22,9 +21,9 @@ func TestCopyFromContainerPathDoesNotExist(t *testing.T) { cid := container.Create(t, ctx, apiclient) _, _, err := apiclient.CopyFromContainer(ctx, cid, "/dne") - assert.Assert(t, client.IsErrNotFound(err)) + assert.Check(t, client.IsErrNotFound(err)) expected := fmt.Sprintf("No such container:path: %s:%s", cid, "/dne") - testutil.ErrorContains(t, err, expected) + assert.Check(t, is.ErrorContains(err, expected)) } func TestCopyFromContainerPathIsNotDir(t *testing.T) { @@ -36,7 +35,7 @@ func TestCopyFromContainerPathIsNotDir(t *testing.T) { cid := container.Create(t, ctx, apiclient) _, _, err := apiclient.CopyFromContainer(ctx, cid, "/etc/passwd/") - assert.Assert(t, is.Contains(err.Error(), "not a directory")) + assert.Assert(t, is.ErrorContains(err, "not a directory")) } func TestCopyToContainerPathDoesNotExist(t *testing.T) { @@ -48,9 +47,9 @@ func TestCopyToContainerPathDoesNotExist(t *testing.T) { cid := container.Create(t, ctx, apiclient) err := apiclient.CopyToContainer(ctx, cid, "/dne", nil, types.CopyToContainerOptions{}) - assert.Assert(t, client.IsErrNotFound(err)) + assert.Check(t, client.IsErrNotFound(err)) expected := fmt.Sprintf("No such container:path: %s:%s", cid, "/dne") - testutil.ErrorContains(t, err, expected) + assert.Check(t, is.ErrorContains(err, expected)) } func TestCopyToContainerPathIsNotDir(t *testing.T) { @@ -62,5 +61,5 @@ func TestCopyToContainerPathIsNotDir(t *testing.T) { cid := container.Create(t, ctx, apiclient) err := apiclient.CopyToContainer(ctx, cid, "/etc/passwd/", nil, types.CopyToContainerOptions{}) - assert.Assert(t, is.Contains(err.Error(), "not a directory")) + assert.Assert(t, is.ErrorContains(err, "not a directory")) } diff --git a/integration/container/create_test.go b/integration/container/create_test.go index 61a07bcc97..cea8c059cc 100644 --- a/integration/container/create_test.go +++ b/integration/container/create_test.go @@ -8,7 +8,8 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/network" "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" + "github.com/gotestyourself/gotestyourself/assert" + is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/skip" ) @@ -48,7 +49,7 @@ func TestCreateFailsWhenIdentifierDoesNotExist(t *testing.T) { &network.NetworkingConfig{}, "", ) - testutil.ErrorContains(t, err, tc.expectedError) + assert.Check(t, is.ErrorContains(err, tc.expectedError)) }) } } @@ -88,7 +89,7 @@ func TestCreateWithInvalidEnv(t *testing.T) { &network.NetworkingConfig{}, "", ) - testutil.ErrorContains(t, err, tc.expectedError) + assert.Check(t, is.ErrorContains(err, tc.expectedError)) }) } } @@ -133,6 +134,6 @@ func TestCreateTmpfsMountsTarget(t *testing.T) { &network.NetworkingConfig{}, "", ) - testutil.ErrorContains(t, err, tc.expectedError) + assert.Check(t, is.ErrorContains(err, tc.expectedError)) } } diff --git a/integration/container/pause_test.go b/integration/container/pause_test.go index e6ecbbc0b5..8854dd9fd9 100644 --- a/integration/container/pause_test.go +++ b/integration/container/pause_test.go @@ -12,7 +12,6 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" @@ -62,7 +61,7 @@ func TestPauseFailsOnWindowsServerContainers(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) err := client.ContainerPause(ctx, cID) - testutil.ErrorContains(t, err, "cannot pause Windows Server Containers") + assert.Check(t, is.ErrorContains(err, "cannot pause Windows Server Containers")) } func TestPauseStopPausedContainer(t *testing.T) { diff --git a/integration/container/remove_test.go b/integration/container/remove_test.go index 5596c88042..185f90cc00 100644 --- a/integration/container/remove_test.go +++ b/integration/container/remove_test.go @@ -10,7 +10,6 @@ import ( "github.com/docker/docker/api/types/filters" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/fs" @@ -50,7 +49,7 @@ func TestRemoveContainerWithRemovedVolume(t *testing.T) { assert.NilError(t, err) _, _, err = client.ContainerInspectWithRaw(ctx, cID, true) - testutil.ErrorContains(t, err, "No such container") + assert.Check(t, is.ErrorContains(err, "No such container")) } // Test case for #2099/#2125 @@ -87,7 +86,7 @@ func TestRemoveContainerRunning(t *testing.T) { cID := container.Run(t, ctx, client) err := client.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{}) - testutil.ErrorContains(t, err, "cannot remove a running container") + assert.Check(t, is.ErrorContains(err, "cannot remove a running container")) } func TestRemoveContainerForceRemoveRunning(t *testing.T) { @@ -109,5 +108,5 @@ func TestRemoveInvalidContainer(t *testing.T) { client := request.NewAPIClient(t) err := client.ContainerRemove(ctx, "unknown", types.ContainerRemoveOptions{}) - testutil.ErrorContains(t, err, "No such container") + assert.Check(t, is.ErrorContains(err, "No such container")) } diff --git a/integration/container/rename_test.go b/integration/container/rename_test.go index 4496b980b7..fd270052a5 100644 --- a/integration/container/rename_test.go +++ b/integration/container/rename_test.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/api/types/versions" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/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" @@ -89,7 +88,7 @@ func TestRenameRunningContainerAndReuse(t *testing.T) { assert.Check(t, is.Equal("/"+newName, inspect.Name)) _, err = client.ContainerInspect(ctx, oldName) - testutil.ErrorContains(t, err, "No such container: "+oldName) + assert.Check(t, is.ErrorContains(err, "No such container: "+oldName)) cID = container.Run(t, ctx, client, container.WithName(oldName)) poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) @@ -109,7 +108,7 @@ func TestRenameInvalidName(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) err := client.ContainerRename(ctx, oldName, "new:invalid") - testutil.ErrorContains(t, err, "Invalid container name") + assert.Check(t, is.ErrorContains(err, "Invalid container name")) inspect, err := client.ContainerInspect(ctx, oldName) assert.NilError(t, err) @@ -179,9 +178,9 @@ func TestRenameContainerWithSameName(t *testing.T) { poll.WaitOn(t, container.IsInState(ctx, client, cID, "running"), poll.WithDelay(100*time.Millisecond)) err := client.ContainerRename(ctx, oldName, oldName) - testutil.ErrorContains(t, err, "Renaming a container with the same name") + assert.Check(t, is.ErrorContains(err, "Renaming a container with the same name")) err = client.ContainerRename(ctx, cID, oldName) - testutil.ErrorContains(t, err, "Renaming a container with the same name") + assert.Check(t, is.ErrorContains(err, "Renaming a container with the same name")) } // Test case for GitHub issue 23973 diff --git a/integration/container/resize_test.go b/integration/container/resize_test.go index 892a5c1765..c6c4e81751 100644 --- a/integration/container/resize_test.go +++ b/integration/container/resize_test.go @@ -11,7 +11,6 @@ import ( "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/request" req "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" @@ -63,5 +62,5 @@ func TestResizeWhenContainerNotStarted(t *testing.T) { Height: 40, Width: 40, }) - testutil.ErrorContains(t, err, "is not running") + assert.Check(t, is.ErrorContains(err, "is not running")) } diff --git a/integration/container/update_test.go b/integration/container/update_test.go index 5e407e0c0b..2ac122aea7 100644 --- a/integration/container/update_test.go +++ b/integration/container/update_test.go @@ -8,7 +8,6 @@ import ( containertypes "github.com/docker/docker/api/types/container" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" "github.com/gotestyourself/gotestyourself/poll" @@ -61,5 +60,5 @@ func TestUpdateRestartWithAutoRemove(t *testing.T) { Name: "always", }, }) - testutil.ErrorContains(t, err, "Restart policy cannot be updated because AutoRemove is enabled for the container") + assert.Check(t, is.ErrorContains(err, "Restart policy cannot be updated because AutoRemove is enabled for the container")) } diff --git a/integration/image/remove_test.go b/integration/image/remove_test.go index 5ad09d51e0..172c27f54d 100644 --- a/integration/image/remove_test.go +++ b/integration/image/remove_test.go @@ -7,7 +7,6 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" ) @@ -56,5 +55,5 @@ func TestRemoveImageOrphaning(t *testing.T) { // check if the second image has been deleted _, _, err = client.ImageInspectWithRaw(ctx, commitResp2.ID) - testutil.ErrorContains(t, err, "No such image:") + assert.Check(t, is.ErrorContains(err, "No such image:")) } diff --git a/integration/image/tag_test.go b/integration/image/tag_test.go index e009114250..06431cd8a2 100644 --- a/integration/image/tag_test.go +++ b/integration/image/tag_test.go @@ -39,7 +39,7 @@ func TestTagInvalidReference(t *testing.T) { for _, repo := range invalidRepos { err := client.ImageTag(ctx, "busybox", repo) - testutil.ErrorContains(t, err, "not a valid repository/tag") + assert.Check(t, is.ErrorContains(err, "not a valid repository/tag")) } longTag := testutil.GenerateRandomAlphaOnlyString(121) @@ -48,24 +48,24 @@ func TestTagInvalidReference(t *testing.T) { for _, repotag := range invalidTags { err := client.ImageTag(ctx, "busybox", repotag) - testutil.ErrorContains(t, err, "not a valid repository/tag") + assert.Check(t, is.ErrorContains(err, "not a valid repository/tag")) } // test repository name begin with '-' err := client.ImageTag(ctx, "busybox:latest", "-busybox:test") - testutil.ErrorContains(t, err, "Error parsing reference") + assert.Check(t, is.ErrorContains(err, "Error parsing reference")) // test namespace name begin with '-' err = client.ImageTag(ctx, "busybox:latest", "-test/busybox:test") - testutil.ErrorContains(t, err, "Error parsing reference") + assert.Check(t, is.ErrorContains(err, "Error parsing reference")) // test index name begin with '-' err = client.ImageTag(ctx, "busybox:latest", "-index:5000/busybox:test") - testutil.ErrorContains(t, err, "Error parsing reference") + assert.Check(t, is.ErrorContains(err, "Error parsing reference")) // test setting tag fails err = client.ImageTag(ctx, "busybox:latest", "sha256:sometag") - testutil.ErrorContains(t, err, "refusing to create an ambiguous tag using digest algorithm as name") + assert.Check(t, is.ErrorContains(err, "refusing to create an ambiguous tag using digest algorithm as name")) } // ensure we allow the use of valid tags @@ -132,8 +132,9 @@ func TestTagMatchesDigest(t *testing.T) { digest := "busybox@sha256:abcdef76720241213f5303bda7704ec4c2ef75613173910a56fb1b6e20251507" // test setting tag fails err := client.ImageTag(ctx, "busybox:latest", digest) - testutil.ErrorContains(t, err, "refusing to create a tag with a digest reference") + assert.Check(t, is.ErrorContains(err, "refusing to create a tag with a digest reference")) + // check that no new image matches the digest _, _, err = client.ImageInspectWithRaw(ctx, digest) - testutil.ErrorContains(t, err, fmt.Sprintf("No such image: %s", digest)) + assert.Check(t, is.ErrorContains(err, fmt.Sprintf("No such image: %s", digest))) } diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index ea4dc7c7e9..96a02a6ec5 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -12,7 +12,6 @@ import ( swarmtypes "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/client" "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" @@ -148,17 +147,17 @@ func TestSecretsCreateAndDelete(t *testing.T) { }, Data: []byte("TESTINGDATA"), }) - testutil.ErrorContains(t, err, "already exists") + assert.Check(t, is.ErrorContains(err, "already exists")) // Ported from original TestSecretsDelete err = client.SecretRemove(ctx, secretID) assert.NilError(t, err) _, _, err = client.SecretInspectWithRaw(ctx, secretID) - testutil.ErrorContains(t, err, "No such secret") + assert.Check(t, is.ErrorContains(err, "No such secret")) err = client.SecretRemove(ctx, "non-existin") - testutil.ErrorContains(t, err, "No such secret: non-existin") + assert.Check(t, is.ErrorContains(err, "No such secret: non-existin")) // Ported from original TestSecretsCreteaWithLabels testName = "test_secret_with_labels" @@ -223,7 +222,7 @@ func TestSecretsUpdate(t *testing.T) { // this test will produce an error in func UpdateSecret insp.Spec.Data = []byte("TESTINGDATA2") err = client.SecretUpdate(ctx, secretID, insp.Version, insp.Spec) - testutil.ErrorContains(t, err, "only updates to Labels are allowed") + assert.Check(t, is.ErrorContains(err, "only updates to Labels are allowed")) } func TestTemplatedSecret(t *testing.T) { diff --git a/integration/volume/volume_test.go b/integration/volume/volume_test.go index d7014ec3ac..4acc6e8b1a 100644 --- a/integration/volume/volume_test.go +++ b/integration/volume/volume_test.go @@ -12,7 +12,6 @@ import ( volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/integration/internal/container" "github.com/docker/docker/internal/test/request" - "github.com/docker/docker/internal/testutil" "github.com/google/go-cmp/cmp/cmpopts" "github.com/gotestyourself/gotestyourself/assert" is "github.com/gotestyourself/gotestyourself/assert/cmp" @@ -63,7 +62,7 @@ func TestVolumesRemove(t *testing.T) { vname := c.Mounts[0].Name err = client.VolumeRemove(ctx, vname, false) - testutil.ErrorContains(t, err, "volume is in use") + assert.Check(t, is.ErrorContains(err, "volume is in use")) err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{ Force: true, diff --git a/internal/testutil/helpers.go b/internal/testutil/helpers.go index 89cb552fea..38cd1693f5 100644 --- a/internal/testutil/helpers.go +++ b/internal/testutil/helpers.go @@ -2,24 +2,8 @@ package testutil // import "github.com/docker/docker/internal/testutil" import ( "io" - - "github.com/gotestyourself/gotestyourself/assert" ) -type helperT interface { - Helper() -} - -// ErrorContains checks that the error is not nil, and contains the expected -// substring. -// 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. var DevZero io.Reader = devZero{}