diff --git a/command/bundlefile/bundlefile_test.go b/command/bundlefile/bundlefile_test.go index c343410df3..bd059c4dca 100644 --- a/command/bundlefile/bundlefile_test.go +++ b/command/bundlefile/bundlefile_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestLoadFileV01Success(t *testing.T) { @@ -25,9 +25,9 @@ func TestLoadFileV01Success(t *testing.T) { }`) bundle, err := LoadFile(reader) - assert.NilError(t, err) - assert.Equal(t, bundle.Version, "0.1") - assert.Equal(t, len(bundle.Services), 2) + assert.NoError(t, err) + assert.Equal(t, "0.1", bundle.Version) + assert.Len(t, bundle.Services, 2) } func TestLoadFileSyntaxError(t *testing.T) { @@ -37,7 +37,7 @@ func TestLoadFileSyntaxError(t *testing.T) { }`) _, err := LoadFile(reader) - assert.Error(t, err, "syntax error at byte 37: invalid character 'u'") + assert.EqualError(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value") } func TestLoadFileTypeError(t *testing.T) { @@ -52,7 +52,7 @@ func TestLoadFileTypeError(t *testing.T) { }`) _, err := LoadFile(reader) - assert.Error(t, err, "Unexpected type at byte 94. Expected []string but received string") + assert.EqualError(t, err, "Unexpected type at byte 94. Expected []string but received string.") } func TestPrint(t *testing.T) { @@ -66,7 +66,7 @@ func TestPrint(t *testing.T) { }, }, } - assert.NilError(t, Print(&buffer, bundle)) + assert.NoError(t, Print(&buffer, bundle)) output := buffer.String() assert.Contains(t, output, "\"Image\": \"image\"") assert.Contains(t, output, diff --git a/command/container/opts_test.go b/command/container/opts_test.go index 575b214edc..2d0049768a 100644 --- a/command/container/opts_test.go +++ b/command/container/opts_test.go @@ -13,11 +13,12 @@ import ( "github.com/docker/docker/api/types/container" networktypes "github.com/docker/docker/api/types/network" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/runconfig" "github.com/docker/go-connections/nat" "github.com/pkg/errors" "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" ) func TestValidateAttach(t *testing.T) { @@ -243,23 +244,23 @@ func TestParseWithMacAddress(t *testing.T) { func TestParseWithMemory(t *testing.T) { invalidMemory := "--memory=invalid" _, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"}) - assert.Error(t, err, invalidMemory) + testutil.ErrorContains(t, err, invalidMemory) _, hostconfig := mustParse(t, "--memory=1G") - assert.Equal(t, hostconfig.Memory, int64(1073741824)) + assert.Equal(t, int64(1073741824), hostconfig.Memory) } func TestParseWithMemorySwap(t *testing.T) { invalidMemory := "--memory-swap=invalid" _, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"}) - assert.Error(t, err, invalidMemory) + testutil.ErrorContains(t, err, invalidMemory) _, hostconfig := mustParse(t, "--memory-swap=1G") - assert.Equal(t, hostconfig.MemorySwap, int64(1073741824)) + assert.Equal(t, int64(1073741824), hostconfig.MemorySwap) _, hostconfig = mustParse(t, "--memory-swap=-1") - assert.Equal(t, hostconfig.MemorySwap, int64(-1)) + assert.Equal(t, int64(-1), hostconfig.MemorySwap) } func TestParseHostname(t *testing.T) { diff --git a/command/container/ps_test.go b/command/container/ps_test.go index 62b0545274..47665b0e2c 100644 --- a/command/container/ps_test.go +++ b/command/container/ps_test.go @@ -4,13 +4,13 @@ import ( "testing" "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestBuildContainerListOptions(t *testing.T) { filters := opts.NewFilterOpt() - assert.NilError(t, filters.Set("foo=bar")) - assert.NilError(t, filters.Set("baz=foo")) + assert.NoError(t, filters.Set("foo=bar")) + assert.NoError(t, filters.Set("baz=foo")) contexts := []struct { psOpts *psOptions @@ -101,12 +101,12 @@ func TestBuildContainerListOptions(t *testing.T) { for _, c := range contexts { options, err := buildContainerListOptions(c.psOpts) - assert.NilError(t, err) + assert.NoError(t, err) assert.Equal(t, c.expectedAll, options.All) assert.Equal(t, c.expectedSize, options.Size) assert.Equal(t, c.expectedLimit, options.Limit) - assert.Equal(t, options.Filters.Len(), len(c.expectedFilters)) + assert.Equal(t, len(c.expectedFilters), options.Filters.Len()) for k, v := range c.expectedFilters { f := options.Filters diff --git a/command/formatter/container_test.go b/command/formatter/container_test.go index a5615d1768..8d23cc781c 100644 --- a/command/formatter/container_test.go +++ b/command/formatter/container_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestContainerPsContext(t *testing.T) { @@ -245,9 +245,9 @@ conta "ubuntu" 24 hours ago//.FOOBAR_BAR testcase.context.Output = out err := ContainerWrite(testcase.context, containers) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -334,7 +334,7 @@ func TestContainerContextWriteJSON(t *testing.T) { if err := json.Unmarshal([]byte(line), &m); err != nil { t.Fatal(err) } - assert.DeepEqual(t, m, expectedJSONs[i]) + assert.Equal(t, expectedJSONs[i], m) } } @@ -354,7 +354,7 @@ func TestContainerContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, containers[i].ID) + assert.Equal(t, containers[i].ID, s) } } diff --git a/command/formatter/diff_test.go b/command/formatter/diff_test.go index 52080354f5..1aa7b53056 100644 --- a/command/formatter/diff_test.go +++ b/command/formatter/diff_test.go @@ -6,7 +6,7 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestDiffContextFormatWrite(t *testing.T) { @@ -51,9 +51,9 @@ D: /usr/app/old_app.js testcase.context.Output = out err := DiffWrite(testcase.context, diffs) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } diff --git a/command/formatter/disk_usage_test.go b/command/formatter/disk_usage_test.go index 7093cfe85a..302eb2c8f7 100644 --- a/command/formatter/disk_usage_test.go +++ b/command/formatter/disk_usage_test.go @@ -4,7 +4,7 @@ import ( "bytes" "testing" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestDiskUsageContextFormatWrite(t *testing.T) { @@ -117,9 +117,9 @@ reclaimable: 0B out := bytes.NewBufferString("") testcase.context.Output = out if err := testcase.context.Write(); err != nil { - assert.Equal(t, err.Error(), testcase.expected) + assert.Equal(t, testcase.expected, err.Error()) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } diff --git a/command/formatter/image_test.go b/command/formatter/image_test.go index e7c15dbf5a..b3c4cc8094 100644 --- a/command/formatter/image_test.go +++ b/command/formatter/image_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestImageContext(t *testing.T) { @@ -265,9 +265,9 @@ image_id: imageID3 testcase.context.Output = out err := ImageWrite(testcase.context, images) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -320,7 +320,7 @@ func TestImageContextWriteWithNoImage(t *testing.T) { for _, context := range contexts { ImageWrite(context.context, images) - assert.Equal(t, out.String(), context.expected) + assert.Equal(t, context.expected, out.String()) // Clean buffer out.Reset() } diff --git a/command/formatter/network_test.go b/command/formatter/network_test.go index 24bf46d256..b8cab078e7 100644 --- a/command/formatter/network_test.go +++ b/command/formatter/network_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestNetworkContext(t *testing.T) { @@ -160,9 +160,9 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC testcase.context.Output = out err := NetworkWrite(testcase.context, networks) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -188,7 +188,7 @@ func TestNetworkContextWriteJSON(t *testing.T) { if err := json.Unmarshal([]byte(line), &m); err != nil { t.Fatal(err) } - assert.DeepEqual(t, m, expectedJSONs[i]) + assert.Equal(t, expectedJSONs[i], m) } } @@ -208,6 +208,6 @@ func TestNetworkContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, networks[i].ID) + assert.Equal(t, networks[i].ID, s) } } diff --git a/command/formatter/node_test.go b/command/formatter/node_test.go index 86f4979d3f..ea2f4ce4d5 100644 --- a/command/formatter/node_test.go +++ b/command/formatter/node_test.go @@ -9,7 +9,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestNodeContext(t *testing.T) { @@ -135,9 +135,9 @@ foobar_bar testcase.context.Output = out err := NodeWrite(testcase.context, nodes, types.Info{}) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -163,7 +163,7 @@ func TestNodeContextWriteJSON(t *testing.T) { if err := json.Unmarshal([]byte(line), &m); err != nil { t.Fatal(err) } - assert.DeepEqual(t, m, expectedJSONs[i]) + assert.Equal(t, expectedJSONs[i], m) } } @@ -183,6 +183,6 @@ func TestNodeContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, nodes[i].ID) + assert.Equal(t, nodes[i].ID, s) } } diff --git a/command/formatter/plugin_test.go b/command/formatter/plugin_test.go index 3cc0af8a3e..607262dcc9 100644 --- a/command/formatter/plugin_test.go +++ b/command/formatter/plugin_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestPluginContext(t *testing.T) { @@ -131,9 +131,9 @@ foobar_bar testcase.context.Output = out err := PluginWrite(testcase.context, plugins) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -158,7 +158,7 @@ func TestPluginContextWriteJSON(t *testing.T) { if err := json.Unmarshal([]byte(line), &m); err != nil { t.Fatal(err) } - assert.DeepEqual(t, m, expectedJSONs[i]) + assert.Equal(t, expectedJSONs[i], m) } } @@ -177,6 +177,6 @@ func TestPluginContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, plugins[i].ID) + assert.Equal(t, plugins[i].ID, s) } } diff --git a/command/formatter/secret_test.go b/command/formatter/secret_test.go index 722b650565..98fe61315f 100644 --- a/command/formatter/secret_test.go +++ b/command/formatter/secret_test.go @@ -6,7 +6,7 @@ import ( "time" "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestSecretContextFormatWrite(t *testing.T) { @@ -55,9 +55,9 @@ id_rsa out := bytes.NewBufferString("") testcase.context.Output = out if err := SecretWrite(testcase.context, secrets); err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } diff --git a/command/formatter/service_test.go b/command/formatter/service_test.go index 93ffc92a3b..629f853930 100644 --- a/command/formatter/service_test.go +++ b/command/formatter/service_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestServiceContextWrite(t *testing.T) { @@ -137,9 +137,9 @@ bar testcase.context.Output = out err := ServiceListWrite(testcase.context, services, info) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -205,7 +205,7 @@ func TestServiceContextWriteJSON(t *testing.T) { if err := json.Unmarshal([]byte(line), &m); err != nil { t.Fatal(err) } - assert.DeepEqual(t, m, expectedJSONs[i]) + assert.Equal(t, expectedJSONs[i], m) } } func TestServiceContextWriteJSONField(t *testing.T) { @@ -234,6 +234,6 @@ func TestServiceContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, services[i].Spec.Name) + assert.Equal(t, services[i].Spec.Name, s) } } diff --git a/command/formatter/stats_test.go b/command/formatter/stats_test.go index 5d6a91e7c9..078e8db32a 100644 --- a/command/formatter/stats_test.go +++ b/command/formatter/stats_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestContainerStatsContext(t *testing.T) { @@ -116,9 +116,9 @@ container2 -- te.context.Output = &out err := ContainerStatsWrite(te.context, stats, "linux") if err != nil { - assert.Error(t, err, te.expected) + assert.EqualError(t, err, te.expected) } else { - assert.Equal(t, out.String(), te.expected) + assert.Equal(t, te.expected, out.String()) } } } @@ -182,9 +182,9 @@ container2 -- -- te.context.Output = &out err := ContainerStatsWrite(te.context, stats, "windows") if err != nil { - assert.Error(t, err, te.expected) + assert.EqualError(t, err, te.expected) } else { - assert.Equal(t, out.String(), te.expected) + assert.Equal(t, te.expected, out.String()) } } } @@ -259,7 +259,7 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) { for _, context := range contexts { ContainerStatsWrite(context.context, []StatsEntry{}, "windows") - assert.Equal(t, out.String(), context.expected) + assert.Equal(t, context.expected, out.String()) // Clean buffer out.Reset() } diff --git a/command/formatter/task_test.go b/command/formatter/task_test.go index 8de9d66f57..d2843c70d4 100644 --- a/command/formatter/task_test.go +++ b/command/formatter/task_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestTaskContextWrite(t *testing.T) { @@ -76,9 +76,9 @@ foobar_bar foo2 testcase.context.Output = out err := TaskWrite(testcase.context, tasks, names, nodes) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -102,6 +102,6 @@ func TestTaskContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, tasks[i].ID) + assert.Equal(t, tasks[i].ID, s) } } diff --git a/command/formatter/volume_test.go b/command/formatter/volume_test.go index 9c23ae447d..bf1100893f 100644 --- a/command/formatter/volume_test.go +++ b/command/formatter/volume_test.go @@ -8,7 +8,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/pkg/stringid" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestVolumeContext(t *testing.T) { @@ -131,9 +131,9 @@ foobar_bar testcase.context.Output = out err := VolumeWrite(testcase.context, volumes) if err != nil { - assert.Error(t, err, testcase.expected) + assert.EqualError(t, err, testcase.expected) } else { - assert.Equal(t, out.String(), testcase.expected) + assert.Equal(t, testcase.expected, out.String()) } } } @@ -158,7 +158,7 @@ func TestVolumeContextWriteJSON(t *testing.T) { if err := json.Unmarshal([]byte(line), &m); err != nil { t.Fatal(err) } - assert.DeepEqual(t, m, expectedJSONs[i]) + assert.Equal(t, expectedJSONs[i], m) } } @@ -178,6 +178,6 @@ func TestVolumeContextWriteJSONField(t *testing.T) { if err := json.Unmarshal([]byte(line), &s); err != nil { t.Fatal(err) } - assert.Equal(t, s, volumes[i].Name) + assert.Equal(t, volumes[i].Name, s) } } diff --git a/command/idresolver/idresolver_test.go b/command/idresolver/idresolver_test.go index 720667daa1..1aca09ce96 100644 --- a/command/idresolver/idresolver_test.go +++ b/command/idresolver/idresolver_test.go @@ -6,8 +6,8 @@ import ( "github.com/docker/docker/api/types/swarm" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -21,7 +21,7 @@ func TestResolveError(t *testing.T) { idResolver := New(cli, false) _, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID") - assert.Error(t, err, "unsupported type") + assert.EqualError(t, err, "unsupported type") } func TestResolveWithNoResolveOption(t *testing.T) { @@ -40,9 +40,9 @@ func TestResolveWithNoResolveOption(t *testing.T) { idResolver := New(cli, true) id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID") - assert.NilError(t, err) - assert.Equal(t, id, "nodeID") - assert.Equal(t, resolved, false) + assert.NoError(t, err) + assert.Equal(t, "nodeID", id) + assert.False(t, resolved) } func TestResolveWithCache(t *testing.T) { @@ -59,11 +59,11 @@ func TestResolveWithCache(t *testing.T) { ctx := context.Background() for i := 0; i < 2; i++ { id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID") - assert.NilError(t, err) - assert.Equal(t, id, "node-foo") + assert.NoError(t, err) + assert.Equal(t, "node-foo", id) } - assert.Equal(t, inspectCounter, 1) + assert.Equal(t, 1, inspectCounter) } func TestResolveNode(t *testing.T) { @@ -103,8 +103,8 @@ func TestResolveNode(t *testing.T) { idResolver := New(cli, false) id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID) - assert.NilError(t, err) - assert.Equal(t, id, tc.expectedID) + assert.NoError(t, err) + assert.Equal(t, tc.expectedID, id) } } @@ -138,7 +138,7 @@ func TestResolveService(t *testing.T) { idResolver := New(cli, false) id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID) - assert.NilError(t, err) - assert.Equal(t, id, tc.expectedID) + assert.NoError(t, err) + assert.Equal(t, tc.expectedID, id) } } diff --git a/command/node/demote_test.go b/command/node/demote_test.go index 710455ff56..803b9c229b 100644 --- a/command/node/demote_test.go +++ b/command/node/demote_test.go @@ -10,7 +10,8 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestNodeDemoteErrors(t *testing.T) { @@ -47,7 +48,7 @@ func TestNodeDemoteErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -66,7 +67,7 @@ func TestNodeDemoteNoChange(t *testing.T) { }, }, buf)) cmd.SetArgs([]string{"nodeID"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } func TestNodeDemoteMultipleNode(t *testing.T) { @@ -84,5 +85,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) { }, }, buf)) cmd.SetArgs([]string{"nodeID1", "nodeID2"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } diff --git a/command/node/inspect_test.go b/command/node/inspect_test.go index 9b6a04f11a..95b45d51e9 100644 --- a/command/node/inspect_test.go +++ b/command/node/inspect_test.go @@ -12,8 +12,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestNodeInspectErrors(t *testing.T) { @@ -77,7 +78,7 @@ func TestNodeInspectErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -115,9 +116,9 @@ func TestNodeInspectPretty(t *testing.T) { }, buf)) cmd.SetArgs([]string{"nodeID"}) cmd.Flags().Set("pretty", "true") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/node/list_test.go b/command/node/list_test.go index 4b8d906c3a..af2d6be156 100644 --- a/command/node/list_test.go +++ b/command/node/list_test.go @@ -12,7 +12,7 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestNodeListErrorOnAPIFailure(t *testing.T) { @@ -50,7 +50,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) { cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newListCommand(cli) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + assert.EqualError(t, cmd.Execute(), tc.expectedError) } } @@ -74,7 +74,7 @@ func TestNodeList(t *testing.T) { }, buf) cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Contains(t, buf.String(), `nodeID1 * nodeHostname1 Ready Active Leader`) assert.Contains(t, buf.String(), `nodeID2 nodeHostname2 Ready Active Reachable`) assert.Contains(t, buf.String(), `nodeID3 nodeHostname3 Ready Active`) @@ -92,7 +92,7 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) { cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newListCommand(cli) cmd.Flags().Set("quiet", "true") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Contains(t, buf.String(), "nodeID") } @@ -102,7 +102,7 @@ func TestNodeListContainsHostname(t *testing.T) { cli := test.NewFakeCli(&fakeClient{}, buf) cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Contains(t, buf.String(), "HOSTNAME") } @@ -128,7 +128,7 @@ func TestNodeListDefaultFormat(t *testing.T) { NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}", }) cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Contains(t, buf.String(), `nodeID1: nodeHostname1 Ready/Leader`) assert.Contains(t, buf.String(), `nodeID2: nodeHostname2 Ready/Reachable`) assert.Contains(t, buf.String(), `nodeID3: nodeHostname3 Ready`) @@ -156,7 +156,7 @@ func TestNodeListFormat(t *testing.T) { }) cmd := newListCommand(cli) cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Contains(t, buf.String(), `nodeHostname1: Leader`) assert.Contains(t, buf.String(), `nodeHostname2: Reachable`) } diff --git a/command/node/promote_test.go b/command/node/promote_test.go index 9b646724d1..ce2fb13dca 100644 --- a/command/node/promote_test.go +++ b/command/node/promote_test.go @@ -10,7 +10,8 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestNodePromoteErrors(t *testing.T) { @@ -47,7 +48,7 @@ func TestNodePromoteErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -66,7 +67,7 @@ func TestNodePromoteNoChange(t *testing.T) { }, }, buf)) cmd.SetArgs([]string{"nodeID"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } func TestNodePromoteMultipleNode(t *testing.T) { @@ -84,5 +85,5 @@ func TestNodePromoteMultipleNode(t *testing.T) { }, }, buf)) cmd.SetArgs([]string{"nodeID1", "nodeID2"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } diff --git a/command/node/ps_test.go b/command/node/ps_test.go index de6ff7d578..f604628991 100644 --- a/command/node/ps_test.go +++ b/command/node/ps_test.go @@ -13,8 +13,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestNodePsErrors(t *testing.T) { @@ -62,7 +63,7 @@ func TestNodePsErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + assert.EqualError(t, cmd.Execute(), tc.expectedError) } } @@ -125,9 +126,9 @@ func TestNodePs(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-ps.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/node/remove_test.go b/command/node/remove_test.go index d7e742aa4c..b53431dfa7 100644 --- a/command/node/remove_test.go +++ b/command/node/remove_test.go @@ -6,8 +6,9 @@ import ( "testing" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestNodeRemoveErrors(t *testing.T) { @@ -35,7 +36,7 @@ func TestNodeRemoveErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -43,5 +44,5 @@ func TestNodeRemoveMultiple(t *testing.T) { buf := new(bytes.Buffer) cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf)) cmd.SetArgs([]string{"nodeID1", "nodeID2"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } diff --git a/command/node/update_test.go b/command/node/update_test.go index 493a386270..a5e2d20e9a 100644 --- a/command/node/update_test.go +++ b/command/node/update_test.go @@ -10,7 +10,8 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestNodeUpdateErrors(t *testing.T) { @@ -67,7 +68,7 @@ func TestNodeUpdateErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -167,6 +168,6 @@ func TestNodeUpdate(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } } diff --git a/command/secret/create_test.go b/command/secret/create_test.go index cbdfd63338..0e9c1cd4af 100644 --- a/command/secret/create_test.go +++ b/command/secret/create_test.go @@ -10,9 +10,10 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) const secretDataFile = "secret-create-with-name.golden" @@ -47,7 +48,7 @@ func TestSecretCreateErrors(t *testing.T) { ) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -71,10 +72,10 @@ func TestSecretCreateWithName(t *testing.T) { cmd := newSecretCreateCommand(cli) cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) expected := golden.Get(t, actual, secretDataFile) - assert.Equal(t, string(actual), string(expected)) - assert.Equal(t, strings.TrimSpace(buf.String()), "ID-"+name) + assert.Equal(t, expected, actual) + assert.Equal(t, "ID-"+name, strings.TrimSpace(buf.String())) } func TestSecretCreateWithLabels(t *testing.T) { @@ -105,8 +106,8 @@ func TestSecretCreateWithLabels(t *testing.T) { cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)}) cmd.Flags().Set("label", "lbl1=Label-foo") cmd.Flags().Set("label", "lbl2=Label-bar") - assert.NilError(t, cmd.Execute()) - assert.Equal(t, strings.TrimSpace(buf.String()), "ID-"+name) + assert.NoError(t, cmd.Execute()) + assert.Equal(t, "ID-"+name, strings.TrimSpace(buf.String())) } func compareMap(actual map[string]string, expected map[string]string) bool { diff --git a/command/secret/inspect_test.go b/command/secret/inspect_test.go index 558e23d7c7..52b9a1cef0 100644 --- a/command/secret/inspect_test.go +++ b/command/secret/inspect_test.go @@ -11,8 +11,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestSecretInspectErrors(t *testing.T) { @@ -62,7 +63,7 @@ func TestSecretInspectErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -100,10 +101,10 @@ func TestSecretInspectWithoutFormat(t *testing.T) { }, buf), ) cmd.SetArgs(tc.args) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } @@ -141,9 +142,9 @@ func TestSecretInspectWithFormat(t *testing.T) { ) cmd.SetArgs(tc.args) cmd.Flags().Set("format", tc.format) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/secret/ls_test.go b/command/secret/ls_test.go index d9a4324b75..cb0510adff 100644 --- a/command/secret/ls_test.go +++ b/command/secret/ls_test.go @@ -13,8 +13,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestSecretListErrors(t *testing.T) { @@ -43,7 +44,7 @@ func TestSecretListErrors(t *testing.T) { ) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -70,10 +71,10 @@ func TestSecretList(t *testing.T) { cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newSecretListCommand(cli) cmd.SetOutput(buf) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "secret-list.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } func TestSecretListWithQuietOption(t *testing.T) { @@ -91,10 +92,10 @@ func TestSecretListWithQuietOption(t *testing.T) { cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newSecretListCommand(cli) cmd.Flags().Set("quiet", "true") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "secret-list-with-quiet-option.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } func TestSecretListWithConfigFormat(t *testing.T) { @@ -113,10 +114,10 @@ func TestSecretListWithConfigFormat(t *testing.T) { SecretFormat: "{{ .Name }} {{ .Labels }}", }) cmd := newSecretListCommand(cli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "secret-list-with-config-format.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } func TestSecretListWithFormat(t *testing.T) { @@ -133,18 +134,18 @@ func TestSecretListWithFormat(t *testing.T) { }, buf) cmd := newSecretListCommand(cli) cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "secret-list-with-format.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } func TestSecretListWithFilter(t *testing.T) { buf := new(bytes.Buffer) cli := test.NewFakeCli(&fakeClient{ secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) { - assert.Equal(t, options.Filters.Get("name")[0], "foo") - assert.Equal(t, options.Filters.Get("label")[0], "lbl1=Label-bar") + assert.Equal(t, "foo", options.Filters.Get("name")[0], "foo") + assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0]) return []swarm.Secret{ *Secret(SecretID("ID-foo"), SecretName("foo"), @@ -165,8 +166,8 @@ func TestSecretListWithFilter(t *testing.T) { cmd := newSecretListCommand(cli) cmd.Flags().Set("filter", "name=foo") cmd.Flags().Set("filter", "label=lbl1=Label-bar") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "secret-list-with-filter.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } diff --git a/command/secret/remove_test.go b/command/secret/remove_test.go index 92ca9b9b9d..b8bbb5e6f5 100644 --- a/command/secret/remove_test.go +++ b/command/secret/remove_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestSecretRemoveErrors(t *testing.T) { @@ -38,7 +39,7 @@ func TestSecretRemoveErrors(t *testing.T) { ) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -54,9 +55,9 @@ func TestSecretRemoveWithName(t *testing.T) { }, buf) cmd := newSecretRemoveCommand(cli) cmd.SetArgs(names) - assert.NilError(t, cmd.Execute()) - assert.EqualStringSlice(t, strings.Split(strings.TrimSpace(buf.String()), "\n"), names) - assert.EqualStringSlice(t, removedSecrets, names) + assert.NoError(t, cmd.Execute()) + assert.Equal(t, names, strings.Split(strings.TrimSpace(buf.String()), "\n")) + assert.Equal(t, names, removedSecrets) } func TestSecretRemoveContinueAfterError(t *testing.T) { @@ -76,6 +77,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) { cmd := newSecretRemoveCommand(cli) cmd.SetArgs(names) - assert.Error(t, cmd.Execute(), "error removing secret: foo") - assert.EqualStringSlice(t, removedSecrets, names) + assert.EqualError(t, cmd.Execute(), "error removing secret: foo") + assert.Equal(t, names, removedSecrets) } diff --git a/command/service/inspect_test.go b/command/service/inspect_test.go index 44d9df9176..c5bda7dcd9 100644 --- a/command/service/inspect_test.go +++ b/command/service/inspect_test.go @@ -10,7 +10,7 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli/command/formatter" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) string { @@ -136,5 +136,5 @@ func TestJSONFormatWithNoUpdateConfig(t *testing.T) { t.Fatal(err) } t.Logf("m2=%+v", m2) - assert.DeepEqual(t, m2, m1) + assert.Equal(t, m1, m2) } diff --git a/command/service/opts_test.go b/command/service/opts_test.go index 46db5fc838..675fbe4b99 100644 --- a/command/service/opts_test.go +++ b/command/service/opts_test.go @@ -1,71 +1,70 @@ package service import ( - "reflect" "testing" "time" "github.com/docker/docker/api/types/container" "github.com/docker/docker/opts" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestMemBytesString(t *testing.T) { var mem opts.MemBytes = 1048576 - assert.Equal(t, mem.String(), "1MiB") + assert.Equal(t, "1MiB", mem.String()) } func TestMemBytesSetAndValue(t *testing.T) { var mem opts.MemBytes - assert.NilError(t, mem.Set("5kb")) - assert.Equal(t, mem.Value(), int64(5120)) + assert.NoError(t, mem.Set("5kb")) + assert.Equal(t, int64(5120), mem.Value()) } func TestNanoCPUsString(t *testing.T) { var cpus opts.NanoCPUs = 6100000000 - assert.Equal(t, cpus.String(), "6.100") + assert.Equal(t, "6.100", cpus.String()) } func TestNanoCPUsSetAndValue(t *testing.T) { var cpus opts.NanoCPUs - assert.NilError(t, cpus.Set("0.35")) - assert.Equal(t, cpus.Value(), int64(350000000)) + assert.NoError(t, cpus.Set("0.35")) + assert.Equal(t, int64(350000000), cpus.Value()) } func TestDurationOptString(t *testing.T) { dur := time.Duration(300 * 10e8) duration := DurationOpt{value: &dur} - assert.Equal(t, duration.String(), "5m0s") + assert.Equal(t, "5m0s", duration.String()) } func TestDurationOptSetAndValue(t *testing.T) { var duration DurationOpt - assert.NilError(t, duration.Set("300s")) - assert.Equal(t, *duration.Value(), time.Duration(300*10e8)) - assert.NilError(t, duration.Set("-300s")) - assert.Equal(t, *duration.Value(), time.Duration(-300*10e8)) + assert.NoError(t, duration.Set("300s")) + assert.Equal(t, time.Duration(300*10e8), *duration.Value()) + assert.NoError(t, duration.Set("-300s")) + assert.Equal(t, time.Duration(-300*10e8), *duration.Value()) } func TestPositiveDurationOptSetAndValue(t *testing.T) { var duration PositiveDurationOpt - assert.NilError(t, duration.Set("300s")) - assert.Equal(t, *duration.Value(), time.Duration(300*10e8)) - assert.Error(t, duration.Set("-300s"), "cannot be negative") + assert.NoError(t, duration.Set("300s")) + assert.Equal(t, time.Duration(300*10e8), *duration.Value()) + assert.EqualError(t, duration.Set("-300s"), "duration cannot be negative") } func TestUint64OptString(t *testing.T) { value := uint64(2345678) opt := Uint64Opt{value: &value} - assert.Equal(t, opt.String(), "2345678") + assert.Equal(t, "2345678", opt.String()) opt = Uint64Opt{} - assert.Equal(t, opt.String(), "") + assert.Equal(t, "", opt.String()) } func TestUint64OptSetAndValue(t *testing.T) { var opt Uint64Opt - assert.NilError(t, opt.Set("14445")) - assert.Equal(t, *opt.Value(), uint64(14445)) + assert.NoError(t, opt.Set("14445")) + assert.Equal(t, uint64(14445), *opt.Value()) } func TestHealthCheckOptionsToHealthConfig(t *testing.T) { @@ -78,14 +77,14 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) { retries: 10, } config, err := opt.toHealthConfig() - assert.NilError(t, err) - assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{ + assert.NoError(t, err) + assert.Equal(t, &container.HealthConfig{ Test: []string{"CMD-SHELL", "curl"}, Interval: time.Second, Timeout: time.Second, StartPeriod: time.Second, Retries: 10, - }), true) + }, config) } func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) { @@ -93,10 +92,10 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) { noHealthcheck: true, } config, err := opt.toHealthConfig() - assert.NilError(t, err) - assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{ + assert.NoError(t, err) + assert.Equal(t, &container.HealthConfig{ Test: []string{"NONE"}, - }), true) + }, config) } func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) { @@ -105,5 +104,5 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) { noHealthcheck: true, } _, err := opt.toHealthConfig() - assert.Error(t, err, "--no-healthcheck conflicts with --health-* options") + assert.EqualError(t, err, "--no-healthcheck conflicts with --health-* options") } diff --git a/command/service/update_test.go b/command/service/update_test.go index 090372fb78..8f49d52ab8 100644 --- a/command/service/update_test.go +++ b/command/service/update_test.go @@ -10,7 +10,8 @@ import ( "github.com/docker/docker/api/types/container" mounttypes "github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/swarm" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "golang.org/x/net/context" ) @@ -23,7 +24,7 @@ func TestUpdateServiceArgs(t *testing.T) { cspec.Args = []string{"old", "args"} updateService(nil, nil, flags, spec) - assert.EqualStringSlice(t, cspec.Args, []string{"the", "new args"}) + assert.Equal(t, []string{"the", "new args"}, cspec.Args) } func TestUpdateLabels(t *testing.T) { @@ -37,9 +38,9 @@ func TestUpdateLabels(t *testing.T) { } updateLabels(flags, &labels) - assert.Equal(t, len(labels), 2) - assert.Equal(t, labels["tokeep"], "value") - assert.Equal(t, labels["toadd"], "newlabel") + assert.Len(t, labels, 2) + assert.Equal(t, "value", labels["tokeep"]) + assert.Equal(t, "newlabel", labels["toadd"]) } func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) { @@ -48,7 +49,7 @@ func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) { labels := map[string]string{"foo": "theoldlabel"} updateLabels(flags, &labels) - assert.Equal(t, len(labels), 1) + assert.Len(t, labels, 1) } func TestUpdatePlacementConstraints(t *testing.T) { @@ -61,9 +62,9 @@ func TestUpdatePlacementConstraints(t *testing.T) { } updatePlacementConstraints(flags, placement) - assert.Equal(t, len(placement.Constraints), 2) - assert.Equal(t, placement.Constraints[0], "container=tokeep") - assert.Equal(t, placement.Constraints[1], "node=toadd") + require.Len(t, placement.Constraints, 2) + assert.Equal(t, "container=tokeep", placement.Constraints[0]) + assert.Equal(t, "node=toadd", placement.Constraints[1]) } func TestUpdatePlacementPrefs(t *testing.T) { @@ -87,9 +88,9 @@ func TestUpdatePlacementPrefs(t *testing.T) { } updatePlacementPreferences(flags, placement) - assert.Equal(t, len(placement.Preferences), 2) - assert.Equal(t, placement.Preferences[0].Spread.SpreadDescriptor, "node.labels.row") - assert.Equal(t, placement.Preferences[1].Spread.SpreadDescriptor, "node.labels.dc") + require.Len(t, placement.Preferences, 2) + assert.Equal(t, "node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor) + assert.Equal(t, "node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor) } func TestUpdateEnvironment(t *testing.T) { @@ -100,11 +101,11 @@ func TestUpdateEnvironment(t *testing.T) { envs := []string{"toremove=theenvtoremove", "tokeep=value"} updateEnvironment(flags, &envs) - assert.Equal(t, len(envs), 2) + require.Len(t, envs, 2) // Order has been removed in updateEnvironment (map) sort.Strings(envs) - assert.Equal(t, envs[0], "toadd=newenv") - assert.Equal(t, envs[1], "tokeep=value") + assert.Equal(t, "toadd=newenv", envs[0]) + assert.Equal(t, "tokeep=value", envs[1]) } func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) { @@ -116,7 +117,7 @@ func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) { envs := []string{"foo=value"} updateEnvironment(flags, &envs) - assert.Equal(t, len(envs), 0) + assert.Len(t, envs, 0) } func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) { @@ -127,8 +128,8 @@ func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) { envs := []string{"A=c"} updateEnvironment(flags, &envs) - assert.Equal(t, len(envs), 1) - assert.Equal(t, envs[0], "A=b") + require.Len(t, envs, 1) + assert.Equal(t, "A=b", envs[0]) } func TestUpdateGroups(t *testing.T) { @@ -142,10 +143,10 @@ func TestUpdateGroups(t *testing.T) { groups := []string{"bar", "root"} updateGroups(flags, &groups) - assert.Equal(t, len(groups), 3) - assert.Equal(t, groups[0], "bar") - assert.Equal(t, groups[1], "foo") - assert.Equal(t, groups[2], "wheel") + require.Len(t, groups, 3) + assert.Equal(t, "bar", groups[0]) + assert.Equal(t, "foo", groups[1]) + assert.Equal(t, "wheel", groups[2]) } func TestUpdateDNSConfig(t *testing.T) { @@ -160,7 +161,7 @@ func TestUpdateDNSConfig(t *testing.T) { // IPv6 flags.Set("dns-add", "2001:db8:abc8::1") // Invalid dns record - assert.Error(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address") + assert.EqualError(t, flags.Set("dns-add", "x.y.z.w"), "x.y.z.w is not an ip address") // domains with duplicates flags.Set("dns-search-add", "example.com") @@ -168,7 +169,7 @@ func TestUpdateDNSConfig(t *testing.T) { flags.Set("dns-search-add", "example.org") flags.Set("dns-search-rm", "example.org") // Invalid dns search domain - assert.Error(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain") + assert.EqualError(t, flags.Set("dns-search-add", "example$com"), "example$com is not a valid domain") flags.Set("dns-option-add", "ndots:9") flags.Set("dns-option-rm", "timeout:3") @@ -181,16 +182,16 @@ func TestUpdateDNSConfig(t *testing.T) { updateDNSConfig(flags, &config) - assert.Equal(t, len(config.Nameservers), 3) - assert.Equal(t, config.Nameservers[0], "1.1.1.1") - assert.Equal(t, config.Nameservers[1], "2001:db8:abc8::1") - assert.Equal(t, config.Nameservers[2], "5.5.5.5") + require.Len(t, config.Nameservers, 3) + assert.Equal(t, "1.1.1.1", config.Nameservers[0]) + assert.Equal(t, "2001:db8:abc8::1", config.Nameservers[1]) + assert.Equal(t, "5.5.5.5", config.Nameservers[2]) - assert.Equal(t, len(config.Search), 2) - assert.Equal(t, config.Search[0], "example.com") - assert.Equal(t, config.Search[1], "localdomain") + require.Len(t, config.Search, 2) + assert.Equal(t, "example.com", config.Search[0]) + assert.Equal(t, "localdomain", config.Search[1]) - assert.Equal(t, len(config.Options), 1) + require.Len(t, config.Options, 1) assert.Equal(t, config.Options[0], "ndots:9") } @@ -205,10 +206,9 @@ func TestUpdateMounts(t *testing.T) { } updateMounts(flags, &mounts) - assert.Equal(t, len(mounts), 2) - assert.Equal(t, mounts[0].Target, "/toadd") - assert.Equal(t, mounts[1].Target, "/tokeep") - + require.Len(t, mounts, 2) + assert.Equal(t, "/toadd", mounts[0].Target) + assert.Equal(t, "/tokeep", mounts[1].Target) } func TestUpdateMountsWithDuplicateMounts(t *testing.T) { @@ -222,10 +222,10 @@ func TestUpdateMountsWithDuplicateMounts(t *testing.T) { } updateMounts(flags, &mounts) - assert.Equal(t, len(mounts), 3) - assert.Equal(t, mounts[0].Target, "/tokeep1") - assert.Equal(t, mounts[1].Target, "/tokeep2") - assert.Equal(t, mounts[2].Target, "/toadd") + require.Len(t, mounts, 3) + assert.Equal(t, "/tokeep1", mounts[0].Target) + assert.Equal(t, "/tokeep2", mounts[1].Target) + assert.Equal(t, "/toadd", mounts[2].Target) } func TestUpdatePorts(t *testing.T) { @@ -239,13 +239,13 @@ func TestUpdatePorts(t *testing.T) { } err := updatePorts(flags, &portConfigs) - assert.Equal(t, err, nil) - assert.Equal(t, len(portConfigs), 2) + assert.NoError(t, err) + require.Len(t, portConfigs, 2) // Do a sort to have the order (might have changed by map) targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)} sort.Ints(targetPorts) - assert.Equal(t, targetPorts[0], 555) - assert.Equal(t, targetPorts[1], 1000) + assert.Equal(t, 555, targetPorts[0]) + assert.Equal(t, 1000, targetPorts[1]) } func TestUpdatePortsDuplicate(t *testing.T) { @@ -263,9 +263,9 @@ func TestUpdatePortsDuplicate(t *testing.T) { } err := updatePorts(flags, &portConfigs) - assert.Equal(t, err, nil) - assert.Equal(t, len(portConfigs), 1) - assert.Equal(t, portConfigs[0].TargetPort, uint32(80)) + assert.NoError(t, err) + require.Len(t, portConfigs, 1) + assert.Equal(t, uint32(80), portConfigs[0].TargetPort) } func TestUpdateHealthcheckTable(t *testing.T) { @@ -339,9 +339,9 @@ func TestUpdateHealthcheckTable(t *testing.T) { } err := updateHealthcheck(flags, cspec) if c.err != "" { - assert.Error(t, err, c.err) + assert.EqualError(t, err, c.err) } else { - assert.NilError(t, err) + assert.NoError(t, err) if !reflect.DeepEqual(cspec.Healthcheck, c.expected) { t.Errorf("incorrect result for test %d, expected health config:\n\t%#v\ngot:\n\t%#v", i, c.expected, cspec.Healthcheck) } @@ -358,15 +358,15 @@ func TestUpdateHosts(t *testing.T) { // just hostname should work as well flags.Set("host-rm", "example.net") // bad format error - assert.Error(t, flags.Set("host-add", "$example.com$"), "bad format for add-host:") + assert.EqualError(t, flags.Set("host-add", "$example.com$"), `bad format for add-host: "$example.com$"`) hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"} updateHosts(flags, &hosts) - assert.Equal(t, len(hosts), 3) - assert.Equal(t, hosts[0], "1.2.3.4 example.com") - assert.Equal(t, hosts[1], "2001:db8:abc8::1 ipv6.net") - assert.Equal(t, hosts[2], "4.3.2.1 example.org") + require.Len(t, hosts, 3) + assert.Equal(t, "1.2.3.4 example.com", hosts[0]) + assert.Equal(t, "2001:db8:abc8::1 ipv6.net", hosts[1]) + assert.Equal(t, "4.3.2.1 example.org", hosts[2]) } func TestUpdatePortsRmWithProtocol(t *testing.T) { @@ -387,10 +387,10 @@ func TestUpdatePortsRmWithProtocol(t *testing.T) { } err := updatePorts(flags, &portConfigs) - assert.Equal(t, err, nil) - assert.Equal(t, len(portConfigs), 2) - assert.Equal(t, portConfigs[0].TargetPort, uint32(81)) - assert.Equal(t, portConfigs[1].TargetPort, uint32(82)) + assert.NoError(t, err) + require.Len(t, portConfigs, 2) + assert.Equal(t, uint32(81), portConfigs[0].TargetPort) + assert.Equal(t, uint32(82), portConfigs[1].TargetPort) } type secretAPIClientMock struct { @@ -444,11 +444,11 @@ func TestUpdateSecretUpdateInPlace(t *testing.T) { updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets) - assert.Equal(t, err, nil) - assert.Equal(t, len(updatedSecrets), 1) - assert.Equal(t, updatedSecrets[0].SecretID, "tn9qiblgnuuut11eufquw5dev") - assert.Equal(t, updatedSecrets[0].SecretName, "foo") - assert.Equal(t, updatedSecrets[0].File.Name, "foo2") + assert.NoError(t, err) + require.Len(t, updatedSecrets, 1) + assert.Equal(t, "tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID) + assert.Equal(t, "foo", updatedSecrets[0].SecretName) + assert.Equal(t, "foo2", updatedSecrets[0].File.Name) } func TestUpdateReadOnly(t *testing.T) { @@ -459,18 +459,18 @@ func TestUpdateReadOnly(t *testing.T) { flags := newUpdateCommand(nil).Flags() flags.Set("read-only", "true") updateService(nil, nil, flags, spec) - assert.Equal(t, cspec.ReadOnly, true) + assert.True(t, cspec.ReadOnly) // Update without --read-only, no change flags = newUpdateCommand(nil).Flags() updateService(nil, nil, flags, spec) - assert.Equal(t, cspec.ReadOnly, true) + assert.True(t, cspec.ReadOnly) // Update with --read-only=false, changed to false flags = newUpdateCommand(nil).Flags() flags.Set("read-only", "false") updateService(nil, nil, flags, spec) - assert.Equal(t, cspec.ReadOnly, false) + assert.False(t, cspec.ReadOnly) } func TestUpdateStopSignal(t *testing.T) { @@ -481,16 +481,16 @@ func TestUpdateStopSignal(t *testing.T) { flags := newUpdateCommand(nil).Flags() flags.Set("stop-signal", "SIGUSR1") updateService(nil, nil, flags, spec) - assert.Equal(t, cspec.StopSignal, "SIGUSR1") + assert.Equal(t, "SIGUSR1", cspec.StopSignal) // Update without --stop-signal, no change flags = newUpdateCommand(nil).Flags() updateService(nil, nil, flags, spec) - assert.Equal(t, cspec.StopSignal, "SIGUSR1") + assert.Equal(t, "SIGUSR1", cspec.StopSignal) // Update with --stop-signal=SIGWINCH flags = newUpdateCommand(nil).Flags() flags.Set("stop-signal", "SIGWINCH") updateService(nil, nil, flags, spec) - assert.Equal(t, cspec.StopSignal, "SIGWINCH") + assert.Equal(t, "SIGWINCH", cspec.StopSignal) } diff --git a/command/stack/deploy_test.go b/command/stack/deploy_test.go index 328222af53..817c06dd04 100644 --- a/command/stack/deploy_test.go +++ b/command/stack/deploy_test.go @@ -6,7 +6,7 @@ import ( "github.com/docker/docker/cli/compose/convert" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" "golang.org/x/net/context" ) @@ -23,5 +23,5 @@ func TestPruneServices(t *testing.T) { pruneServices(ctx, dockerCli, namespace, services) - assert.DeepEqual(t, client.removedServices, buildObjectIDs([]string{objectName("foo", "remove")})) + assert.Equal(t, buildObjectIDs([]string{objectName("foo", "remove")}), client.removedServices) } diff --git a/command/stack/remove_test.go b/command/stack/remove_test.go index 7f64fb5505..17a334db1e 100644 --- a/command/stack/remove_test.go +++ b/command/stack/remove_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestRemoveStack(t *testing.T) { @@ -17,20 +17,20 @@ func TestRemoveStack(t *testing.T) { objectName("bar", "service1"), objectName("bar", "service2"), } - allServicesIDs := buildObjectIDs(allServices) + allServiceIDs := buildObjectIDs(allServices) allNetworks := []string{ objectName("foo", "network1"), objectName("bar", "network1"), } - allNetworksIDs := buildObjectIDs(allNetworks) + allNetworkIDs := buildObjectIDs(allNetworks) allSecrets := []string{ objectName("foo", "secret1"), objectName("foo", "secret2"), objectName("bar", "secret1"), } - allSecretsIDs := buildObjectIDs(allSecrets) + allSecretIDs := buildObjectIDs(allSecrets) cli := &fakeClient{ services: allServices, @@ -40,22 +40,22 @@ func TestRemoveStack(t *testing.T) { cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{})) cmd.SetArgs([]string{"foo", "bar"}) - assert.NilError(t, cmd.Execute()) - assert.DeepEqual(t, cli.removedServices, allServicesIDs) - assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs) - assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs) + assert.NoError(t, cmd.Execute()) + assert.Equal(t, allServiceIDs, cli.removedServices) + assert.Equal(t, allNetworkIDs, cli.removedNetworks) + assert.Equal(t, allSecretIDs, cli.removedSecrets) } func TestSkipEmptyStack(t *testing.T) { buf := new(bytes.Buffer) allServices := []string{objectName("bar", "service1"), objectName("bar", "service2")} - allServicesIDs := buildObjectIDs(allServices) + allServiceIDs := buildObjectIDs(allServices) allNetworks := []string{objectName("bar", "network1")} - allNetworksIDs := buildObjectIDs(allNetworks) + allNetworkIDs := buildObjectIDs(allNetworks) allSecrets := []string{objectName("bar", "secret1")} - allSecretsIDs := buildObjectIDs(allSecrets) + allSecretIDs := buildObjectIDs(allSecrets) cli := &fakeClient{ services: allServices, @@ -65,22 +65,22 @@ func TestSkipEmptyStack(t *testing.T) { cmd := newRemoveCommand(test.NewFakeCli(cli, buf)) cmd.SetArgs([]string{"foo", "bar"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Contains(t, buf.String(), "Nothing found in stack: foo") - assert.DeepEqual(t, cli.removedServices, allServicesIDs) - assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs) - assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs) + assert.Equal(t, allServiceIDs, cli.removedServices) + assert.Equal(t, allNetworkIDs, cli.removedNetworks) + assert.Equal(t, allSecretIDs, cli.removedSecrets) } func TestContinueAfterError(t *testing.T) { allServices := []string{objectName("foo", "service1"), objectName("bar", "service1")} - allServicesIDs := buildObjectIDs(allServices) + allServiceIDs := buildObjectIDs(allServices) allNetworks := []string{objectName("foo", "network1"), objectName("bar", "network1")} - allNetworksIDs := buildObjectIDs(allNetworks) + allNetworkIDs := buildObjectIDs(allNetworks) allSecrets := []string{objectName("foo", "secret1"), objectName("bar", "secret1")} - allSecretsIDs := buildObjectIDs(allSecrets) + allSecretIDs := buildObjectIDs(allSecrets) removedServices := []string{} cli := &fakeClient{ @@ -100,8 +100,8 @@ func TestContinueAfterError(t *testing.T) { cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{})) cmd.SetArgs([]string{"foo", "bar"}) - assert.Error(t, cmd.Execute(), "Failed to remove some resources from stack: foo") - assert.DeepEqual(t, removedServices, allServicesIDs) - assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs) - assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs) + assert.EqualError(t, cmd.Execute(), "Failed to remove some resources from stack: foo") + assert.Equal(t, allServiceIDs, removedServices) + assert.Equal(t, allNetworkIDs, cli.removedNetworks) + assert.Equal(t, allSecretIDs, cli.removedSecrets) } diff --git a/command/swarm/init_test.go b/command/swarm/init_test.go index c21433bdb9..39cb73888c 100644 --- a/command/swarm/init_test.go +++ b/command/swarm/init_test.go @@ -9,9 +9,10 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestSwarmInitErrorOnAPIFailure(t *testing.T) { @@ -76,7 +77,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + assert.EqualError(t, cmd.Execute(), tc.expectedError) } } @@ -122,9 +123,9 @@ func TestSwarmInit(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("init-%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/swarm/join_test.go b/command/swarm/join_test.go index 6d92f0c4fa..6893f68e1d 100644 --- a/command/swarm/join_test.go +++ b/command/swarm/join_test.go @@ -9,8 +9,9 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestSwarmJoinErrors(t *testing.T) { @@ -56,7 +57,7 @@ func TestSwarmJoinErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -96,7 +97,7 @@ func TestSwarmJoin(t *testing.T) { infoFunc: tc.infoFunc, }, buf)) cmd.SetArgs([]string{"remote"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected) } } diff --git a/command/swarm/join_token_test.go b/command/swarm/join_token_test.go index 9b10369ad0..9289189009 100644 --- a/command/swarm/join_token_test.go +++ b/command/swarm/join_token_test.go @@ -12,8 +12,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestSwarmJoinTokenErrors(t *testing.T) { @@ -102,7 +103,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -208,9 +209,9 @@ func TestSwarmJoinToken(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("jointoken-%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/swarm/leave_test.go b/command/swarm/leave_test.go index 93a58887a7..030f18039a 100644 --- a/command/swarm/leave_test.go +++ b/command/swarm/leave_test.go @@ -7,8 +7,9 @@ import ( "testing" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestSwarmLeaveErrors(t *testing.T) { @@ -39,7 +40,7 @@ func TestSwarmLeaveErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -47,6 +48,6 @@ func TestSwarmLeave(t *testing.T) { buf := new(bytes.Buffer) cmd := newLeaveCommand( test.NewFakeCli(&fakeClient{}, buf)) - assert.NilError(t, cmd.Execute()) - assert.Equal(t, strings.TrimSpace(buf.String()), "Node left the swarm.") + assert.NoError(t, cmd.Execute()) + assert.Equal(t, "Node left the swarm.", strings.TrimSpace(buf.String())) } diff --git a/command/swarm/opts_test.go b/command/swarm/opts_test.go index 9a97e8bd2c..c694cc1bdd 100644 --- a/command/swarm/opts_test.go +++ b/command/swarm/opts_test.go @@ -3,37 +3,37 @@ package swarm import ( "testing" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestNodeAddrOptionSetHostAndPort(t *testing.T) { opt := NewNodeAddrOption("old:123") addr := "newhost:5555" - assert.NilError(t, opt.Set(addr)) - assert.Equal(t, opt.Value(), addr) + assert.NoError(t, opt.Set(addr)) + assert.Equal(t, addr, opt.Value()) } func TestNodeAddrOptionSetHostOnly(t *testing.T) { opt := NewListenAddrOption() - assert.NilError(t, opt.Set("newhost")) - assert.Equal(t, opt.Value(), "newhost:2377") + assert.NoError(t, opt.Set("newhost")) + assert.Equal(t, "newhost:2377", opt.Value()) } func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) { opt := NewListenAddrOption() - assert.NilError(t, opt.Set("::1")) - assert.Equal(t, opt.Value(), "[::1]:2377") + assert.NoError(t, opt.Set("::1")) + assert.Equal(t, "[::1]:2377", opt.Value()) } func TestNodeAddrOptionSetPortOnly(t *testing.T) { opt := NewListenAddrOption() - assert.NilError(t, opt.Set(":4545")) - assert.Equal(t, opt.Value(), "0.0.0.0:4545") + assert.NoError(t, opt.Set(":4545")) + assert.Equal(t, "0.0.0.0:4545", opt.Value()) } func TestNodeAddrOptionSetInvalidFormat(t *testing.T) { opt := NewListenAddrOption() - assert.Error(t, opt.Set("http://localhost:4545"), "Invalid") + assert.EqualError(t, opt.Set("http://localhost:4545"), "Invalid proto, expected tcp: http://localhost:4545") } func TestExternalCAOptionErrors(t *testing.T) { @@ -64,7 +64,7 @@ func TestExternalCAOptionErrors(t *testing.T) { } for _, tc := range testCases { opt := &ExternalCAOption{} - assert.Error(t, opt.Set(tc.externalCA), tc.expectedError) + assert.EqualError(t, opt.Set(tc.externalCA), tc.expectedError) } } @@ -96,15 +96,15 @@ func TestExternalCAOption(t *testing.T) { } for _, tc := range testCases { opt := &ExternalCAOption{} - assert.NilError(t, opt.Set(tc.externalCA)) - assert.Equal(t, opt.String(), tc.expected) + assert.NoError(t, opt.Set(tc.externalCA)) + assert.Equal(t, tc.expected, opt.String()) } } func TestExternalCAOptionMultiple(t *testing.T) { opt := &ExternalCAOption{} - assert.NilError(t, opt.Set("protocol=cfssl,url=https://example.com")) - assert.NilError(t, opt.Set("protocol=CFSSL,url=anything")) - assert.Equal(t, len(opt.Value()), 2) - assert.Equal(t, opt.String(), "cfssl: https://example.com, cfssl: anything") + assert.NoError(t, opt.Set("protocol=cfssl,url=https://example.com")) + assert.NoError(t, opt.Set("protocol=CFSSL,url=anything")) + assert.Len(t, opt.Value(), 2) + assert.Equal(t, "cfssl: https://example.com, cfssl: anything", opt.String()) } diff --git a/command/swarm/unlock_key_test.go b/command/swarm/unlock_key_test.go index 7b644f70e9..23752104aa 100644 --- a/command/swarm/unlock_key_test.go +++ b/command/swarm/unlock_key_test.go @@ -12,8 +12,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestSwarmUnlockKeyErrors(t *testing.T) { @@ -94,7 +95,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -168,9 +169,9 @@ func TestSwarmUnlockKey(t *testing.T) { for key, value := range tc.flags { cmd.Flags().Set(key, value) } - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("unlockkeys-%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/swarm/unlock_test.go b/command/swarm/unlock_test.go index 620fecafed..e1a2bb4cc5 100644 --- a/command/swarm/unlock_test.go +++ b/command/swarm/unlock_test.go @@ -9,8 +9,9 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/swarm" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestSwarmUnlockErrors(t *testing.T) { @@ -73,7 +74,7 @@ func TestSwarmUnlockErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -97,5 +98,5 @@ func TestSwarmUnlock(t *testing.T) { }, buf) dockerCli.SetIn(ioutil.NopCloser(strings.NewReader(input))) cmd := newUnlockCommand(dockerCli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } diff --git a/command/swarm/update_test.go b/command/swarm/update_test.go index 0450c02979..65366ddd20 100644 --- a/command/swarm/update_test.go +++ b/command/swarm/update_test.go @@ -13,8 +13,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestSwarmUpdateErrors(t *testing.T) { @@ -79,7 +80,7 @@ func TestSwarmUpdateErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -175,9 +176,9 @@ func TestSwarmUpdate(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(buf) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("update-%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/volume/create_test.go b/command/volume/create_test.go index ccb7ac75bf..45cf631134 100644 --- a/command/volume/create_test.go +++ b/command/volume/create_test.go @@ -9,8 +9,9 @@ import ( "github.com/docker/docker/api/types" volumetypes "github.com/docker/docker/api/types/volume" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestVolumeCreateErrors(t *testing.T) { @@ -50,7 +51,7 @@ func TestVolumeCreateErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -71,15 +72,15 @@ func TestVolumeCreateWithName(t *testing.T) { // Test by flags cmd := newCreateCommand(cli) cmd.Flags().Set("name", name) - assert.NilError(t, cmd.Execute()) - assert.Equal(t, strings.TrimSpace(buf.String()), name) + assert.NoError(t, cmd.Execute()) + assert.Equal(t, name, strings.TrimSpace(buf.String())) // Then by args buf.Reset() cmd = newCreateCommand(cli) cmd.SetArgs([]string{name}) - assert.NilError(t, cmd.Execute()) - assert.Equal(t, strings.TrimSpace(buf.String()), name) + assert.NoError(t, cmd.Execute()) + assert.Equal(t, name, strings.TrimSpace(buf.String())) } func TestVolumeCreateWithFlags(t *testing.T) { @@ -121,8 +122,8 @@ func TestVolumeCreateWithFlags(t *testing.T) { cmd.Flags().Set("opt", "baz=baz") cmd.Flags().Set("label", "lbl1=v1") cmd.Flags().Set("label", "lbl2=v2") - assert.NilError(t, cmd.Execute()) - assert.Equal(t, strings.TrimSpace(buf.String()), name) + assert.NoError(t, cmd.Execute()) + assert.Equal(t, name, strings.TrimSpace(buf.String())) } func compareMap(actual map[string]string, expected map[string]string) bool { diff --git a/command/volume/inspect_test.go b/command/volume/inspect_test.go index 7c4cce39db..bc1b526440 100644 --- a/command/volume/inspect_test.go +++ b/command/volume/inspect_test.go @@ -11,8 +11,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestVolumeInspectErrors(t *testing.T) { @@ -64,7 +65,7 @@ func TestVolumeInspectErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -102,10 +103,10 @@ func TestVolumeInspectWithoutFormat(t *testing.T) { }, buf), ) cmd.SetArgs(tc.args) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-without-format.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } @@ -143,9 +144,9 @@ func TestVolumeInspectWithFormat(t *testing.T) { ) cmd.SetArgs(tc.args) cmd.Flags().Set("format", tc.format) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/volume/list_test.go b/command/volume/list_test.go index b2306a5d8e..4f5e99389f 100644 --- a/command/volume/list_test.go +++ b/command/volume/list_test.go @@ -13,8 +13,9 @@ import ( "github.com/pkg/errors" // Import builders to get the builder function as package function . "github.com/docker/docker/cli/internal/test/builders" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" + "github.com/stretchr/testify/assert" ) func TestVolumeListErrors(t *testing.T) { @@ -47,7 +48,7 @@ func TestVolumeListErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -68,10 +69,10 @@ func TestVolumeListWithoutFormat(t *testing.T) { }, buf) cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "volume-list-without-format.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } func TestVolumeListWithConfigFormat(t *testing.T) { @@ -93,10 +94,10 @@ func TestVolumeListWithConfigFormat(t *testing.T) { VolumesFormat: "{{ .Name }} {{ .Driver }} {{ .Labels }}", }) cmd := newListCommand(cli) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "volume-list-with-config-format.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } func TestVolumeListWithFormat(t *testing.T) { @@ -117,8 +118,8 @@ func TestVolumeListWithFormat(t *testing.T) { cli.SetConfigfile(&configfile.ConfigFile{}) cmd := newListCommand(cli) cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "volume-list-with-format.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } diff --git a/command/volume/prune_test.go b/command/volume/prune_test.go index dab997f625..05da9bdded 100644 --- a/command/volume/prune_test.go +++ b/command/volume/prune_test.go @@ -11,9 +11,10 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/filters" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/docker/docker/pkg/testutil/golden" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestVolumePruneErrors(t *testing.T) { @@ -48,7 +49,7 @@ func TestVolumePruneErrors(t *testing.T) { cmd.Flags().Set(key, value) } cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -73,10 +74,10 @@ func TestVolumePruneForce(t *testing.T) { }, buf), ) cmd.Flags().Set("force", "true") - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-prune.%s.golden", tc.name)) - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } func TestVolumePrunePromptYes(t *testing.T) { @@ -94,10 +95,10 @@ func TestVolumePrunePromptYes(t *testing.T) { cmd := NewPruneCommand( cli, ) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "volume-prune-yes.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } @@ -116,10 +117,10 @@ func TestVolumePrunePromptNo(t *testing.T) { cmd := NewPruneCommand( cli, ) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) actual := buf.String() expected := golden.Get(t, []byte(actual), "volume-prune-no.golden") - assert.EqualNormalizedString(t, assert.RemoveSpace, actual, string(expected)) + testutil.EqualNormalizedString(t, testutil.RemoveSpace, actual, string(expected)) } } diff --git a/command/volume/remove_test.go b/command/volume/remove_test.go index 0154a5d551..5a4dc1f4b7 100644 --- a/command/volume/remove_test.go +++ b/command/volume/remove_test.go @@ -6,8 +6,9 @@ import ( "testing" "github.com/docker/docker/cli/internal/test" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" "github.com/pkg/errors" + "github.com/stretchr/testify/assert" ) func TestVolumeRemoveErrors(t *testing.T) { @@ -35,7 +36,7 @@ func TestVolumeRemoveErrors(t *testing.T) { }, buf)) cmd.SetArgs(tc.args) cmd.SetOutput(ioutil.Discard) - assert.Error(t, cmd.Execute(), tc.expectedError) + testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) } } @@ -43,5 +44,5 @@ func TestNodeRemoveMultiple(t *testing.T) { buf := new(bytes.Buffer) cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf)) cmd.SetArgs([]string{"volume1", "volume2"}) - assert.NilError(t, cmd.Execute()) + assert.NoError(t, cmd.Execute()) } diff --git a/compose/convert/compose_test.go b/compose/convert/compose_test.go index c267820956..a76d5ecd4f 100644 --- a/compose/convert/compose_test.go +++ b/compose/convert/compose_test.go @@ -6,13 +6,14 @@ import ( "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/network" composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" "github.com/docker/docker/pkg/testutil/tempfile" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) func TestNamespaceScope(t *testing.T) { scoped := Namespace{name: "foo"}.Scope("bar") - assert.Equal(t, scoped, "foo_bar") + assert.Equal(t, "foo_bar", scoped) } func TestAddStackLabel(t *testing.T) { @@ -24,7 +25,7 @@ func TestAddStackLabel(t *testing.T) { "something": "labeled", LabelNamespace: "foo", } - assert.DeepEqual(t, actual, expected) + assert.Equal(t, expected, actual) } func TestNetworks(t *testing.T) { @@ -98,8 +99,8 @@ func TestNetworks(t *testing.T) { } networks, externals := Networks(namespace, source, serviceNetworks) - assert.DeepEqual(t, networks, expected) - assert.DeepEqual(t, externals, []string{"special"}) + assert.Equal(t, expected, networks) + assert.Equal(t, []string{"special"}, externals) } func TestSecrets(t *testing.T) { @@ -122,13 +123,13 @@ func TestSecrets(t *testing.T) { } specs, err := Secrets(namespace, source) - assert.NilError(t, err) - assert.Equal(t, len(specs), 1) + assert.NoError(t, err) + require.Len(t, specs, 1) secret := specs[0] - assert.Equal(t, secret.Name, "foo_one") - assert.DeepEqual(t, secret.Labels, map[string]string{ + assert.Equal(t, "foo_one", secret.Name) + assert.Equal(t, map[string]string{ "monster": "mash", LabelNamespace: "foo", - }) - assert.DeepEqual(t, secret.Data, []byte(secretText)) + }, secret.Labels) + assert.Equal(t, []byte(secretText), secret.Data) } diff --git a/compose/convert/service_test.go b/compose/convert/service_test.go index 91af572994..b08ecf3636 100644 --- a/compose/convert/service_test.go +++ b/compose/convert/service_test.go @@ -9,18 +9,18 @@ import ( "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestConvertRestartPolicyFromNone(t *testing.T) { policy, err := convertRestartPolicy("no", nil) - assert.NilError(t, err) - assert.Equal(t, policy, (*swarm.RestartPolicy)(nil)) + assert.NoError(t, err) + assert.Equal(t, (*swarm.RestartPolicy)(nil), policy) } func TestConvertRestartPolicyFromUnknown(t *testing.T) { _, err := convertRestartPolicy("unknown", nil) - assert.Error(t, err, "unknown restart policy: unknown") + assert.EqualError(t, err, "unknown restart policy: unknown") } func TestConvertRestartPolicyFromAlways(t *testing.T) { @@ -28,8 +28,8 @@ func TestConvertRestartPolicyFromAlways(t *testing.T) { expected := &swarm.RestartPolicy{ Condition: swarm.RestartPolicyConditionAny, } - assert.NilError(t, err) - assert.DeepEqual(t, policy, expected) + assert.NoError(t, err) + assert.Equal(t, expected, policy) } func TestConvertRestartPolicyFromFailure(t *testing.T) { @@ -39,8 +39,8 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) { Condition: swarm.RestartPolicyConditionOnFailure, MaxAttempts: &attempts, } - assert.NilError(t, err) - assert.DeepEqual(t, policy, expected) + assert.NoError(t, err) + assert.Equal(t, expected, policy) } func strPtr(val string) *string { @@ -54,7 +54,7 @@ func TestConvertEnvironment(t *testing.T) { } env := convertEnvironment(source) sort.Strings(env) - assert.DeepEqual(t, env, []string{"foo=bar", "key=value"}) + assert.Equal(t, []string{"foo=bar", "key=value"}, env) } func TestConvertResourcesFull(t *testing.T) { @@ -69,7 +69,7 @@ func TestConvertResourcesFull(t *testing.T) { }, } resources, err := convertResources(source) - assert.NilError(t, err) + assert.NoError(t, err) expected := &swarm.ResourceRequirements{ Limits: &swarm.Resources{ @@ -81,7 +81,7 @@ func TestConvertResourcesFull(t *testing.T) { MemoryBytes: 200000000, }, } - assert.DeepEqual(t, resources, expected) + assert.Equal(t, expected, resources) } func TestConvertResourcesOnlyMemory(t *testing.T) { @@ -94,7 +94,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) { }, } resources, err := convertResources(source) - assert.NilError(t, err) + assert.NoError(t, err) expected := &swarm.ResourceRequirements{ Limits: &swarm.Resources{ @@ -104,7 +104,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) { MemoryBytes: 200000000, }, } - assert.DeepEqual(t, resources, expected) + assert.Equal(t, expected, resources) } func TestConvertHealthcheck(t *testing.T) { @@ -123,8 +123,8 @@ func TestConvertHealthcheck(t *testing.T) { } healthcheck, err := convertHealthcheck(source) - assert.NilError(t, err) - assert.DeepEqual(t, healthcheck, expected) + assert.NoError(t, err) + assert.Equal(t, expected, healthcheck) } func TestConvertHealthcheckDisable(t *testing.T) { @@ -134,8 +134,8 @@ func TestConvertHealthcheckDisable(t *testing.T) { } healthcheck, err := convertHealthcheck(source) - assert.NilError(t, err) - assert.DeepEqual(t, healthcheck, expected) + assert.NoError(t, err) + assert.Equal(t, expected, healthcheck) } func TestConvertHealthcheckDisableWithTest(t *testing.T) { @@ -144,7 +144,7 @@ func TestConvertHealthcheckDisableWithTest(t *testing.T) { Test: []string{"EXEC", "touch"}, } _, err := convertHealthcheck(source) - assert.Error(t, err, "test and disable can't be set") + assert.EqualError(t, err, "test and disable can't be set at the same time") } func TestConvertEndpointSpec(t *testing.T) { @@ -178,8 +178,8 @@ func TestConvertEndpointSpec(t *testing.T) { }, } - assert.NilError(t, err) - assert.DeepEqual(t, *endpoint, expected) + assert.NoError(t, err) + assert.Equal(t, expected, *endpoint) } func TestConvertServiceNetworksOnlyDefault(t *testing.T) { @@ -195,8 +195,8 @@ func TestConvertServiceNetworksOnlyDefault(t *testing.T) { }, } - assert.NilError(t, err) - assert.DeepEqual(t, configs, expected) + assert.NoError(t, err) + assert.Equal(t, expected, configs) } func TestConvertServiceNetworks(t *testing.T) { @@ -235,8 +235,8 @@ func TestConvertServiceNetworks(t *testing.T) { sortedConfigs := byTargetSort(configs) sort.Sort(&sortedConfigs) - assert.NilError(t, err) - assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(sortedConfigs), expected) + assert.NoError(t, err) + assert.Equal(t, expected, []swarm.NetworkAttachmentConfig(sortedConfigs)) } func TestConvertServiceNetworksCustomDefault(t *testing.T) { @@ -260,8 +260,8 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) { }, } - assert.NilError(t, err) - assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(configs), expected) + assert.NoError(t, err) + assert.Equal(t, expected, []swarm.NetworkAttachmentConfig(configs)) } type byTargetSort []swarm.NetworkAttachmentConfig @@ -281,8 +281,8 @@ func (s byTargetSort) Swap(i, j int) { func TestConvertDNSConfigEmpty(t *testing.T) { dnsConfig, err := convertDNSConfig(nil, nil) - assert.NilError(t, err) - assert.Equal(t, dnsConfig, (*swarm.DNSConfig)(nil)) + assert.NoError(t, err) + assert.Equal(t, (*swarm.DNSConfig)(nil), dnsConfig) } var ( @@ -292,27 +292,27 @@ var ( func TestConvertDNSConfigAll(t *testing.T) { dnsConfig, err := convertDNSConfig(nameservers, search) - assert.NilError(t, err) - assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{ + assert.NoError(t, err) + assert.Equal(t, &swarm.DNSConfig{ Nameservers: nameservers, Search: search, - }) + }, dnsConfig) } func TestConvertDNSConfigNameservers(t *testing.T) { dnsConfig, err := convertDNSConfig(nameservers, nil) - assert.NilError(t, err) - assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{ + assert.NoError(t, err) + assert.Equal(t, &swarm.DNSConfig{ Nameservers: nameservers, Search: nil, - }) + }, dnsConfig) } func TestConvertDNSConfigSearch(t *testing.T) { dnsConfig, err := convertDNSConfig(nil, search) - assert.NilError(t, err) - assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{ + assert.NoError(t, err) + assert.Equal(t, &swarm.DNSConfig{ Nameservers: nil, Search: search, - }) + }, dnsConfig) } diff --git a/compose/convert/volume_test.go b/compose/convert/volume_test.go index 73d642e5fe..a7502d1737 100644 --- a/compose/convert/volume_test.go +++ b/compose/convert/volume_test.go @@ -5,7 +5,7 @@ import ( "github.com/docker/docker/api/types/mount" composetypes "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/stretchr/testify/assert" ) func TestConvertVolumeToMountAnonymousVolume(t *testing.T) { @@ -18,8 +18,8 @@ func TestConvertVolumeToMountAnonymousVolume(t *testing.T) { Target: "/foo/bar", } mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) + assert.NoError(t, err) + assert.Equal(t, expected, mount) } func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) { @@ -34,7 +34,7 @@ func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) { }, } _, err := convertVolumeToMount(config, volumes{}, namespace) - assert.Error(t, err, "bind options are incompatible") + assert.EqualError(t, err, "bind options are incompatible with type volume") } func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) { @@ -49,7 +49,7 @@ func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) { }, } _, err := convertVolumeToMount(config, volumes{}, namespace) - assert.Error(t, err, "volume options are incompatible") + assert.EqualError(t, err, "volume options are incompatible with type bind") } func TestConvertVolumeToMountNamedVolume(t *testing.T) { @@ -94,8 +94,8 @@ func TestConvertVolumeToMountNamedVolume(t *testing.T) { }, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) + assert.NoError(t, err) + assert.Equal(t, expected, mount) } func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) { @@ -122,8 +122,8 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) { Target: "/foo", } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) + assert.NoError(t, err) + assert.Equal(t, expected, mount) } func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) { @@ -153,8 +153,8 @@ func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) { }, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) + assert.NoError(t, err) + assert.Equal(t, expected, mount) } func TestConvertVolumeToMountBind(t *testing.T) { @@ -175,8 +175,8 @@ func TestConvertVolumeToMountBind(t *testing.T) { Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"}, } mount, err := convertVolumeToMount(config, stackVolumes, namespace) - assert.NilError(t, err) - assert.DeepEqual(t, mount, expected) + assert.NoError(t, err) + assert.Equal(t, expected, mount) } func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) { @@ -188,5 +188,5 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) { ReadOnly: true, } _, err := convertVolumeToMount(config, volumes{}, namespace) - assert.Error(t, err, "undefined volume \"unknown\"") + assert.EqualError(t, err, "undefined volume \"unknown\"") } diff --git a/compose/loader/volume_test.go b/compose/loader/volume_test.go index 19d19f2306..9b09c13534 100644 --- a/compose/loader/volume_test.go +++ b/compose/loader/volume_test.go @@ -4,15 +4,16 @@ import ( "testing" "github.com/docker/docker/cli/compose/types" - "github.com/docker/docker/pkg/testutil/assert" + "github.com/docker/docker/pkg/testutil" + "github.com/stretchr/testify/assert" ) func TestParseVolumeAnonymousVolume(t *testing.T) { for _, path := range []string{"/path", "/path/foo"} { volume, err := parseVolume(path) expected := types.ServiceVolumeConfig{Type: "volume", Target: path} - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } @@ -20,29 +21,29 @@ func TestParseVolumeAnonymousVolumeWindows(t *testing.T) { for _, path := range []string{"C:\\path", "Z:\\path\\foo"} { volume, err := parseVolume(path) expected := types.ServiceVolumeConfig{Type: "volume", Target: path} - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } func TestParseVolumeTooManyColons(t *testing.T) { _, err := parseVolume("/foo:/foo:ro:foo") - assert.Error(t, err, "too many colons") + assert.EqualError(t, err, "invalid spec: /foo:/foo:ro:foo: too many colons") } func TestParseVolumeShortVolumes(t *testing.T) { for _, path := range []string{".", "/a"} { volume, err := parseVolume(path) expected := types.ServiceVolumeConfig{Type: "volume", Target: path} - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } func TestParseVolumeMissingSource(t *testing.T) { for _, spec := range []string{":foo", "/foo::ro"} { _, err := parseVolume(spec) - assert.Error(t, err, "empty section between colons") + testutil.ErrorContains(t, err, "empty section between colons") } } @@ -54,8 +55,8 @@ func TestParseVolumeBindMount(t *testing.T) { Source: path, Target: "/target", } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } @@ -72,8 +73,8 @@ func TestParseVolumeRelativeBindMountWindows(t *testing.T) { Source: path, Target: "d:\\target", } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } @@ -85,8 +86,8 @@ func TestParseVolumeWithBindOptions(t *testing.T) { Target: "/target", Bind: &types.ServiceVolumeBind{Propagation: "slave"}, } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } func TestParseVolumeWithBindOptionsWindows(t *testing.T) { @@ -98,13 +99,13 @@ func TestParseVolumeWithBindOptionsWindows(t *testing.T) { ReadOnly: true, Bind: &types.ServiceVolumeBind{Propagation: "rprivate"}, } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) { _, err := parseVolume("name:/target:bogus") - assert.Error(t, err, "invalid spec: name:/target:bogus: unknown option: bogus") + assert.EqualError(t, err, "invalid spec: name:/target:bogus: unknown option: bogus") } func TestParseVolumeWithVolumeOptions(t *testing.T) { @@ -115,8 +116,8 @@ func TestParseVolumeWithVolumeOptions(t *testing.T) { Target: "/target", Volume: &types.ServiceVolumeVolume{NoCopy: true}, } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } func TestParseVolumeWithReadOnly(t *testing.T) { @@ -128,8 +129,8 @@ func TestParseVolumeWithReadOnly(t *testing.T) { Target: "/target", ReadOnly: true, } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } @@ -142,7 +143,7 @@ func TestParseVolumeWithRW(t *testing.T) { Target: "/target", ReadOnly: false, } - assert.NilError(t, err) - assert.DeepEqual(t, volume, expected) + assert.NoError(t, err) + assert.Equal(t, expected, volume) } } diff --git a/compose/template/template_test.go b/compose/template/template_test.go index 6b81bf0a39..4ad3f252ac 100644 --- a/compose/template/template_test.go +++ b/compose/template/template_test.go @@ -18,7 +18,7 @@ func defaultMapping(name string) (string, bool) { func TestEscaped(t *testing.T) { result, err := Substitute("$${foo}", defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "${foo}", result) } @@ -43,7 +43,7 @@ func TestInvalid(t *testing.T) { func TestNoValueNoDefault(t *testing.T) { for _, template := range []string{"This ${missing} var", "This ${BAR} var"} { result, err := Substitute(template, defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "This var", result) } } @@ -51,7 +51,7 @@ func TestNoValueNoDefault(t *testing.T) { func TestValueNoDefault(t *testing.T) { for _, template := range []string{"This $FOO var", "This ${FOO} var"} { result, err := Substitute(template, defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "This first var", result) } } @@ -59,25 +59,25 @@ func TestValueNoDefault(t *testing.T) { func TestNoValueWithDefault(t *testing.T) { for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} { result, err := Substitute(template, defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "ok def", result) } } func TestEmptyValueWithSoftDefault(t *testing.T) { result, err := Substitute("ok ${BAR:-def}", defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "ok def", result) } func TestEmptyValueWithHardDefault(t *testing.T) { result, err := Substitute("ok ${BAR-def}", defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "ok ", result) } func TestNonAlphanumericDefault(t *testing.T) { result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping) - assert.NoError(t, err) + assert.Nil(t, err) assert.Equal(t, "ok /non:-alphanumeric", result) } diff --git a/flags/common_test.go b/flags/common_test.go index 616d577f0b..cf0bf22e26 100644 --- a/flags/common_test.go +++ b/flags/common_test.go @@ -5,8 +5,8 @@ import ( "testing" cliconfig "github.com/docker/docker/cli/config" - "github.com/docker/docker/pkg/testutil/assert" "github.com/spf13/pflag" + "github.com/stretchr/testify/assert" ) func TestCommonOptionsInstallFlags(t *testing.T) { @@ -19,9 +19,9 @@ func TestCommonOptionsInstallFlags(t *testing.T) { "--tlscert=\"/foo/cert\"", "--tlskey=\"/foo/key\"", }) - assert.NilError(t, err) - assert.Equal(t, opts.TLSOptions.CAFile, "/foo/cafile") - assert.Equal(t, opts.TLSOptions.CertFile, "/foo/cert") + 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") } @@ -35,8 +35,8 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) { opts.InstallFlags(flags) err := flags.Parse([]string{}) - assert.NilError(t, err) - assert.Equal(t, opts.TLSOptions.CAFile, defaultPath("ca.pem")) - assert.Equal(t, opts.TLSOptions.CertFile, defaultPath("cert.pem")) - assert.Equal(t, opts.TLSOptions.KeyFile, defaultPath("key.pem")) + 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) }