Remove pkg/testutil/assert in favor of testify

I noticed that we're using a homegrown package for assertions. The
functions are extremely similar to testify, but with enough slight
differences to be confusing (for example, Equal takes its arguments in a
different order). We already vendor testify, and it's used in a few
places by tests.

I also found some problems with pkg/testutil/assert. For example, the
NotNil function seems to be broken. It checks the argument against
"nil", which only works for an interface. If you pass in a nil map or
slice, the equality check will fail.

In the interest of avoiding NIH, I'm proposing replacing
pkg/testutil/assert with testify. The test code looks almost the same,
but we avoid the confusion of having two similar but slightly different
assertion packages, and having to maintain our own package instead of
using a commonly-used one.

In the process, I found a few places where the tests should halt if an
assertion fails, so I've made those cases (that I noticed) use "require"
instead of "assert", and I've vendored the "require" package from
testify alongside the already-present "assert" package.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2017-04-13 15:45:37 -07:00
parent 1601dbe620
commit 7059a96e2e
51 changed files with 469 additions and 445 deletions

View File

@ -5,7 +5,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestLoadFileV01Success(t *testing.T) { func TestLoadFileV01Success(t *testing.T) {
@ -25,9 +25,9 @@ func TestLoadFileV01Success(t *testing.T) {
}`) }`)
bundle, err := LoadFile(reader) bundle, err := LoadFile(reader)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, bundle.Version, "0.1") assert.Equal(t, "0.1", bundle.Version)
assert.Equal(t, len(bundle.Services), 2) assert.Len(t, bundle.Services, 2)
} }
func TestLoadFileSyntaxError(t *testing.T) { func TestLoadFileSyntaxError(t *testing.T) {
@ -37,7 +37,7 @@ func TestLoadFileSyntaxError(t *testing.T) {
}`) }`)
_, err := LoadFile(reader) _, 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) { func TestLoadFileTypeError(t *testing.T) {
@ -52,7 +52,7 @@ func TestLoadFileTypeError(t *testing.T) {
}`) }`)
_, err := LoadFile(reader) _, 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) { 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() output := buffer.String()
assert.Contains(t, output, "\"Image\": \"image\"") assert.Contains(t, output, "\"Image\": \"image\"")
assert.Contains(t, output, assert.Contains(t, output,

View File

@ -13,11 +13,12 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network" 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/docker/runconfig"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
) )
func TestValidateAttach(t *testing.T) { func TestValidateAttach(t *testing.T) {
@ -243,23 +244,23 @@ func TestParseWithMacAddress(t *testing.T) {
func TestParseWithMemory(t *testing.T) { func TestParseWithMemory(t *testing.T) {
invalidMemory := "--memory=invalid" invalidMemory := "--memory=invalid"
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"}) _, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
assert.Error(t, err, invalidMemory) testutil.ErrorContains(t, err, invalidMemory)
_, hostconfig := mustParse(t, "--memory=1G") _, hostconfig := mustParse(t, "--memory=1G")
assert.Equal(t, hostconfig.Memory, int64(1073741824)) assert.Equal(t, int64(1073741824), hostconfig.Memory)
} }
func TestParseWithMemorySwap(t *testing.T) { func TestParseWithMemorySwap(t *testing.T) {
invalidMemory := "--memory-swap=invalid" invalidMemory := "--memory-swap=invalid"
_, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"}) _, _, _, err := parseRun([]string{invalidMemory, "img", "cmd"})
assert.Error(t, err, invalidMemory) testutil.ErrorContains(t, err, invalidMemory)
_, hostconfig := mustParse(t, "--memory-swap=1G") _, 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") _, 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) { func TestParseHostname(t *testing.T) {

View File

@ -4,13 +4,13 @@ import (
"testing" "testing"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestBuildContainerListOptions(t *testing.T) { func TestBuildContainerListOptions(t *testing.T) {
filters := opts.NewFilterOpt() filters := opts.NewFilterOpt()
assert.NilError(t, filters.Set("foo=bar")) assert.NoError(t, filters.Set("foo=bar"))
assert.NilError(t, filters.Set("baz=foo")) assert.NoError(t, filters.Set("baz=foo"))
contexts := []struct { contexts := []struct {
psOpts *psOptions psOpts *psOptions
@ -101,12 +101,12 @@ func TestBuildContainerListOptions(t *testing.T) {
for _, c := range contexts { for _, c := range contexts {
options, err := buildContainerListOptions(c.psOpts) options, err := buildContainerListOptions(c.psOpts)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, c.expectedAll, options.All) assert.Equal(t, c.expectedAll, options.All)
assert.Equal(t, c.expectedSize, options.Size) assert.Equal(t, c.expectedSize, options.Size)
assert.Equal(t, c.expectedLimit, options.Limit) 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 { for k, v := range c.expectedFilters {
f := options.Filters f := options.Filters

View File

@ -10,7 +10,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestContainerPsContext(t *testing.T) { func TestContainerPsContext(t *testing.T) {
@ -245,9 +245,9 @@ conta "ubuntu" 24 hours ago//.FOOBAR_BAR
testcase.context.Output = out testcase.context.Output = out
err := ContainerWrite(testcase.context, containers) err := ContainerWrite(testcase.context, containers)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err) 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 { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, containers[i].ID) assert.Equal(t, containers[i].ID, s)
} }
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestDiffContextFormatWrite(t *testing.T) { func TestDiffContextFormatWrite(t *testing.T) {
@ -51,9 +51,9 @@ D: /usr/app/old_app.js
testcase.context.Output = out testcase.context.Output = out
err := DiffWrite(testcase.context, diffs) err := DiffWrite(testcase.context, diffs)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Equal(t, testcase.expected, out.String())
} }
} }
} }

View File

@ -4,7 +4,7 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestDiskUsageContextFormatWrite(t *testing.T) { func TestDiskUsageContextFormatWrite(t *testing.T) {
@ -117,9 +117,9 @@ reclaimable: 0B
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
testcase.context.Output = out testcase.context.Output = out
if err := testcase.context.Write(); err != nil { if err := testcase.context.Write(); err != nil {
assert.Equal(t, err.Error(), testcase.expected) assert.Equal(t, testcase.expected, err.Error())
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Equal(t, testcase.expected, out.String())
} }
} }
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestImageContext(t *testing.T) { func TestImageContext(t *testing.T) {
@ -265,9 +265,9 @@ image_id: imageID3
testcase.context.Output = out testcase.context.Output = out
err := ImageWrite(testcase.context, images) err := ImageWrite(testcase.context, images)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { for _, context := range contexts {
ImageWrite(context.context, images) ImageWrite(context.context, images)
assert.Equal(t, out.String(), context.expected) assert.Equal(t, context.expected, out.String())
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestNetworkContext(t *testing.T) { func TestNetworkContext(t *testing.T) {
@ -160,9 +160,9 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
testcase.context.Output = out testcase.context.Output = out
err := NetworkWrite(testcase.context, networks) err := NetworkWrite(testcase.context, networks)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err) 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 { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, networks[i].ID) assert.Equal(t, networks[i].ID, s)
} }
} }

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestNodeContext(t *testing.T) { func TestNodeContext(t *testing.T) {
@ -135,9 +135,9 @@ foobar_bar
testcase.context.Output = out testcase.context.Output = out
err := NodeWrite(testcase.context, nodes, types.Info{}) err := NodeWrite(testcase.context, nodes, types.Info{})
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err) 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 { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, nodes[i].ID) assert.Equal(t, nodes[i].ID, s)
} }
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestPluginContext(t *testing.T) { func TestPluginContext(t *testing.T) {
@ -131,9 +131,9 @@ foobar_bar
testcase.context.Output = out testcase.context.Output = out
err := PluginWrite(testcase.context, plugins) err := PluginWrite(testcase.context, plugins)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err) 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 { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, plugins[i].ID) assert.Equal(t, plugins[i].ID, s)
} }
} }

View File

@ -6,7 +6,7 @@ import (
"time" "time"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestSecretContextFormatWrite(t *testing.T) { func TestSecretContextFormatWrite(t *testing.T) {
@ -55,9 +55,9 @@ id_rsa
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
testcase.context.Output = out testcase.context.Output = out
if err := SecretWrite(testcase.context, secrets); err != nil { if err := SecretWrite(testcase.context, secrets); err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Equal(t, testcase.expected, out.String())
} }
} }
} }

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestServiceContextWrite(t *testing.T) { func TestServiceContextWrite(t *testing.T) {
@ -137,9 +137,9 @@ bar
testcase.context.Output = out testcase.context.Output = out
err := ServiceListWrite(testcase.context, services, info) err := ServiceListWrite(testcase.context, services, info)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.DeepEqual(t, m, expectedJSONs[i]) assert.Equal(t, expectedJSONs[i], m)
} }
} }
func TestServiceContextWriteJSONField(t *testing.T) { func TestServiceContextWriteJSONField(t *testing.T) {
@ -234,6 +234,6 @@ func TestServiceContextWriteJSONField(t *testing.T) {
if err := json.Unmarshal([]byte(line), &s); err != nil { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, services[i].Spec.Name) assert.Equal(t, services[i].Spec.Name, s)
} }
} }

View File

@ -5,7 +5,7 @@ import (
"testing" "testing"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestContainerStatsContext(t *testing.T) { func TestContainerStatsContext(t *testing.T) {
@ -116,9 +116,9 @@ container2 --
te.context.Output = &out te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "linux") err := ContainerStatsWrite(te.context, stats, "linux")
if err != nil { if err != nil {
assert.Error(t, err, te.expected) assert.EqualError(t, err, te.expected)
} else { } else {
assert.Equal(t, out.String(), te.expected) assert.Equal(t, te.expected, out.String())
} }
} }
} }
@ -182,9 +182,9 @@ container2 -- --
te.context.Output = &out te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "windows") err := ContainerStatsWrite(te.context, stats, "windows")
if err != nil { if err != nil {
assert.Error(t, err, te.expected) assert.EqualError(t, err, te.expected)
} else { } 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 { for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{}, "windows") ContainerStatsWrite(context.context, []StatsEntry{}, "windows")
assert.Equal(t, out.String(), context.expected) assert.Equal(t, context.expected, out.String())
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestTaskContextWrite(t *testing.T) { func TestTaskContextWrite(t *testing.T) {
@ -76,9 +76,9 @@ foobar_bar foo2
testcase.context.Output = out testcase.context.Output = out
err := TaskWrite(testcase.context, tasks, names, nodes) err := TaskWrite(testcase.context, tasks, names, nodes)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, tasks[i].ID) assert.Equal(t, tasks[i].ID, s)
} }
} }

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestVolumeContext(t *testing.T) { func TestVolumeContext(t *testing.T) {
@ -131,9 +131,9 @@ foobar_bar
testcase.context.Output = out testcase.context.Output = out
err := VolumeWrite(testcase.context, volumes) err := VolumeWrite(testcase.context, volumes)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.EqualError(t, err, testcase.expected)
} else { } 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 { if err := json.Unmarshal([]byte(line), &m); err != nil {
t.Fatal(err) 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 { if err := json.Unmarshal([]byte(line), &s); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, s, volumes[i].Name) assert.Equal(t, volumes[i].Name, s)
} }
} }

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "github.com/docker/docker/cli/internal/test/builders"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -21,7 +21,7 @@ func TestResolveError(t *testing.T) {
idResolver := New(cli, false) idResolver := New(cli, false)
_, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID") _, err := idResolver.Resolve(context.Background(), struct{}{}, "nodeID")
assert.Error(t, err, "unsupported type") assert.EqualError(t, err, "unsupported type")
} }
func TestResolveWithNoResolveOption(t *testing.T) { func TestResolveWithNoResolveOption(t *testing.T) {
@ -40,9 +40,9 @@ func TestResolveWithNoResolveOption(t *testing.T) {
idResolver := New(cli, true) idResolver := New(cli, true)
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID") id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID")
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, id, "nodeID") assert.Equal(t, "nodeID", id)
assert.Equal(t, resolved, false) assert.False(t, resolved)
} }
func TestResolveWithCache(t *testing.T) { func TestResolveWithCache(t *testing.T) {
@ -59,11 +59,11 @@ func TestResolveWithCache(t *testing.T) {
ctx := context.Background() ctx := context.Background()
for i := 0; i < 2; i++ { for i := 0; i < 2; i++ {
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID") id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, id, "node-foo") assert.Equal(t, "node-foo", id)
} }
assert.Equal(t, inspectCounter, 1) assert.Equal(t, 1, inspectCounter)
} }
func TestResolveNode(t *testing.T) { func TestResolveNode(t *testing.T) {
@ -103,8 +103,8 @@ func TestResolveNode(t *testing.T) {
idResolver := New(cli, false) idResolver := New(cli, false)
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID) id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, id, tc.expectedID) assert.Equal(t, tc.expectedID, id)
} }
} }
@ -138,7 +138,7 @@ func TestResolveService(t *testing.T) {
idResolver := New(cli, false) idResolver := New(cli, false)
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID) id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, id, tc.expectedID) assert.Equal(t, tc.expectedID, id)
} }
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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) { func TestNodeDemoteErrors(t *testing.T) {
@ -47,7 +48,7 @@ func TestNodeDemoteErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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)) }, buf))
cmd.SetArgs([]string{"nodeID"}) cmd.SetArgs([]string{"nodeID"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }
func TestNodeDemoteMultipleNode(t *testing.T) { func TestNodeDemoteMultipleNode(t *testing.T) {
@ -84,5 +85,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
}, },
}, buf)) }, buf))
cmd.SetArgs([]string{"nodeID1", "nodeID2"}) cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }

View File

@ -12,8 +12,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestNodeInspectErrors(t *testing.T) { func TestNodeInspectErrors(t *testing.T) {
@ -77,7 +78,7 @@ func TestNodeInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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)) }, buf))
cmd.SetArgs([]string{"nodeID"}) cmd.SetArgs([]string{"nodeID"})
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name)) 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))
} }
} }

View File

@ -12,7 +12,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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) { func TestNodeListErrorOnAPIFailure(t *testing.T) {
@ -50,7 +50,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.SetOutput(ioutil.Discard) 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) }, buf)
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newListCommand(cli) 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(), `nodeID1 * nodeHostname1 Ready Active Leader`)
assert.Contains(t, buf.String(), `nodeID2 nodeHostname2 Ready Active Reachable`) assert.Contains(t, buf.String(), `nodeID2 nodeHostname2 Ready Active Reachable`)
assert.Contains(t, buf.String(), `nodeID3 nodeHostname3 Ready Active`) assert.Contains(t, buf.String(), `nodeID3 nodeHostname3 Ready Active`)
@ -92,7 +92,7 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Contains(t, buf.String(), "nodeID") assert.Contains(t, buf.String(), "nodeID")
} }
@ -102,7 +102,7 @@ func TestNodeListContainsHostname(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{}, buf) cli := test.NewFakeCli(&fakeClient{}, buf)
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Contains(t, buf.String(), "HOSTNAME") assert.Contains(t, buf.String(), "HOSTNAME")
} }
@ -128,7 +128,7 @@ func TestNodeListDefaultFormat(t *testing.T) {
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}", NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
}) })
cmd := newListCommand(cli) 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(), `nodeID1: nodeHostname1 Ready/Leader`)
assert.Contains(t, buf.String(), `nodeID2: nodeHostname2 Ready/Reachable`) assert.Contains(t, buf.String(), `nodeID2: nodeHostname2 Ready/Reachable`)
assert.Contains(t, buf.String(), `nodeID3: nodeHostname3 Ready`) assert.Contains(t, buf.String(), `nodeID3: nodeHostname3 Ready`)
@ -156,7 +156,7 @@ func TestNodeListFormat(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}") 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(), `nodeHostname1: Leader`)
assert.Contains(t, buf.String(), `nodeHostname2: Reachable`) assert.Contains(t, buf.String(), `nodeHostname2: Reachable`)
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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) { func TestNodePromoteErrors(t *testing.T) {
@ -47,7 +48,7 @@ func TestNodePromoteErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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)) }, buf))
cmd.SetArgs([]string{"nodeID"}) cmd.SetArgs([]string{"nodeID"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }
func TestNodePromoteMultipleNode(t *testing.T) { func TestNodePromoteMultipleNode(t *testing.T) {
@ -84,5 +85,5 @@ func TestNodePromoteMultipleNode(t *testing.T) {
}, },
}, buf)) }, buf))
cmd.SetArgs([]string{"nodeID1", "nodeID2"}) cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }

View File

@ -13,8 +13,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestNodePsErrors(t *testing.T) { func TestNodePsErrors(t *testing.T) {
@ -62,7 +63,7 @@ func TestNodePsErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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 { for key, value := range tc.flags {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("node-ps.%s.golden", tc.name)) 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))
} }
} }

View File

@ -6,8 +6,9 @@ import (
"testing" "testing"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNodeRemoveErrors(t *testing.T) { func TestNodeRemoveErrors(t *testing.T) {
@ -35,7 +36,7 @@ func TestNodeRemoveErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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) buf := new(bytes.Buffer)
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf)) cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
cmd.SetArgs([]string{"nodeID1", "nodeID2"}) cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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) { func TestNodeUpdateErrors(t *testing.T) {
@ -67,7 +68,7 @@ func TestNodeUpdateErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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 { for key, value := range tc.flags {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }
} }

View File

@ -10,9 +10,10 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/internal/test" "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/docker/docker/pkg/testutil/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
const secretDataFile = "secret-create-with-name.golden" const secretDataFile = "secret-create-with-name.golden"
@ -47,7 +48,7 @@ func TestSecretCreateErrors(t *testing.T) {
) )
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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 := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)}) cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
expected := golden.Get(t, actual, secretDataFile) expected := golden.Get(t, actual, secretDataFile)
assert.Equal(t, string(actual), string(expected)) assert.Equal(t, expected, actual)
assert.Equal(t, strings.TrimSpace(buf.String()), "ID-"+name) assert.Equal(t, "ID-"+name, strings.TrimSpace(buf.String()))
} }
func TestSecretCreateWithLabels(t *testing.T) { func TestSecretCreateWithLabels(t *testing.T) {
@ -105,8 +106,8 @@ func TestSecretCreateWithLabels(t *testing.T) {
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)}) cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
cmd.Flags().Set("label", "lbl1=Label-foo") cmd.Flags().Set("label", "lbl1=Label-foo")
cmd.Flags().Set("label", "lbl2=Label-bar") cmd.Flags().Set("label", "lbl2=Label-bar")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), "ID-"+name) assert.Equal(t, "ID-"+name, strings.TrimSpace(buf.String()))
} }
func compareMap(actual map[string]string, expected map[string]string) bool { func compareMap(actual map[string]string, expected map[string]string) bool {

View File

@ -11,8 +11,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestSecretInspectErrors(t *testing.T) { func TestSecretInspectErrors(t *testing.T) {
@ -62,7 +63,7 @@ func TestSecretInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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), }, buf),
) )
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name)) 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.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format) cmd.Flags().Set("format", tc.format)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name)) 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))
} }
} }

View File

@ -13,8 +13,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestSecretListErrors(t *testing.T) { func TestSecretListErrors(t *testing.T) {
@ -43,7 +44,7 @@ func TestSecretListErrors(t *testing.T) {
) )
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
cmd.SetOutput(buf) cmd.SetOutput(buf)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "secret-list.golden") 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) { func TestSecretListWithQuietOption(t *testing.T) {
@ -91,10 +92,10 @@ func TestSecretListWithQuietOption(t *testing.T) {
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "secret-list-with-quiet-option.golden") 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) { func TestSecretListWithConfigFormat(t *testing.T) {
@ -113,10 +114,10 @@ func TestSecretListWithConfigFormat(t *testing.T) {
SecretFormat: "{{ .Name }} {{ .Labels }}", SecretFormat: "{{ .Name }} {{ .Labels }}",
}) })
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "secret-list-with-config-format.golden") 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) { func TestSecretListWithFormat(t *testing.T) {
@ -133,18 +134,18 @@ func TestSecretListWithFormat(t *testing.T) {
}, buf) }, buf)
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "secret-list-with-format.golden") 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) { func TestSecretListWithFilter(t *testing.T) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) { secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
assert.Equal(t, options.Filters.Get("name")[0], "foo") assert.Equal(t, "foo", options.Filters.Get("name")[0], "foo")
assert.Equal(t, options.Filters.Get("label")[0], "lbl1=Label-bar") assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])
return []swarm.Secret{ return []swarm.Secret{
*Secret(SecretID("ID-foo"), *Secret(SecretID("ID-foo"),
SecretName("foo"), SecretName("foo"),
@ -165,8 +166,8 @@ func TestSecretListWithFilter(t *testing.T) {
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
cmd.Flags().Set("filter", "name=foo") cmd.Flags().Set("filter", "name=foo")
cmd.Flags().Set("filter", "label=lbl1=Label-bar") cmd.Flags().Set("filter", "label=lbl1=Label-bar")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "secret-list-with-filter.golden") 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))
} }

View File

@ -7,8 +7,9 @@ import (
"testing" "testing"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSecretRemoveErrors(t *testing.T) { func TestSecretRemoveErrors(t *testing.T) {
@ -38,7 +39,7 @@ func TestSecretRemoveErrors(t *testing.T) {
) )
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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) }, buf)
cmd := newSecretRemoveCommand(cli) cmd := newSecretRemoveCommand(cli)
cmd.SetArgs(names) cmd.SetArgs(names)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.EqualStringSlice(t, strings.Split(strings.TrimSpace(buf.String()), "\n"), names) assert.Equal(t, names, strings.Split(strings.TrimSpace(buf.String()), "\n"))
assert.EqualStringSlice(t, removedSecrets, names) assert.Equal(t, names, removedSecrets)
} }
func TestSecretRemoveContinueAfterError(t *testing.T) { func TestSecretRemoveContinueAfterError(t *testing.T) {
@ -76,6 +77,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
cmd := newSecretRemoveCommand(cli) cmd := newSecretRemoveCommand(cli)
cmd.SetArgs(names) cmd.SetArgs(names)
assert.Error(t, cmd.Execute(), "error removing secret: foo") assert.EqualError(t, cmd.Execute(), "error removing secret: foo")
assert.EqualStringSlice(t, removedSecrets, names) assert.Equal(t, names, removedSecrets)
} }

View File

@ -10,7 +10,7 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/command/formatter" "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 { 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.Fatal(err)
} }
t.Logf("m2=%+v", m2) t.Logf("m2=%+v", m2)
assert.DeepEqual(t, m2, m1) assert.Equal(t, m1, m2)
} }

View File

@ -1,71 +1,70 @@
package service package service
import ( import (
"reflect"
"testing" "testing"
"time" "time"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestMemBytesString(t *testing.T) { func TestMemBytesString(t *testing.T) {
var mem opts.MemBytes = 1048576 var mem opts.MemBytes = 1048576
assert.Equal(t, mem.String(), "1MiB") assert.Equal(t, "1MiB", mem.String())
} }
func TestMemBytesSetAndValue(t *testing.T) { func TestMemBytesSetAndValue(t *testing.T) {
var mem opts.MemBytes var mem opts.MemBytes
assert.NilError(t, mem.Set("5kb")) assert.NoError(t, mem.Set("5kb"))
assert.Equal(t, mem.Value(), int64(5120)) assert.Equal(t, int64(5120), mem.Value())
} }
func TestNanoCPUsString(t *testing.T) { func TestNanoCPUsString(t *testing.T) {
var cpus opts.NanoCPUs = 6100000000 var cpus opts.NanoCPUs = 6100000000
assert.Equal(t, cpus.String(), "6.100") assert.Equal(t, "6.100", cpus.String())
} }
func TestNanoCPUsSetAndValue(t *testing.T) { func TestNanoCPUsSetAndValue(t *testing.T) {
var cpus opts.NanoCPUs var cpus opts.NanoCPUs
assert.NilError(t, cpus.Set("0.35")) assert.NoError(t, cpus.Set("0.35"))
assert.Equal(t, cpus.Value(), int64(350000000)) assert.Equal(t, int64(350000000), cpus.Value())
} }
func TestDurationOptString(t *testing.T) { func TestDurationOptString(t *testing.T) {
dur := time.Duration(300 * 10e8) dur := time.Duration(300 * 10e8)
duration := DurationOpt{value: &dur} duration := DurationOpt{value: &dur}
assert.Equal(t, duration.String(), "5m0s") assert.Equal(t, "5m0s", duration.String())
} }
func TestDurationOptSetAndValue(t *testing.T) { func TestDurationOptSetAndValue(t *testing.T) {
var duration DurationOpt var duration DurationOpt
assert.NilError(t, duration.Set("300s")) assert.NoError(t, duration.Set("300s"))
assert.Equal(t, *duration.Value(), time.Duration(300*10e8)) assert.Equal(t, time.Duration(300*10e8), *duration.Value())
assert.NilError(t, duration.Set("-300s")) assert.NoError(t, duration.Set("-300s"))
assert.Equal(t, *duration.Value(), time.Duration(-300*10e8)) assert.Equal(t, time.Duration(-300*10e8), *duration.Value())
} }
func TestPositiveDurationOptSetAndValue(t *testing.T) { func TestPositiveDurationOptSetAndValue(t *testing.T) {
var duration PositiveDurationOpt var duration PositiveDurationOpt
assert.NilError(t, duration.Set("300s")) assert.NoError(t, duration.Set("300s"))
assert.Equal(t, *duration.Value(), time.Duration(300*10e8)) assert.Equal(t, time.Duration(300*10e8), *duration.Value())
assert.Error(t, duration.Set("-300s"), "cannot be negative") assert.EqualError(t, duration.Set("-300s"), "duration cannot be negative")
} }
func TestUint64OptString(t *testing.T) { func TestUint64OptString(t *testing.T) {
value := uint64(2345678) value := uint64(2345678)
opt := Uint64Opt{value: &value} opt := Uint64Opt{value: &value}
assert.Equal(t, opt.String(), "2345678") assert.Equal(t, "2345678", opt.String())
opt = Uint64Opt{} opt = Uint64Opt{}
assert.Equal(t, opt.String(), "") assert.Equal(t, "", opt.String())
} }
func TestUint64OptSetAndValue(t *testing.T) { func TestUint64OptSetAndValue(t *testing.T) {
var opt Uint64Opt var opt Uint64Opt
assert.NilError(t, opt.Set("14445")) assert.NoError(t, opt.Set("14445"))
assert.Equal(t, *opt.Value(), uint64(14445)) assert.Equal(t, uint64(14445), *opt.Value())
} }
func TestHealthCheckOptionsToHealthConfig(t *testing.T) { func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
@ -78,14 +77,14 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
retries: 10, retries: 10,
} }
config, err := opt.toHealthConfig() config, err := opt.toHealthConfig()
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{ assert.Equal(t, &container.HealthConfig{
Test: []string{"CMD-SHELL", "curl"}, Test: []string{"CMD-SHELL", "curl"},
Interval: time.Second, Interval: time.Second,
Timeout: time.Second, Timeout: time.Second,
StartPeriod: time.Second, StartPeriod: time.Second,
Retries: 10, Retries: 10,
}), true) }, config)
} }
func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) { func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
@ -93,10 +92,10 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
noHealthcheck: true, noHealthcheck: true,
} }
config, err := opt.toHealthConfig() config, err := opt.toHealthConfig()
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, reflect.DeepEqual(config, &container.HealthConfig{ assert.Equal(t, &container.HealthConfig{
Test: []string{"NONE"}, Test: []string{"NONE"},
}), true) }, config)
} }
func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) { func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
@ -105,5 +104,5 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
noHealthcheck: true, noHealthcheck: true,
} }
_, err := opt.toHealthConfig() _, err := opt.toHealthConfig()
assert.Error(t, err, "--no-healthcheck conflicts with --health-* options") assert.EqualError(t, err, "--no-healthcheck conflicts with --health-* options")
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
mounttypes "github.com/docker/docker/api/types/mount" mounttypes "github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/swarm" "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" "golang.org/x/net/context"
) )
@ -23,7 +24,7 @@ func TestUpdateServiceArgs(t *testing.T) {
cspec.Args = []string{"old", "args"} cspec.Args = []string{"old", "args"}
updateService(nil, nil, flags, spec) 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) { func TestUpdateLabels(t *testing.T) {
@ -37,9 +38,9 @@ func TestUpdateLabels(t *testing.T) {
} }
updateLabels(flags, &labels) updateLabels(flags, &labels)
assert.Equal(t, len(labels), 2) assert.Len(t, labels, 2)
assert.Equal(t, labels["tokeep"], "value") assert.Equal(t, "value", labels["tokeep"])
assert.Equal(t, labels["toadd"], "newlabel") assert.Equal(t, "newlabel", labels["toadd"])
} }
func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) { func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
@ -48,7 +49,7 @@ func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
labels := map[string]string{"foo": "theoldlabel"} labels := map[string]string{"foo": "theoldlabel"}
updateLabels(flags, &labels) updateLabels(flags, &labels)
assert.Equal(t, len(labels), 1) assert.Len(t, labels, 1)
} }
func TestUpdatePlacementConstraints(t *testing.T) { func TestUpdatePlacementConstraints(t *testing.T) {
@ -61,9 +62,9 @@ func TestUpdatePlacementConstraints(t *testing.T) {
} }
updatePlacementConstraints(flags, placement) updatePlacementConstraints(flags, placement)
assert.Equal(t, len(placement.Constraints), 2) require.Len(t, placement.Constraints, 2)
assert.Equal(t, placement.Constraints[0], "container=tokeep") assert.Equal(t, "container=tokeep", placement.Constraints[0])
assert.Equal(t, placement.Constraints[1], "node=toadd") assert.Equal(t, "node=toadd", placement.Constraints[1])
} }
func TestUpdatePlacementPrefs(t *testing.T) { func TestUpdatePlacementPrefs(t *testing.T) {
@ -87,9 +88,9 @@ func TestUpdatePlacementPrefs(t *testing.T) {
} }
updatePlacementPreferences(flags, placement) updatePlacementPreferences(flags, placement)
assert.Equal(t, len(placement.Preferences), 2) require.Len(t, placement.Preferences, 2)
assert.Equal(t, placement.Preferences[0].Spread.SpreadDescriptor, "node.labels.row") assert.Equal(t, "node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor)
assert.Equal(t, placement.Preferences[1].Spread.SpreadDescriptor, "node.labels.dc") assert.Equal(t, "node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor)
} }
func TestUpdateEnvironment(t *testing.T) { func TestUpdateEnvironment(t *testing.T) {
@ -100,11 +101,11 @@ func TestUpdateEnvironment(t *testing.T) {
envs := []string{"toremove=theenvtoremove", "tokeep=value"} envs := []string{"toremove=theenvtoremove", "tokeep=value"}
updateEnvironment(flags, &envs) updateEnvironment(flags, &envs)
assert.Equal(t, len(envs), 2) require.Len(t, envs, 2)
// Order has been removed in updateEnvironment (map) // Order has been removed in updateEnvironment (map)
sort.Strings(envs) sort.Strings(envs)
assert.Equal(t, envs[0], "toadd=newenv") assert.Equal(t, "toadd=newenv", envs[0])
assert.Equal(t, envs[1], "tokeep=value") assert.Equal(t, "tokeep=value", envs[1])
} }
func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) { func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
@ -116,7 +117,7 @@ func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
envs := []string{"foo=value"} envs := []string{"foo=value"}
updateEnvironment(flags, &envs) updateEnvironment(flags, &envs)
assert.Equal(t, len(envs), 0) assert.Len(t, envs, 0)
} }
func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) { func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
@ -127,8 +128,8 @@ func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
envs := []string{"A=c"} envs := []string{"A=c"}
updateEnvironment(flags, &envs) updateEnvironment(flags, &envs)
assert.Equal(t, len(envs), 1) require.Len(t, envs, 1)
assert.Equal(t, envs[0], "A=b") assert.Equal(t, "A=b", envs[0])
} }
func TestUpdateGroups(t *testing.T) { func TestUpdateGroups(t *testing.T) {
@ -142,10 +143,10 @@ func TestUpdateGroups(t *testing.T) {
groups := []string{"bar", "root"} groups := []string{"bar", "root"}
updateGroups(flags, &groups) updateGroups(flags, &groups)
assert.Equal(t, len(groups), 3) require.Len(t, groups, 3)
assert.Equal(t, groups[0], "bar") assert.Equal(t, "bar", groups[0])
assert.Equal(t, groups[1], "foo") assert.Equal(t, "foo", groups[1])
assert.Equal(t, groups[2], "wheel") assert.Equal(t, "wheel", groups[2])
} }
func TestUpdateDNSConfig(t *testing.T) { func TestUpdateDNSConfig(t *testing.T) {
@ -160,7 +161,7 @@ func TestUpdateDNSConfig(t *testing.T) {
// IPv6 // IPv6
flags.Set("dns-add", "2001:db8:abc8::1") flags.Set("dns-add", "2001:db8:abc8::1")
// Invalid dns record // 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 // domains with duplicates
flags.Set("dns-search-add", "example.com") 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-add", "example.org")
flags.Set("dns-search-rm", "example.org") flags.Set("dns-search-rm", "example.org")
// Invalid dns search domain // 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-add", "ndots:9")
flags.Set("dns-option-rm", "timeout:3") flags.Set("dns-option-rm", "timeout:3")
@ -181,16 +182,16 @@ func TestUpdateDNSConfig(t *testing.T) {
updateDNSConfig(flags, &config) updateDNSConfig(flags, &config)
assert.Equal(t, len(config.Nameservers), 3) require.Len(t, config.Nameservers, 3)
assert.Equal(t, config.Nameservers[0], "1.1.1.1") assert.Equal(t, "1.1.1.1", config.Nameservers[0])
assert.Equal(t, config.Nameservers[1], "2001:db8:abc8::1") assert.Equal(t, "2001:db8:abc8::1", config.Nameservers[1])
assert.Equal(t, config.Nameservers[2], "5.5.5.5") assert.Equal(t, "5.5.5.5", config.Nameservers[2])
assert.Equal(t, len(config.Search), 2) require.Len(t, config.Search, 2)
assert.Equal(t, config.Search[0], "example.com") assert.Equal(t, "example.com", config.Search[0])
assert.Equal(t, config.Search[1], "localdomain") 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") assert.Equal(t, config.Options[0], "ndots:9")
} }
@ -205,10 +206,9 @@ func TestUpdateMounts(t *testing.T) {
} }
updateMounts(flags, &mounts) updateMounts(flags, &mounts)
assert.Equal(t, len(mounts), 2) require.Len(t, mounts, 2)
assert.Equal(t, mounts[0].Target, "/toadd") assert.Equal(t, "/toadd", mounts[0].Target)
assert.Equal(t, mounts[1].Target, "/tokeep") assert.Equal(t, "/tokeep", mounts[1].Target)
} }
func TestUpdateMountsWithDuplicateMounts(t *testing.T) { func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
@ -222,10 +222,10 @@ func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
} }
updateMounts(flags, &mounts) updateMounts(flags, &mounts)
assert.Equal(t, len(mounts), 3) require.Len(t, mounts, 3)
assert.Equal(t, mounts[0].Target, "/tokeep1") assert.Equal(t, "/tokeep1", mounts[0].Target)
assert.Equal(t, mounts[1].Target, "/tokeep2") assert.Equal(t, "/tokeep2", mounts[1].Target)
assert.Equal(t, mounts[2].Target, "/toadd") assert.Equal(t, "/toadd", mounts[2].Target)
} }
func TestUpdatePorts(t *testing.T) { func TestUpdatePorts(t *testing.T) {
@ -239,13 +239,13 @@ func TestUpdatePorts(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.Equal(t, err, nil) assert.NoError(t, err)
assert.Equal(t, len(portConfigs), 2) require.Len(t, portConfigs, 2)
// Do a sort to have the order (might have changed by map) // Do a sort to have the order (might have changed by map)
targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)} targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)}
sort.Ints(targetPorts) sort.Ints(targetPorts)
assert.Equal(t, targetPorts[0], 555) assert.Equal(t, 555, targetPorts[0])
assert.Equal(t, targetPorts[1], 1000) assert.Equal(t, 1000, targetPorts[1])
} }
func TestUpdatePortsDuplicate(t *testing.T) { func TestUpdatePortsDuplicate(t *testing.T) {
@ -263,9 +263,9 @@ func TestUpdatePortsDuplicate(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.Equal(t, err, nil) assert.NoError(t, err)
assert.Equal(t, len(portConfigs), 1) require.Len(t, portConfigs, 1)
assert.Equal(t, portConfigs[0].TargetPort, uint32(80)) assert.Equal(t, uint32(80), portConfigs[0].TargetPort)
} }
func TestUpdateHealthcheckTable(t *testing.T) { func TestUpdateHealthcheckTable(t *testing.T) {
@ -339,9 +339,9 @@ func TestUpdateHealthcheckTable(t *testing.T) {
} }
err := updateHealthcheck(flags, cspec) err := updateHealthcheck(flags, cspec)
if c.err != "" { if c.err != "" {
assert.Error(t, err, c.err) assert.EqualError(t, err, c.err)
} else { } else {
assert.NilError(t, err) assert.NoError(t, err)
if !reflect.DeepEqual(cspec.Healthcheck, c.expected) { 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) 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 // just hostname should work as well
flags.Set("host-rm", "example.net") flags.Set("host-rm", "example.net")
// bad format error // 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"} hosts := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 example.net"}
updateHosts(flags, &hosts) updateHosts(flags, &hosts)
assert.Equal(t, len(hosts), 3) require.Len(t, hosts, 3)
assert.Equal(t, hosts[0], "1.2.3.4 example.com") assert.Equal(t, "1.2.3.4 example.com", hosts[0])
assert.Equal(t, hosts[1], "2001:db8:abc8::1 ipv6.net") assert.Equal(t, "2001:db8:abc8::1 ipv6.net", hosts[1])
assert.Equal(t, hosts[2], "4.3.2.1 example.org") assert.Equal(t, "4.3.2.1 example.org", hosts[2])
} }
func TestUpdatePortsRmWithProtocol(t *testing.T) { func TestUpdatePortsRmWithProtocol(t *testing.T) {
@ -387,10 +387,10 @@ func TestUpdatePortsRmWithProtocol(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.Equal(t, err, nil) assert.NoError(t, err)
assert.Equal(t, len(portConfigs), 2) require.Len(t, portConfigs, 2)
assert.Equal(t, portConfigs[0].TargetPort, uint32(81)) assert.Equal(t, uint32(81), portConfigs[0].TargetPort)
assert.Equal(t, portConfigs[1].TargetPort, uint32(82)) assert.Equal(t, uint32(82), portConfigs[1].TargetPort)
} }
type secretAPIClientMock struct { type secretAPIClientMock struct {
@ -444,11 +444,11 @@ func TestUpdateSecretUpdateInPlace(t *testing.T) {
updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets) updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets)
assert.Equal(t, err, nil) assert.NoError(t, err)
assert.Equal(t, len(updatedSecrets), 1) require.Len(t, updatedSecrets, 1)
assert.Equal(t, updatedSecrets[0].SecretID, "tn9qiblgnuuut11eufquw5dev") assert.Equal(t, "tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID)
assert.Equal(t, updatedSecrets[0].SecretName, "foo") assert.Equal(t, "foo", updatedSecrets[0].SecretName)
assert.Equal(t, updatedSecrets[0].File.Name, "foo2") assert.Equal(t, "foo2", updatedSecrets[0].File.Name)
} }
func TestUpdateReadOnly(t *testing.T) { func TestUpdateReadOnly(t *testing.T) {
@ -459,18 +459,18 @@ func TestUpdateReadOnly(t *testing.T) {
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
flags.Set("read-only", "true") flags.Set("read-only", "true")
updateService(nil, nil, flags, spec) updateService(nil, nil, flags, spec)
assert.Equal(t, cspec.ReadOnly, true) assert.True(t, cspec.ReadOnly)
// Update without --read-only, no change // Update without --read-only, no change
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
updateService(nil, nil, flags, spec) updateService(nil, nil, flags, spec)
assert.Equal(t, cspec.ReadOnly, true) assert.True(t, cspec.ReadOnly)
// Update with --read-only=false, changed to false // Update with --read-only=false, changed to false
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
flags.Set("read-only", "false") flags.Set("read-only", "false")
updateService(nil, nil, flags, spec) updateService(nil, nil, flags, spec)
assert.Equal(t, cspec.ReadOnly, false) assert.False(t, cspec.ReadOnly)
} }
func TestUpdateStopSignal(t *testing.T) { func TestUpdateStopSignal(t *testing.T) {
@ -481,16 +481,16 @@ func TestUpdateStopSignal(t *testing.T) {
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
flags.Set("stop-signal", "SIGUSR1") flags.Set("stop-signal", "SIGUSR1")
updateService(nil, nil, flags, spec) updateService(nil, nil, flags, spec)
assert.Equal(t, cspec.StopSignal, "SIGUSR1") assert.Equal(t, "SIGUSR1", cspec.StopSignal)
// Update without --stop-signal, no change // Update without --stop-signal, no change
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
updateService(nil, nil, flags, spec) updateService(nil, nil, flags, spec)
assert.Equal(t, cspec.StopSignal, "SIGUSR1") assert.Equal(t, "SIGUSR1", cspec.StopSignal)
// Update with --stop-signal=SIGWINCH // Update with --stop-signal=SIGWINCH
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
flags.Set("stop-signal", "SIGWINCH") flags.Set("stop-signal", "SIGWINCH")
updateService(nil, nil, flags, spec) updateService(nil, nil, flags, spec)
assert.Equal(t, cspec.StopSignal, "SIGWINCH") assert.Equal(t, "SIGWINCH", cspec.StopSignal)
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/docker/docker/cli/compose/convert" "github.com/docker/docker/cli/compose/convert"
"github.com/docker/docker/cli/internal/test" "github.com/docker/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -23,5 +23,5 @@ func TestPruneServices(t *testing.T) {
pruneServices(ctx, dockerCli, namespace, services) 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)
} }

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/docker/docker/cli/internal/test" "github.com/docker/docker/cli/internal/test"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestRemoveStack(t *testing.T) { func TestRemoveStack(t *testing.T) {
@ -17,20 +17,20 @@ func TestRemoveStack(t *testing.T) {
objectName("bar", "service1"), objectName("bar", "service1"),
objectName("bar", "service2"), objectName("bar", "service2"),
} }
allServicesIDs := buildObjectIDs(allServices) allServiceIDs := buildObjectIDs(allServices)
allNetworks := []string{ allNetworks := []string{
objectName("foo", "network1"), objectName("foo", "network1"),
objectName("bar", "network1"), objectName("bar", "network1"),
} }
allNetworksIDs := buildObjectIDs(allNetworks) allNetworkIDs := buildObjectIDs(allNetworks)
allSecrets := []string{ allSecrets := []string{
objectName("foo", "secret1"), objectName("foo", "secret1"),
objectName("foo", "secret2"), objectName("foo", "secret2"),
objectName("bar", "secret1"), objectName("bar", "secret1"),
} }
allSecretsIDs := buildObjectIDs(allSecrets) allSecretIDs := buildObjectIDs(allSecrets)
cli := &fakeClient{ cli := &fakeClient{
services: allServices, services: allServices,
@ -40,22 +40,22 @@ func TestRemoveStack(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{})) cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.DeepEqual(t, cli.removedServices, allServicesIDs) assert.Equal(t, allServiceIDs, cli.removedServices)
assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs) assert.Equal(t, allNetworkIDs, cli.removedNetworks)
assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs) assert.Equal(t, allSecretIDs, cli.removedSecrets)
} }
func TestSkipEmptyStack(t *testing.T) { func TestSkipEmptyStack(t *testing.T) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
allServices := []string{objectName("bar", "service1"), objectName("bar", "service2")} allServices := []string{objectName("bar", "service1"), objectName("bar", "service2")}
allServicesIDs := buildObjectIDs(allServices) allServiceIDs := buildObjectIDs(allServices)
allNetworks := []string{objectName("bar", "network1")} allNetworks := []string{objectName("bar", "network1")}
allNetworksIDs := buildObjectIDs(allNetworks) allNetworkIDs := buildObjectIDs(allNetworks)
allSecrets := []string{objectName("bar", "secret1")} allSecrets := []string{objectName("bar", "secret1")}
allSecretsIDs := buildObjectIDs(allSecrets) allSecretIDs := buildObjectIDs(allSecrets)
cli := &fakeClient{ cli := &fakeClient{
services: allServices, services: allServices,
@ -65,22 +65,22 @@ func TestSkipEmptyStack(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(cli, buf)) cmd := newRemoveCommand(test.NewFakeCli(cli, buf))
cmd.SetArgs([]string{"foo", "bar"}) 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.Contains(t, buf.String(), "Nothing found in stack: foo")
assert.DeepEqual(t, cli.removedServices, allServicesIDs) assert.Equal(t, allServiceIDs, cli.removedServices)
assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs) assert.Equal(t, allNetworkIDs, cli.removedNetworks)
assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs) assert.Equal(t, allSecretIDs, cli.removedSecrets)
} }
func TestContinueAfterError(t *testing.T) { func TestContinueAfterError(t *testing.T) {
allServices := []string{objectName("foo", "service1"), objectName("bar", "service1")} allServices := []string{objectName("foo", "service1"), objectName("bar", "service1")}
allServicesIDs := buildObjectIDs(allServices) allServiceIDs := buildObjectIDs(allServices)
allNetworks := []string{objectName("foo", "network1"), objectName("bar", "network1")} allNetworks := []string{objectName("foo", "network1"), objectName("bar", "network1")}
allNetworksIDs := buildObjectIDs(allNetworks) allNetworkIDs := buildObjectIDs(allNetworks)
allSecrets := []string{objectName("foo", "secret1"), objectName("bar", "secret1")} allSecrets := []string{objectName("foo", "secret1"), objectName("bar", "secret1")}
allSecretsIDs := buildObjectIDs(allSecrets) allSecretIDs := buildObjectIDs(allSecrets)
removedServices := []string{} removedServices := []string{}
cli := &fakeClient{ cli := &fakeClient{
@ -100,8 +100,8 @@ func TestContinueAfterError(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{})) cmd := newRemoveCommand(test.NewFakeCli(cli, &bytes.Buffer{}))
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.Error(t, cmd.Execute(), "Failed to remove some resources from stack: foo") assert.EqualError(t, cmd.Execute(), "Failed to remove some resources from stack: foo")
assert.DeepEqual(t, removedServices, allServicesIDs) assert.Equal(t, allServiceIDs, removedServices)
assert.DeepEqual(t, cli.removedNetworks, allNetworksIDs) assert.Equal(t, allNetworkIDs, cli.removedNetworks)
assert.DeepEqual(t, cli.removedSecrets, allSecretsIDs) assert.Equal(t, allSecretIDs, cli.removedSecrets)
} }

View File

@ -9,9 +9,10 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/internal/test" "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/docker/docker/pkg/testutil/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSwarmInitErrorOnAPIFailure(t *testing.T) { func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
@ -76,7 +77,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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 { for key, value := range tc.flags {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("init-%s.golden", tc.name)) 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))
} }
} }

View File

@ -9,8 +9,9 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSwarmJoinErrors(t *testing.T) { func TestSwarmJoinErrors(t *testing.T) {
@ -56,7 +57,7 @@ func TestSwarmJoinErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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, infoFunc: tc.infoFunc,
}, buf)) }, buf))
cmd.SetArgs([]string{"remote"}) cmd.SetArgs([]string{"remote"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected) assert.Equal(t, strings.TrimSpace(buf.String()), tc.expected)
} }
} }

View File

@ -12,8 +12,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestSwarmJoinTokenErrors(t *testing.T) { func TestSwarmJoinTokenErrors(t *testing.T) {
@ -102,7 +103,7 @@ func TestSwarmJoinTokenErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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 { for key, value := range tc.flags {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("jointoken-%s.golden", tc.name)) 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))
} }
} }

View File

@ -7,8 +7,9 @@ import (
"testing" "testing"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSwarmLeaveErrors(t *testing.T) { func TestSwarmLeaveErrors(t *testing.T) {
@ -39,7 +40,7 @@ func TestSwarmLeaveErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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) buf := new(bytes.Buffer)
cmd := newLeaveCommand( cmd := newLeaveCommand(
test.NewFakeCli(&fakeClient{}, buf)) test.NewFakeCli(&fakeClient{}, buf))
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), "Node left the swarm.") assert.Equal(t, "Node left the swarm.", strings.TrimSpace(buf.String()))
} }

View File

@ -3,37 +3,37 @@ package swarm
import ( import (
"testing" "testing"
"github.com/docker/docker/pkg/testutil/assert" "github.com/stretchr/testify/assert"
) )
func TestNodeAddrOptionSetHostAndPort(t *testing.T) { func TestNodeAddrOptionSetHostAndPort(t *testing.T) {
opt := NewNodeAddrOption("old:123") opt := NewNodeAddrOption("old:123")
addr := "newhost:5555" addr := "newhost:5555"
assert.NilError(t, opt.Set(addr)) assert.NoError(t, opt.Set(addr))
assert.Equal(t, opt.Value(), addr) assert.Equal(t, addr, opt.Value())
} }
func TestNodeAddrOptionSetHostOnly(t *testing.T) { func TestNodeAddrOptionSetHostOnly(t *testing.T) {
opt := NewListenAddrOption() opt := NewListenAddrOption()
assert.NilError(t, opt.Set("newhost")) assert.NoError(t, opt.Set("newhost"))
assert.Equal(t, opt.Value(), "newhost:2377") assert.Equal(t, "newhost:2377", opt.Value())
} }
func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) { func TestNodeAddrOptionSetHostOnlyIPv6(t *testing.T) {
opt := NewListenAddrOption() opt := NewListenAddrOption()
assert.NilError(t, opt.Set("::1")) assert.NoError(t, opt.Set("::1"))
assert.Equal(t, opt.Value(), "[::1]:2377") assert.Equal(t, "[::1]:2377", opt.Value())
} }
func TestNodeAddrOptionSetPortOnly(t *testing.T) { func TestNodeAddrOptionSetPortOnly(t *testing.T) {
opt := NewListenAddrOption() opt := NewListenAddrOption()
assert.NilError(t, opt.Set(":4545")) assert.NoError(t, opt.Set(":4545"))
assert.Equal(t, opt.Value(), "0.0.0.0:4545") assert.Equal(t, "0.0.0.0:4545", opt.Value())
} }
func TestNodeAddrOptionSetInvalidFormat(t *testing.T) { func TestNodeAddrOptionSetInvalidFormat(t *testing.T) {
opt := NewListenAddrOption() 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) { func TestExternalCAOptionErrors(t *testing.T) {
@ -64,7 +64,7 @@ func TestExternalCAOptionErrors(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
opt := &ExternalCAOption{} 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 { for _, tc := range testCases {
opt := &ExternalCAOption{} opt := &ExternalCAOption{}
assert.NilError(t, opt.Set(tc.externalCA)) assert.NoError(t, opt.Set(tc.externalCA))
assert.Equal(t, opt.String(), tc.expected) assert.Equal(t, tc.expected, opt.String())
} }
} }
func TestExternalCAOptionMultiple(t *testing.T) { func TestExternalCAOptionMultiple(t *testing.T) {
opt := &ExternalCAOption{} opt := &ExternalCAOption{}
assert.NilError(t, opt.Set("protocol=cfssl,url=https://example.com")) assert.NoError(t, opt.Set("protocol=cfssl,url=https://example.com"))
assert.NilError(t, opt.Set("protocol=CFSSL,url=anything")) assert.NoError(t, opt.Set("protocol=CFSSL,url=anything"))
assert.Equal(t, len(opt.Value()), 2) assert.Len(t, opt.Value(), 2)
assert.Equal(t, opt.String(), "cfssl: https://example.com, cfssl: anything") assert.Equal(t, "cfssl: https://example.com, cfssl: anything", opt.String())
} }

View File

@ -12,8 +12,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestSwarmUnlockKeyErrors(t *testing.T) { func TestSwarmUnlockKeyErrors(t *testing.T) {
@ -94,7 +95,7 @@ func TestSwarmUnlockKeyErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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 { for key, value := range tc.flags {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("unlockkeys-%s.golden", tc.name)) 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))
} }
} }

View File

@ -9,8 +9,9 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSwarmUnlockErrors(t *testing.T) { func TestSwarmUnlockErrors(t *testing.T) {
@ -73,7 +74,7 @@ func TestSwarmUnlockErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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) }, buf)
dockerCli.SetIn(ioutil.NopCloser(strings.NewReader(input))) dockerCli.SetIn(ioutil.NopCloser(strings.NewReader(input)))
cmd := newUnlockCommand(dockerCli) cmd := newUnlockCommand(dockerCli)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }

View File

@ -13,8 +13,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestSwarmUpdateErrors(t *testing.T) { func TestSwarmUpdateErrors(t *testing.T) {
@ -79,7 +80,7 @@ func TestSwarmUpdateErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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.Flags().Set(key, value)
} }
cmd.SetOutput(buf) cmd.SetOutput(buf)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("update-%s.golden", tc.name)) 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))
} }
} }

View File

@ -9,8 +9,9 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
volumetypes "github.com/docker/docker/api/types/volume" volumetypes "github.com/docker/docker/api/types/volume"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestVolumeCreateErrors(t *testing.T) { func TestVolumeCreateErrors(t *testing.T) {
@ -50,7 +51,7 @@ func TestVolumeCreateErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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 // Test by flags
cmd := newCreateCommand(cli) cmd := newCreateCommand(cli)
cmd.Flags().Set("name", name) cmd.Flags().Set("name", name)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), name) assert.Equal(t, name, strings.TrimSpace(buf.String()))
// Then by args // Then by args
buf.Reset() buf.Reset()
cmd = newCreateCommand(cli) cmd = newCreateCommand(cli)
cmd.SetArgs([]string{name}) cmd.SetArgs([]string{name})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), name) assert.Equal(t, name, strings.TrimSpace(buf.String()))
} }
func TestVolumeCreateWithFlags(t *testing.T) { func TestVolumeCreateWithFlags(t *testing.T) {
@ -121,8 +122,8 @@ func TestVolumeCreateWithFlags(t *testing.T) {
cmd.Flags().Set("opt", "baz=baz") cmd.Flags().Set("opt", "baz=baz")
cmd.Flags().Set("label", "lbl1=v1") cmd.Flags().Set("label", "lbl1=v1")
cmd.Flags().Set("label", "lbl2=v2") cmd.Flags().Set("label", "lbl2=v2")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(buf.String()), name) assert.Equal(t, name, strings.TrimSpace(buf.String()))
} }
func compareMap(actual map[string]string, expected map[string]string) bool { func compareMap(actual map[string]string, expected map[string]string) bool {

View File

@ -11,8 +11,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestVolumeInspectErrors(t *testing.T) { func TestVolumeInspectErrors(t *testing.T) {
@ -64,7 +65,7 @@ func TestVolumeInspectErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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), }, buf),
) )
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-without-format.%s.golden", tc.name)) 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.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format) cmd.Flags().Set("format", tc.format)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-inspect-with-format.%s.golden", tc.name)) 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))
} }
} }

View File

@ -13,8 +13,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/docker/cli/internal/test/builders" . "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/docker/docker/pkg/testutil/golden"
"github.com/stretchr/testify/assert"
) )
func TestVolumeListErrors(t *testing.T) { func TestVolumeListErrors(t *testing.T) {
@ -47,7 +48,7 @@ func TestVolumeListErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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) }, buf)
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "volume-list-without-format.golden") 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) { func TestVolumeListWithConfigFormat(t *testing.T) {
@ -93,10 +94,10 @@ func TestVolumeListWithConfigFormat(t *testing.T) {
VolumesFormat: "{{ .Name }} {{ .Driver }} {{ .Labels }}", VolumesFormat: "{{ .Name }} {{ .Driver }} {{ .Labels }}",
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "volume-list-with-config-format.golden") 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) { func TestVolumeListWithFormat(t *testing.T) {
@ -117,8 +118,8 @@ func TestVolumeListWithFormat(t *testing.T) {
cli.SetConfigfile(&configfile.ConfigFile{}) cli.SetConfigfile(&configfile.ConfigFile{})
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}") cmd.Flags().Set("format", "{{ .Name }} {{ .Driver }} {{ .Labels }}")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "volume-list-with-format.golden") 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))
} }

View File

@ -11,9 +11,10 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters" "github.com/docker/docker/api/types/filters"
"github.com/docker/docker/cli/internal/test" "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/docker/docker/pkg/testutil/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestVolumePruneErrors(t *testing.T) { func TestVolumePruneErrors(t *testing.T) {
@ -48,7 +49,7 @@ func TestVolumePruneErrors(t *testing.T) {
cmd.Flags().Set(key, value) cmd.Flags().Set(key, value)
} }
cmd.SetOutput(ioutil.Discard) 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), }, buf),
) )
cmd.Flags().Set("force", "true") cmd.Flags().Set("force", "true")
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), fmt.Sprintf("volume-prune.%s.golden", tc.name)) 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) { func TestVolumePrunePromptYes(t *testing.T) {
@ -94,10 +95,10 @@ func TestVolumePrunePromptYes(t *testing.T) {
cmd := NewPruneCommand( cmd := NewPruneCommand(
cli, cli,
) )
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "volume-prune-yes.golden") 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( cmd := NewPruneCommand(
cli, cli,
) )
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
actual := buf.String() actual := buf.String()
expected := golden.Get(t, []byte(actual), "volume-prune-no.golden") 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))
} }
} }

View File

@ -6,8 +6,9 @@ import (
"testing" "testing"
"github.com/docker/docker/cli/internal/test" "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/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestVolumeRemoveErrors(t *testing.T) { func TestVolumeRemoveErrors(t *testing.T) {
@ -35,7 +36,7 @@ func TestVolumeRemoveErrors(t *testing.T) {
}, buf)) }, buf))
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.SetOutput(ioutil.Discard) 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) buf := new(bytes.Buffer)
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf)) cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}, buf))
cmd.SetArgs([]string{"volume1", "volume2"}) cmd.SetArgs([]string{"volume1", "volume2"})
assert.NilError(t, cmd.Execute()) assert.NoError(t, cmd.Execute())
} }

View File

@ -6,13 +6,14 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
composetypes "github.com/docker/docker/cli/compose/types" composetypes "github.com/docker/docker/cli/compose/types"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/docker/docker/pkg/testutil/tempfile" "github.com/docker/docker/pkg/testutil/tempfile"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestNamespaceScope(t *testing.T) { func TestNamespaceScope(t *testing.T) {
scoped := Namespace{name: "foo"}.Scope("bar") scoped := Namespace{name: "foo"}.Scope("bar")
assert.Equal(t, scoped, "foo_bar") assert.Equal(t, "foo_bar", scoped)
} }
func TestAddStackLabel(t *testing.T) { func TestAddStackLabel(t *testing.T) {
@ -24,7 +25,7 @@ func TestAddStackLabel(t *testing.T) {
"something": "labeled", "something": "labeled",
LabelNamespace: "foo", LabelNamespace: "foo",
} }
assert.DeepEqual(t, actual, expected) assert.Equal(t, expected, actual)
} }
func TestNetworks(t *testing.T) { func TestNetworks(t *testing.T) {
@ -98,8 +99,8 @@ func TestNetworks(t *testing.T) {
} }
networks, externals := Networks(namespace, source, serviceNetworks) networks, externals := Networks(namespace, source, serviceNetworks)
assert.DeepEqual(t, networks, expected) assert.Equal(t, expected, networks)
assert.DeepEqual(t, externals, []string{"special"}) assert.Equal(t, []string{"special"}, externals)
} }
func TestSecrets(t *testing.T) { func TestSecrets(t *testing.T) {
@ -122,13 +123,13 @@ func TestSecrets(t *testing.T) {
} }
specs, err := Secrets(namespace, source) specs, err := Secrets(namespace, source)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, len(specs), 1) require.Len(t, specs, 1)
secret := specs[0] secret := specs[0]
assert.Equal(t, secret.Name, "foo_one") assert.Equal(t, "foo_one", secret.Name)
assert.DeepEqual(t, secret.Labels, map[string]string{ assert.Equal(t, map[string]string{
"monster": "mash", "monster": "mash",
LabelNamespace: "foo", LabelNamespace: "foo",
}) }, secret.Labels)
assert.DeepEqual(t, secret.Data, []byte(secretText)) assert.Equal(t, []byte(secretText), secret.Data)
} }

View File

@ -9,18 +9,18 @@ import (
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
composetypes "github.com/docker/docker/cli/compose/types" 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) { func TestConvertRestartPolicyFromNone(t *testing.T) {
policy, err := convertRestartPolicy("no", nil) policy, err := convertRestartPolicy("no", nil)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, policy, (*swarm.RestartPolicy)(nil)) assert.Equal(t, (*swarm.RestartPolicy)(nil), policy)
} }
func TestConvertRestartPolicyFromUnknown(t *testing.T) { func TestConvertRestartPolicyFromUnknown(t *testing.T) {
_, err := convertRestartPolicy("unknown", nil) _, 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) { func TestConvertRestartPolicyFromAlways(t *testing.T) {
@ -28,8 +28,8 @@ func TestConvertRestartPolicyFromAlways(t *testing.T) {
expected := &swarm.RestartPolicy{ expected := &swarm.RestartPolicy{
Condition: swarm.RestartPolicyConditionAny, Condition: swarm.RestartPolicyConditionAny,
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, policy, expected) assert.Equal(t, expected, policy)
} }
func TestConvertRestartPolicyFromFailure(t *testing.T) { func TestConvertRestartPolicyFromFailure(t *testing.T) {
@ -39,8 +39,8 @@ func TestConvertRestartPolicyFromFailure(t *testing.T) {
Condition: swarm.RestartPolicyConditionOnFailure, Condition: swarm.RestartPolicyConditionOnFailure,
MaxAttempts: &attempts, MaxAttempts: &attempts,
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, policy, expected) assert.Equal(t, expected, policy)
} }
func strPtr(val string) *string { func strPtr(val string) *string {
@ -54,7 +54,7 @@ func TestConvertEnvironment(t *testing.T) {
} }
env := convertEnvironment(source) env := convertEnvironment(source)
sort.Strings(env) 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) { func TestConvertResourcesFull(t *testing.T) {
@ -69,7 +69,7 @@ func TestConvertResourcesFull(t *testing.T) {
}, },
} }
resources, err := convertResources(source) resources, err := convertResources(source)
assert.NilError(t, err) assert.NoError(t, err)
expected := &swarm.ResourceRequirements{ expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{ Limits: &swarm.Resources{
@ -81,7 +81,7 @@ func TestConvertResourcesFull(t *testing.T) {
MemoryBytes: 200000000, MemoryBytes: 200000000,
}, },
} }
assert.DeepEqual(t, resources, expected) assert.Equal(t, expected, resources)
} }
func TestConvertResourcesOnlyMemory(t *testing.T) { func TestConvertResourcesOnlyMemory(t *testing.T) {
@ -94,7 +94,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
}, },
} }
resources, err := convertResources(source) resources, err := convertResources(source)
assert.NilError(t, err) assert.NoError(t, err)
expected := &swarm.ResourceRequirements{ expected := &swarm.ResourceRequirements{
Limits: &swarm.Resources{ Limits: &swarm.Resources{
@ -104,7 +104,7 @@ func TestConvertResourcesOnlyMemory(t *testing.T) {
MemoryBytes: 200000000, MemoryBytes: 200000000,
}, },
} }
assert.DeepEqual(t, resources, expected) assert.Equal(t, expected, resources)
} }
func TestConvertHealthcheck(t *testing.T) { func TestConvertHealthcheck(t *testing.T) {
@ -123,8 +123,8 @@ func TestConvertHealthcheck(t *testing.T) {
} }
healthcheck, err := convertHealthcheck(source) healthcheck, err := convertHealthcheck(source)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, healthcheck, expected) assert.Equal(t, expected, healthcheck)
} }
func TestConvertHealthcheckDisable(t *testing.T) { func TestConvertHealthcheckDisable(t *testing.T) {
@ -134,8 +134,8 @@ func TestConvertHealthcheckDisable(t *testing.T) {
} }
healthcheck, err := convertHealthcheck(source) healthcheck, err := convertHealthcheck(source)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, healthcheck, expected) assert.Equal(t, expected, healthcheck)
} }
func TestConvertHealthcheckDisableWithTest(t *testing.T) { func TestConvertHealthcheckDisableWithTest(t *testing.T) {
@ -144,7 +144,7 @@ func TestConvertHealthcheckDisableWithTest(t *testing.T) {
Test: []string{"EXEC", "touch"}, Test: []string{"EXEC", "touch"},
} }
_, err := convertHealthcheck(source) _, 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) { func TestConvertEndpointSpec(t *testing.T) {
@ -178,8 +178,8 @@ func TestConvertEndpointSpec(t *testing.T) {
}, },
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, *endpoint, expected) assert.Equal(t, expected, *endpoint)
} }
func TestConvertServiceNetworksOnlyDefault(t *testing.T) { func TestConvertServiceNetworksOnlyDefault(t *testing.T) {
@ -195,8 +195,8 @@ func TestConvertServiceNetworksOnlyDefault(t *testing.T) {
}, },
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, configs, expected) assert.Equal(t, expected, configs)
} }
func TestConvertServiceNetworks(t *testing.T) { func TestConvertServiceNetworks(t *testing.T) {
@ -235,8 +235,8 @@ func TestConvertServiceNetworks(t *testing.T) {
sortedConfigs := byTargetSort(configs) sortedConfigs := byTargetSort(configs)
sort.Sort(&sortedConfigs) sort.Sort(&sortedConfigs)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(sortedConfigs), expected) assert.Equal(t, expected, []swarm.NetworkAttachmentConfig(sortedConfigs))
} }
func TestConvertServiceNetworksCustomDefault(t *testing.T) { func TestConvertServiceNetworksCustomDefault(t *testing.T) {
@ -260,8 +260,8 @@ func TestConvertServiceNetworksCustomDefault(t *testing.T) {
}, },
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, []swarm.NetworkAttachmentConfig(configs), expected) assert.Equal(t, expected, []swarm.NetworkAttachmentConfig(configs))
} }
type byTargetSort []swarm.NetworkAttachmentConfig type byTargetSort []swarm.NetworkAttachmentConfig
@ -281,8 +281,8 @@ func (s byTargetSort) Swap(i, j int) {
func TestConvertDNSConfigEmpty(t *testing.T) { func TestConvertDNSConfigEmpty(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, nil) dnsConfig, err := convertDNSConfig(nil, nil)
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, dnsConfig, (*swarm.DNSConfig)(nil)) assert.Equal(t, (*swarm.DNSConfig)(nil), dnsConfig)
} }
var ( var (
@ -292,27 +292,27 @@ var (
func TestConvertDNSConfigAll(t *testing.T) { func TestConvertDNSConfigAll(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, search) dnsConfig, err := convertDNSConfig(nameservers, search)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{ assert.Equal(t, &swarm.DNSConfig{
Nameservers: nameservers, Nameservers: nameservers,
Search: search, Search: search,
}) }, dnsConfig)
} }
func TestConvertDNSConfigNameservers(t *testing.T) { func TestConvertDNSConfigNameservers(t *testing.T) {
dnsConfig, err := convertDNSConfig(nameservers, nil) dnsConfig, err := convertDNSConfig(nameservers, nil)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{ assert.Equal(t, &swarm.DNSConfig{
Nameservers: nameservers, Nameservers: nameservers,
Search: nil, Search: nil,
}) }, dnsConfig)
} }
func TestConvertDNSConfigSearch(t *testing.T) { func TestConvertDNSConfigSearch(t *testing.T) {
dnsConfig, err := convertDNSConfig(nil, search) dnsConfig, err := convertDNSConfig(nil, search)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, dnsConfig, &swarm.DNSConfig{ assert.Equal(t, &swarm.DNSConfig{
Nameservers: nil, Nameservers: nil,
Search: search, Search: search,
}) }, dnsConfig)
} }

View File

@ -5,7 +5,7 @@ import (
"github.com/docker/docker/api/types/mount" "github.com/docker/docker/api/types/mount"
composetypes "github.com/docker/docker/cli/compose/types" 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) { func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
@ -18,8 +18,8 @@ func TestConvertVolumeToMountAnonymousVolume(t *testing.T) {
Target: "/foo/bar", Target: "/foo/bar",
} }
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo")) mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, mount, expected) assert.Equal(t, expected, mount)
} }
func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) { func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) {
@ -34,7 +34,7 @@ func TestConvertVolumeToMountConflictingOptionsBind(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, 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) { func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) {
@ -49,7 +49,7 @@ func TestConvertVolumeToMountConflictingOptionsVolume(t *testing.T) {
}, },
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, 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) { func TestConvertVolumeToMountNamedVolume(t *testing.T) {
@ -94,8 +94,8 @@ func TestConvertVolumeToMountNamedVolume(t *testing.T) {
}, },
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, mount, expected) assert.Equal(t, expected, mount)
} }
func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) { func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
@ -122,8 +122,8 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) {
Target: "/foo", Target: "/foo",
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, mount, expected) assert.Equal(t, expected, mount)
} }
func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) { func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
@ -153,8 +153,8 @@ func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) {
}, },
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, mount, expected) assert.Equal(t, expected, mount)
} }
func TestConvertVolumeToMountBind(t *testing.T) { func TestConvertVolumeToMountBind(t *testing.T) {
@ -175,8 +175,8 @@ func TestConvertVolumeToMountBind(t *testing.T) {
Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"}, Bind: &composetypes.ServiceVolumeBind{Propagation: "shared"},
} }
mount, err := convertVolumeToMount(config, stackVolumes, namespace) mount, err := convertVolumeToMount(config, stackVolumes, namespace)
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, mount, expected) assert.Equal(t, expected, mount)
} }
func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) { func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
@ -188,5 +188,5 @@ func TestConvertVolumeToMountVolumeDoesNotExist(t *testing.T) {
ReadOnly: true, ReadOnly: true,
} }
_, err := convertVolumeToMount(config, volumes{}, namespace) _, err := convertVolumeToMount(config, volumes{}, namespace)
assert.Error(t, err, "undefined volume \"unknown\"") assert.EqualError(t, err, "undefined volume \"unknown\"")
} }

View File

@ -4,15 +4,16 @@ import (
"testing" "testing"
"github.com/docker/docker/cli/compose/types" "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) { func TestParseVolumeAnonymousVolume(t *testing.T) {
for _, path := range []string{"/path", "/path/foo"} { for _, path := range []string{"/path", "/path/foo"} {
volume, err := parseVolume(path) volume, err := parseVolume(path)
expected := types.ServiceVolumeConfig{Type: "volume", Target: path} expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }
@ -20,29 +21,29 @@ func TestParseVolumeAnonymousVolumeWindows(t *testing.T) {
for _, path := range []string{"C:\\path", "Z:\\path\\foo"} { for _, path := range []string{"C:\\path", "Z:\\path\\foo"} {
volume, err := parseVolume(path) volume, err := parseVolume(path)
expected := types.ServiceVolumeConfig{Type: "volume", Target: path} expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }
func TestParseVolumeTooManyColons(t *testing.T) { func TestParseVolumeTooManyColons(t *testing.T) {
_, err := parseVolume("/foo:/foo:ro:foo") _, 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) { func TestParseVolumeShortVolumes(t *testing.T) {
for _, path := range []string{".", "/a"} { for _, path := range []string{".", "/a"} {
volume, err := parseVolume(path) volume, err := parseVolume(path)
expected := types.ServiceVolumeConfig{Type: "volume", Target: path} expected := types.ServiceVolumeConfig{Type: "volume", Target: path}
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }
func TestParseVolumeMissingSource(t *testing.T) { func TestParseVolumeMissingSource(t *testing.T) {
for _, spec := range []string{":foo", "/foo::ro"} { for _, spec := range []string{":foo", "/foo::ro"} {
_, err := parseVolume(spec) _, 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, Source: path,
Target: "/target", Target: "/target",
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }
@ -72,8 +73,8 @@ func TestParseVolumeRelativeBindMountWindows(t *testing.T) {
Source: path, Source: path,
Target: "d:\\target", Target: "d:\\target",
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }
@ -85,8 +86,8 @@ func TestParseVolumeWithBindOptions(t *testing.T) {
Target: "/target", Target: "/target",
Bind: &types.ServiceVolumeBind{Propagation: "slave"}, Bind: &types.ServiceVolumeBind{Propagation: "slave"},
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
func TestParseVolumeWithBindOptionsWindows(t *testing.T) { func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
@ -98,13 +99,13 @@ func TestParseVolumeWithBindOptionsWindows(t *testing.T) {
ReadOnly: true, ReadOnly: true,
Bind: &types.ServiceVolumeBind{Propagation: "rprivate"}, Bind: &types.ServiceVolumeBind{Propagation: "rprivate"},
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) { func TestParseVolumeWithInvalidVolumeOptions(t *testing.T) {
_, err := parseVolume("name:/target:bogus") _, 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) { func TestParseVolumeWithVolumeOptions(t *testing.T) {
@ -115,8 +116,8 @@ func TestParseVolumeWithVolumeOptions(t *testing.T) {
Target: "/target", Target: "/target",
Volume: &types.ServiceVolumeVolume{NoCopy: true}, Volume: &types.ServiceVolumeVolume{NoCopy: true},
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
func TestParseVolumeWithReadOnly(t *testing.T) { func TestParseVolumeWithReadOnly(t *testing.T) {
@ -128,8 +129,8 @@ func TestParseVolumeWithReadOnly(t *testing.T) {
Target: "/target", Target: "/target",
ReadOnly: true, ReadOnly: true,
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }
@ -142,7 +143,7 @@ func TestParseVolumeWithRW(t *testing.T) {
Target: "/target", Target: "/target",
ReadOnly: false, ReadOnly: false,
} }
assert.NilError(t, err) assert.NoError(t, err)
assert.DeepEqual(t, volume, expected) assert.Equal(t, expected, volume)
} }
} }

View File

@ -18,7 +18,7 @@ func defaultMapping(name string) (string, bool) {
func TestEscaped(t *testing.T) { func TestEscaped(t *testing.T) {
result, err := Substitute("$${foo}", defaultMapping) result, err := Substitute("$${foo}", defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "${foo}", result) assert.Equal(t, "${foo}", result)
} }
@ -43,7 +43,7 @@ func TestInvalid(t *testing.T) {
func TestNoValueNoDefault(t *testing.T) { func TestNoValueNoDefault(t *testing.T) {
for _, template := range []string{"This ${missing} var", "This ${BAR} var"} { for _, template := range []string{"This ${missing} var", "This ${BAR} var"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "This var", result) assert.Equal(t, "This var", result)
} }
} }
@ -51,7 +51,7 @@ func TestNoValueNoDefault(t *testing.T) {
func TestValueNoDefault(t *testing.T) { func TestValueNoDefault(t *testing.T) {
for _, template := range []string{"This $FOO var", "This ${FOO} var"} { for _, template := range []string{"This $FOO var", "This ${FOO} var"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "This first var", result) assert.Equal(t, "This first var", result)
} }
} }
@ -59,25 +59,25 @@ func TestValueNoDefault(t *testing.T) {
func TestNoValueWithDefault(t *testing.T) { func TestNoValueWithDefault(t *testing.T) {
for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} { for _, template := range []string{"ok ${missing:-def}", "ok ${missing-def}"} {
result, err := Substitute(template, defaultMapping) result, err := Substitute(template, defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "ok def", result) assert.Equal(t, "ok def", result)
} }
} }
func TestEmptyValueWithSoftDefault(t *testing.T) { func TestEmptyValueWithSoftDefault(t *testing.T) {
result, err := Substitute("ok ${BAR:-def}", defaultMapping) result, err := Substitute("ok ${BAR:-def}", defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "ok def", result) assert.Equal(t, "ok def", result)
} }
func TestEmptyValueWithHardDefault(t *testing.T) { func TestEmptyValueWithHardDefault(t *testing.T) {
result, err := Substitute("ok ${BAR-def}", defaultMapping) result, err := Substitute("ok ${BAR-def}", defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "ok ", result) assert.Equal(t, "ok ", result)
} }
func TestNonAlphanumericDefault(t *testing.T) { func TestNonAlphanumericDefault(t *testing.T) {
result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping) result, err := Substitute("ok ${BAR:-/non:-alphanumeric}", defaultMapping)
assert.NoError(t, err) assert.Nil(t, err)
assert.Equal(t, "ok /non:-alphanumeric", result) assert.Equal(t, "ok /non:-alphanumeric", result)
} }

View File

@ -5,8 +5,8 @@ import (
"testing" "testing"
cliconfig "github.com/docker/docker/cli/config" cliconfig "github.com/docker/docker/cli/config"
"github.com/docker/docker/pkg/testutil/assert"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
) )
func TestCommonOptionsInstallFlags(t *testing.T) { func TestCommonOptionsInstallFlags(t *testing.T) {
@ -19,9 +19,9 @@ func TestCommonOptionsInstallFlags(t *testing.T) {
"--tlscert=\"/foo/cert\"", "--tlscert=\"/foo/cert\"",
"--tlskey=\"/foo/key\"", "--tlskey=\"/foo/key\"",
}) })
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, opts.TLSOptions.CAFile, "/foo/cafile") assert.Equal(t, "/foo/cafile", opts.TLSOptions.CAFile)
assert.Equal(t, opts.TLSOptions.CertFile, "/foo/cert") assert.Equal(t, "/foo/cert", opts.TLSOptions.CertFile)
assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key") assert.Equal(t, opts.TLSOptions.KeyFile, "/foo/key")
} }
@ -35,8 +35,8 @@ func TestCommonOptionsInstallFlagsWithDefaults(t *testing.T) {
opts.InstallFlags(flags) opts.InstallFlags(flags)
err := flags.Parse([]string{}) err := flags.Parse([]string{})
assert.NilError(t, err) assert.NoError(t, err)
assert.Equal(t, opts.TLSOptions.CAFile, defaultPath("ca.pem")) assert.Equal(t, defaultPath("ca.pem"), opts.TLSOptions.CAFile)
assert.Equal(t, opts.TLSOptions.CertFile, defaultPath("cert.pem")) assert.Equal(t, defaultPath("cert.pem"), opts.TLSOptions.CertFile)
assert.Equal(t, opts.TLSOptions.KeyFile, defaultPath("key.pem")) assert.Equal(t, defaultPath("key.pem"), opts.TLSOptions.KeyFile)
} }