Automated migration

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2018-03-05 18:53:52 -05:00
parent 5ef8835f23
commit 39c2ca57c1
158 changed files with 1812 additions and 1727 deletions

View File

@ -5,7 +5,8 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestLoadFileV01Success(t *testing.T) { func TestLoadFileV01Success(t *testing.T) {
@ -25,9 +26,9 @@ func TestLoadFileV01Success(t *testing.T) {
}`) }`)
bundle, err := LoadFile(reader) bundle, err := LoadFile(reader)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, "0.1", bundle.Version) assert.Check(t, is.Equal("0.1", bundle.Version))
assert.Len(t, bundle.Services, 2) assert.Check(t, is.Len(bundle.Services, 2))
} }
func TestLoadFileSyntaxError(t *testing.T) { func TestLoadFileSyntaxError(t *testing.T) {
@ -37,7 +38,7 @@ func TestLoadFileSyntaxError(t *testing.T) {
}`) }`)
_, err := LoadFile(reader) _, err := LoadFile(reader)
assert.EqualError(t, err, "JSON syntax error at byte 37: invalid character 'u' looking for beginning of value") assert.Check(t, is.Error(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 +53,7 @@ func TestLoadFileTypeError(t *testing.T) {
}`) }`)
_, err := LoadFile(reader) _, err := LoadFile(reader)
assert.EqualError(t, err, "Unexpected type at byte 94. Expected []string but received string.") assert.Check(t, is.Error(err, "Unexpected type at byte 94. Expected []string but received string."))
} }
func TestPrint(t *testing.T) { func TestPrint(t *testing.T) {
@ -66,12 +67,12 @@ func TestPrint(t *testing.T) {
}, },
}, },
} }
assert.NoError(t, Print(&buffer, bundle)) assert.Check(t, Print(&buffer, bundle))
output := buffer.String() output := buffer.String()
assert.Contains(t, output, "\"Image\": \"image\"") assert.Check(t, is.Contains(output, "\"Image\": \"image\""))
assert.Contains(t, output, assert.Check(t, is.Contains(output,
`"Command": [ `"Command": [
"echo", "echo",
"something" "something"
]`) ]`))
} }

View File

@ -8,8 +8,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestCheckpointCreateErrors(t *testing.T) { func TestCheckpointCreateErrors(t *testing.T) {
@ -63,10 +64,10 @@ func TestCheckpointCreateWithOptions(t *testing.T) {
cmd.SetArgs([]string{"container-foo", checkpoint}) cmd.SetArgs([]string{"container-foo", checkpoint})
cmd.Flags().Set("leave-running", "true") cmd.Flags().Set("leave-running", "true")
cmd.Flags().Set("checkpoint-dir", "/dir/foo") cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "container-foo", containerID) assert.Check(t, is.Equal("container-foo", containerID))
assert.Equal(t, checkpoint, checkpointID) assert.Check(t, is.Equal(checkpoint, checkpointID))
assert.Equal(t, "/dir/foo", checkpointDir) assert.Check(t, is.Equal("/dir/foo", checkpointDir))
assert.Equal(t, false, exit) assert.Check(t, is.Equal(false, exit))
assert.Equal(t, checkpoint, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal(checkpoint, strings.TrimSpace(cli.OutBuffer().String())))
} }

View File

@ -7,9 +7,10 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestCheckpointListErrors(t *testing.T) { func TestCheckpointListErrors(t *testing.T) {
@ -60,8 +61,8 @@ func TestCheckpointListWithOptions(t *testing.T) {
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.SetArgs([]string{"container-foo"}) cmd.SetArgs([]string{"container-foo"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo") cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "container-foo", containerID) assert.Check(t, is.Equal("container-foo", containerID))
assert.Equal(t, "/dir/foo", checkpointDir) assert.Check(t, is.Equal("/dir/foo", checkpointDir))
golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden") golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden")
} }

View File

@ -7,8 +7,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestCheckpointRemoveErrors(t *testing.T) { func TestCheckpointRemoveErrors(t *testing.T) {
@ -58,8 +59,8 @@ func TestCheckpointRemoveWithOptions(t *testing.T) {
cmd := newRemoveCommand(cli) cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"container-foo", "checkpoint-bar"}) cmd.SetArgs([]string{"container-foo", "checkpoint-bar"})
cmd.Flags().Set("checkpoint-dir", "/dir/foo") cmd.Flags().Set("checkpoint-dir", "/dir/foo")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "container-foo", containerID) assert.Check(t, is.Equal("container-foo", containerID))
assert.Equal(t, "checkpoint-bar", checkpointID) assert.Check(t, is.Equal("checkpoint-bar", checkpointID))
assert.Equal(t, "/dir/foo", checkpointDir) assert.Check(t, is.Equal("/dir/foo", checkpointDir))
} }

View File

@ -12,10 +12,10 @@ import (
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -28,15 +28,15 @@ func TestNewAPIClientFromFlags(t *testing.T) {
}, },
} }
apiclient, err := NewAPIClientFromFlags(opts, configFile) apiclient, err := NewAPIClientFromFlags(opts, configFile)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, host, apiclient.DaemonHost()) assert.Check(t, is.Equal(host, apiclient.DaemonHost()))
expectedHeaders := map[string]string{ expectedHeaders := map[string]string{
"My-Header": "Custom-Value", "My-Header": "Custom-Value",
"User-Agent": UserAgent(), "User-Agent": UserAgent(),
} }
assert.Equal(t, expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders()) assert.Check(t, is.DeepEqual(expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders()))
assert.Equal(t, api.DefaultVersion, apiclient.ClientVersion()) assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
} }
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) { func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
@ -46,20 +46,20 @@ func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
opts := &flags.CommonOptions{} opts := &flags.CommonOptions{}
configFile := &configfile.ConfigFile{} configFile := &configfile.ConfigFile{}
apiclient, err := NewAPIClientFromFlags(opts, configFile) apiclient, err := NewAPIClientFromFlags(opts, configFile)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, customVersion, apiclient.ClientVersion()) assert.Check(t, is.Equal(customVersion, apiclient.ClientVersion()))
} }
// TODO: use gotestyourself/env.Patch // TODO: use gotestyourself/env.Patch
func patchEnvVariable(t *testing.T, key, value string) func() { func patchEnvVariable(t *testing.T, key, value string) func() {
oldValue, ok := os.LookupEnv(key) oldValue, ok := os.LookupEnv(key)
require.NoError(t, os.Setenv(key, value)) assert.NilError(t, os.Setenv(key, value))
return func() { return func() {
if !ok { if !ok {
require.NoError(t, os.Unsetenv(key)) assert.NilError(t, os.Unsetenv(key))
return return
} }
require.NoError(t, os.Setenv(key, oldValue)) assert.NilError(t, os.Setenv(key, oldValue))
} }
} }
@ -125,8 +125,8 @@ func TestInitializeFromClient(t *testing.T) {
cli := &DockerCli{client: apiclient} cli := &DockerCli{client: apiclient}
cli.initializeFromClient() cli.initializeFromClient()
assert.Equal(t, testcase.expectedServer, cli.serverInfo) assert.Check(t, is.DeepEqual(testcase.expectedServer, cli.serverInfo))
assert.Equal(t, testcase.negotiated, apiclient.negotiated) assert.Check(t, is.Equal(testcase.negotiated, apiclient.negotiated))
}) })
} }
} }
@ -164,8 +164,8 @@ func TestExperimentalCLI(t *testing.T) {
cli := &DockerCli{client: apiclient, err: os.Stderr} cli := &DockerCli{client: apiclient, err: os.Stderr}
cliconfig.SetDir(dir.Path()) cliconfig.SetDir(dir.Path())
err := cli.Initialize(flags.NewClientOptions()) err := cli.Initialize(flags.NewClientOptions())
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental) assert.Check(t, is.Equal(testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental))
}) })
} }
} }
@ -267,9 +267,9 @@ func TestOrchestratorSwitch(t *testing.T) {
options.Common.Orchestrator = testcase.flagOrchestrator options.Common.Orchestrator = testcase.flagOrchestrator
} }
err := cli.Initialize(options) err := cli.Initialize(options)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes()) assert.Check(t, is.Equal(testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes()))
assert.Equal(t, testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator)) assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator)))
}) })
} }
} }
@ -335,7 +335,7 @@ func TestGetClientWithPassword(t *testing.T) {
return return
} }
assert.NoError(t, err) assert.Check(t, err)
}) })
} }
} }

View File

@ -11,9 +11,10 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
const configDataFile = "config-create-with-name.golden" const configDataFile = "config-create-with-name.golden"
@ -70,9 +71,9 @@ func TestConfigCreateWithName(t *testing.T) {
cmd := newConfigCreateCommand(cli) cmd := newConfigCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, string(actual), configDataFile) golden.Assert(t, string(actual), configDataFile)
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }
func TestConfigCreateWithLabels(t *testing.T) { func TestConfigCreateWithLabels(t *testing.T) {
@ -83,7 +84,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
name := "foo" name := "foo"
data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile)) data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile))
assert.NoError(t, err) assert.Check(t, err)
expected := swarm.ConfigSpec{ expected := swarm.ConfigSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{
@ -109,8 +110,8 @@ func TestConfigCreateWithLabels(t *testing.T) {
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }
func TestConfigCreateWithTemplatingDriver(t *testing.T) { func TestConfigCreateWithTemplatingDriver(t *testing.T) {
@ -138,6 +139,6 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
cmd := newConfigCreateCommand(cli) cmd := newConfigCreateCommand(cli)
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)}) cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
cmd.Flags().Set("template-driver", expectedDriver.Name) cmd.Flags().Set("template-driver", expectedDriver.Name)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }

View File

@ -12,8 +12,8 @@ import (
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestConfigInspectErrors(t *testing.T) { func TestConfigInspectErrors(t *testing.T) {
@ -96,7 +96,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc}) cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc})
cmd := newConfigInspectCommand(cli) cmd := newConfigInspectCommand(cli)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-without-format.%s.golden", tc.name))
} }
} }
@ -133,7 +133,7 @@ func TestConfigInspectWithFormat(t *testing.T) {
cmd := newConfigInspectCommand(cli) cmd := newConfigInspectCommand(cli)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format) cmd.Flags().Set("format", tc.format)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-with-format.%s.golden", tc.name))
} }
} }
@ -167,7 +167,7 @@ func TestConfigInspectPretty(t *testing.T) {
cmd.SetArgs([]string{"configID"}) cmd.SetArgs([]string{"configID"})
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("config-inspect-pretty.%s.golden", tc.name))
} }
} }

View File

@ -13,8 +13,9 @@ import (
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestConfigListErrors(t *testing.T) { func TestConfigListErrors(t *testing.T) {
@ -72,7 +73,7 @@ func TestConfigList(t *testing.T) {
}, },
}) })
cmd := newConfigListCommand(cli) cmd := newConfigListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden") golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden")
} }
@ -89,7 +90,7 @@ func TestConfigListWithQuietOption(t *testing.T) {
}) })
cmd := newConfigListCommand(cli) cmd := newConfigListCommand(cli)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden") golden.Assert(t, cli.OutBuffer().String(), "config-list-with-quiet-option.golden")
} }
@ -108,7 +109,7 @@ func TestConfigListWithConfigFormat(t *testing.T) {
ConfigFormat: "{{ .Name }} {{ .Labels }}", ConfigFormat: "{{ .Name }} {{ .Labels }}",
}) })
cmd := newConfigListCommand(cli) cmd := newConfigListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden") golden.Assert(t, cli.OutBuffer().String(), "config-list-with-config-format.golden")
} }
@ -125,15 +126,15 @@ func TestConfigListWithFormat(t *testing.T) {
}) })
cmd := newConfigListCommand(cli) cmd := newConfigListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden") golden.Assert(t, cli.OutBuffer().String(), "config-list-with-format.golden")
} }
func TestConfigListWithFilter(t *testing.T) { func TestConfigListWithFilter(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) { configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
assert.Equal(t, "foo", options.Filters.Get("name")[0]) assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]))
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0]) assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
return []swarm.Config{ return []swarm.Config{
*Config(ConfigID("ID-foo"), *Config(ConfigID("ID-foo"),
ConfigName("foo"), ConfigName("foo"),
@ -153,6 +154,6 @@ func TestConfigListWithFilter(t *testing.T) {
cmd := newConfigListCommand(cli) cmd := newConfigListCommand(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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden") golden.Assert(t, cli.OutBuffer().String(), "config-list-with-filter.golden")
} }

View File

@ -7,8 +7,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestConfigRemoveErrors(t *testing.T) { func TestConfigRemoveErrors(t *testing.T) {
@ -52,9 +53,9 @@ func TestConfigRemoveWithName(t *testing.T) {
}) })
cmd := newConfigRemoveCommand(cli) cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names) cmd.SetArgs(names)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")) assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
assert.Equal(t, names, removedConfigs) assert.Check(t, is.DeepEqual(names, removedConfigs))
} }
func TestConfigRemoveContinueAfterError(t *testing.T) { func TestConfigRemoveContinueAfterError(t *testing.T) {
@ -74,6 +75,6 @@ func TestConfigRemoveContinueAfterError(t *testing.T) {
cmd := newConfigRemoveCommand(cli) cmd := newConfigRemoveCommand(cli)
cmd.SetArgs(names) cmd.SetArgs(names)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.EqualError(t, cmd.Execute(), "error removing config: foo") assert.Check(t, is.Error(cmd.Execute(), "error removing config: foo"))
assert.Equal(t, names, removedConfigs) assert.Check(t, is.DeepEqual(names, removedConfigs))
} }

View File

@ -10,8 +10,9 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewAttachCommandErrors(t *testing.T) { func TestNewAttachCommandErrors(t *testing.T) {
@ -123,6 +124,6 @@ func TestGetExitStatus(t *testing.T) {
resultC <- *testcase.result resultC <- *testcase.result
} }
err := getExitStatus(errC, resultC) err := getExitStatus(errC, resultC)
assert.Equal(t, testcase.expectedError, err) assert.Check(t, is.DeepEqual(testcase.expectedError, err))
} }
} }

View File

@ -12,10 +12,10 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/gotestyourself/gotestyourself/skip" "github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestRunCopyWithInvalidArguments(t *testing.T) { func TestRunCopyWithInvalidArguments(t *testing.T) {
@ -44,7 +44,7 @@ func TestRunCopyWithInvalidArguments(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
t.Run(testcase.doc, func(t *testing.T) { t.Run(testcase.doc, func(t *testing.T) {
err := runCopy(test.NewFakeCli(nil), testcase.options) err := runCopy(test.NewFakeCli(nil), testcase.options)
assert.EqualError(t, err, testcase.expectedErr) assert.Check(t, is.Error(err, testcase.expectedErr))
}) })
} }
} }
@ -54,16 +54,16 @@ func TestRunCopyFromContainerToStdout(t *testing.T) {
fakeClient := &fakeClient{ fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) { containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Equal(t, "container", container) assert.Check(t, is.Equal("container", container))
return ioutil.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil return ioutil.NopCloser(strings.NewReader(tarContent)), types.ContainerPathStat{}, nil
}, },
} }
options := copyOptions{source: "container:/path", destination: "-"} options := copyOptions{source: "container:/path", destination: "-"}
cli := test.NewFakeCli(fakeClient) cli := test.NewFakeCli(fakeClient)
err := runCopy(cli, options) err := runCopy(cli, options)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, tarContent, cli.OutBuffer().String()) assert.Check(t, is.Equal(tarContent, cli.OutBuffer().String()))
assert.Equal(t, "", cli.ErrBuffer().String()) assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
} }
func TestRunCopyFromContainerToFilesystem(t *testing.T) { func TestRunCopyFromContainerToFilesystem(t *testing.T) {
@ -73,7 +73,7 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
fakeClient := &fakeClient{ fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) { containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Equal(t, "container", container) assert.Check(t, is.Equal("container", container))
readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{}) readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{})
return readCloser, types.ContainerPathStat{}, err return readCloser, types.ContainerPathStat{}, err
}, },
@ -81,13 +81,13 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
options := copyOptions{source: "container:/path", destination: destDir.Path()} options := copyOptions{source: "container:/path", destination: destDir.Path()}
cli := test.NewFakeCli(fakeClient) cli := test.NewFakeCli(fakeClient)
err := runCopy(cli, options) err := runCopy(cli, options)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, "", cli.OutBuffer().String()) assert.Check(t, is.Equal("", cli.OutBuffer().String()))
assert.Equal(t, "", cli.ErrBuffer().String()) assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
content, err := ioutil.ReadFile(destDir.Join("file1")) content, err := ioutil.ReadFile(destDir.Join("file1"))
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, "content\n", string(content)) assert.Check(t, is.Equal("content\n", string(content)))
} }
func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.T) { func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.T) {
@ -97,7 +97,7 @@ func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.
fakeClient := &fakeClient{ fakeClient := &fakeClient{
containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) { containerCopyFromFunc: func(container, srcPath string) (io.ReadCloser, types.ContainerPathStat, error) {
assert.Equal(t, "container", container) assert.Check(t, is.Equal("container", container))
readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{}) readCloser, err := archive.TarWithOptions(destDir.Path(), &archive.TarOptions{})
return readCloser, types.ContainerPathStat{}, err return readCloser, types.ContainerPathStat{}, err
}, },
@ -181,8 +181,8 @@ func TestSplitCpArg(t *testing.T) {
skip.IfCondition(t, testcase.os != "" && testcase.os != runtime.GOOS) skip.IfCondition(t, testcase.os != "" && testcase.os != runtime.GOOS)
container, path := splitCpArg(testcase.path) container, path := splitCpArg(testcase.path)
assert.Equal(t, testcase.expectedContainer, container) assert.Check(t, is.Equal(testcase.expectedContainer, container))
assert.Equal(t, testcase.expectedPath, path) assert.Check(t, is.Equal(testcase.expectedPath, path))
}) })
} }
} }

View File

@ -14,19 +14,19 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestCIDFileNoOPWithNoFilename(t *testing.T) { func TestCIDFileNoOPWithNoFilename(t *testing.T) {
file, err := newCIDFile("") file, err := newCIDFile("")
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, &cidFile{}, file) assert.Check(t, is.DeepEqual(&cidFile{}, file))
assert.NoError(t, file.Write("id")) assert.Check(t, file.Write("id"))
assert.NoError(t, file.Close()) assert.Check(t, file.Close())
} }
func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) { func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
@ -43,12 +43,12 @@ func TestCIDFileCloseWithNoWrite(t *testing.T) {
path := tempdir.Join("cidfile") path := tempdir.Join("cidfile")
file, err := newCIDFile(path) file, err := newCIDFile(path)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, file.path, path) assert.Check(t, is.Equal(file.path, path))
assert.NoError(t, file.Close()) assert.Check(t, file.Close())
_, err = os.Stat(path) _, err = os.Stat(path)
assert.True(t, os.IsNotExist(err)) assert.Check(t, os.IsNotExist(err))
} }
func TestCIDFileCloseWithWrite(t *testing.T) { func TestCIDFileCloseWithWrite(t *testing.T) {
@ -57,18 +57,18 @@ func TestCIDFileCloseWithWrite(t *testing.T) {
path := tempdir.Join("cidfile") path := tempdir.Join("cidfile")
file, err := newCIDFile(path) file, err := newCIDFile(path)
require.NoError(t, err) assert.NilError(t, err)
content := "id" content := "id"
assert.NoError(t, file.Write(content)) assert.Check(t, file.Write(content))
actual, err := ioutil.ReadFile(path) actual, err := ioutil.ReadFile(path)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, content, string(actual)) assert.Check(t, is.Equal(content, string(actual)))
assert.NoError(t, file.Close()) assert.Check(t, file.Close())
_, err = os.Stat(path) _, err = os.Stat(path)
require.NoError(t, err) assert.NilError(t, err)
} }
func TestCreateContainerPullsImageIfMissing(t *testing.T) { func TestCreateContainerPullsImageIfMissing(t *testing.T) {
@ -108,11 +108,11 @@ func TestCreateContainerPullsImageIfMissing(t *testing.T) {
HostConfig: &container.HostConfig{}, HostConfig: &container.HostConfig{},
} }
body, err := createContainer(context.Background(), cli, config, "name", runtime.GOOS) body, err := createContainer(context.Background(), cli, config, "name", runtime.GOOS)
require.NoError(t, err) assert.NilError(t, err)
expected := container.ContainerCreateCreatedBody{ID: containerID} expected := container.ContainerCreateCreatedBody{ID: containerID}
assert.Equal(t, expected, *body) assert.Check(t, is.DeepEqual(expected, *body))
stderr := cli.ErrBuffer().String() stderr := cli.ErrBuffer().String()
assert.Contains(t, stderr, "Unable to find image 'does-not-exist-locally:latest' locally") assert.Check(t, is.Contains(stderr, "Unable to find image 'does-not-exist-locally:latest' locally"))
} }
type fakeNotFound struct{} type fakeNotFound struct{}

View File

@ -10,8 +10,9 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -106,7 +107,7 @@ func TestParseExec(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
execConfig := parseExec(testcase.options, &testcase.configFile) execConfig := parseExec(testcase.options, &testcase.configFile)
assert.Equal(t, testcase.expected, *execConfig) assert.Check(t, is.DeepEqual(testcase.expected, *execConfig))
} }
} }
@ -152,12 +153,12 @@ func TestRunExec(t *testing.T) {
if testcase.expectedError != "" { if testcase.expectedError != "" {
testutil.ErrorContains(t, err, testcase.expectedError) testutil.ErrorContains(t, err, testcase.expectedError)
} else { } else {
if !assert.NoError(t, err) { if !assert.Check(t, err) {
return return
} }
} }
assert.Equal(t, testcase.expectedOut, cli.OutBuffer().String()) assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
assert.Equal(t, testcase.expectedErr, cli.ErrBuffer().String()) assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
}) })
} }
} }
@ -192,12 +193,12 @@ func TestGetExecExitStatus(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
client := &fakeClient{ client := &fakeClient{
execInspectFunc: func(id string) (types.ContainerExecInspect, error) { execInspectFunc: func(id string) (types.ContainerExecInspect, error) {
assert.Equal(t, execID, id) assert.Check(t, is.Equal(execID, id))
return types.ContainerExecInspect{ExitCode: testcase.exitCode}, testcase.inspectError return types.ContainerExecInspect{ExitCode: testcase.exitCode}, testcase.inspectError
}, },
} }
err := getExecExitStatus(context.Background(), client, execID) err := getExecExitStatus(context.Background(), client, execID)
assert.Equal(t, testcase.expectedError, err) assert.Check(t, is.DeepEqual(testcase.expectedError, err))
} }
} }

View File

@ -9,9 +9,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
) )
@ -69,7 +69,7 @@ func TestContainerListWithoutFormat(t *testing.T) {
}, },
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden") golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden")
} }
@ -84,7 +84,7 @@ func TestContainerListNoTrunc(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("no-trunc", "true") cmd.Flags().Set("no-trunc", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden") golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format-no-trunc.golden")
} }
@ -100,7 +100,7 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Names}} {{.Names}}") cmd.Flags().Set("format", "{{.Names}} {{.Names}}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden") golden.Assert(t, cli.OutBuffer().String(), "container-list-format-name-name.golden")
} }
@ -116,20 +116,20 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`) cmd.Flags().Set("format", `{{.Names}} {{.Label "some.label"}}`)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden") golden.Assert(t, cli.OutBuffer().String(), "container-list-format-with-arg.golden")
} }
func TestContainerListFormatSizeSetsOption(t *testing.T) { func TestContainerListFormatSizeSetsOption(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
containerListFunc: func(options types.ContainerListOptions) ([]types.Container, error) { containerListFunc: func(options types.ContainerListOptions) ([]types.Container, error) {
assert.True(t, options.Size) assert.Check(t, options.Size)
return []types.Container{}, nil return []types.Container{}, nil
}, },
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", `{{.Size}}`) cmd.Flags().Set("format", `{{.Size}}`)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }
func TestContainerListWithConfigFormat(t *testing.T) { func TestContainerListWithConfigFormat(t *testing.T) {
@ -145,7 +145,7 @@ func TestContainerListWithConfigFormat(t *testing.T) {
PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }}", PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }}",
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden") golden.Assert(t, cli.OutBuffer().String(), "container-list-with-config-format.golden")
} }
@ -160,6 +160,6 @@ func TestContainerListWithFormat(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}") cmd.Flags().Set("format", "{{ .Names }} {{ .Image }} {{ .Labels }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden") golden.Assert(t, cli.OutBuffer().String(), "container-list-with-format.golden")
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
var logFn = func(expectedOut string) func(string, types.ContainerLogsOptions) (io.ReadCloser, error) { var logFn = func(expectedOut string) func(string, types.ContainerLogsOptions) (io.ReadCloser, error) {
@ -51,12 +52,12 @@ func TestRunLogs(t *testing.T) {
if testcase.expectedError != "" { if testcase.expectedError != "" {
testutil.ErrorContains(t, err, testcase.expectedError) testutil.ErrorContains(t, err, testcase.expectedError)
} else { } else {
if !assert.NoError(t, err) { if !assert.Check(t, err) {
return return
} }
} }
assert.Equal(t, testcase.expectedOut, cli.OutBuffer().String()) assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
assert.Equal(t, testcase.expectedErr, cli.ErrBuffer().String()) assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
}) })
} }
} }

View File

@ -13,10 +13,10 @@ 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/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/spf13/pflag" "github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestValidateAttach(t *testing.T) { func TestValidateAttach(t *testing.T) {
@ -67,12 +67,12 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
func parseMustError(t *testing.T, args string) { func parseMustError(t *testing.T, args string) {
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " ")) _, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
assert.Error(t, err, args) assert.Check(t, is.ErrorContains(err, ""), args)
} }
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) { func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) {
config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash")) config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
assert.NoError(t, err) assert.Check(t, err)
return config, hostConfig return config, hostConfig
} }
@ -239,7 +239,7 @@ func TestRunFlagsParseWithMemory(t *testing.T) {
testutil.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`) testutil.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
_, hostconfig := mustParse(t, "--memory=1G") _, hostconfig := mustParse(t, "--memory=1G")
assert.Equal(t, int64(1073741824), hostconfig.Memory) assert.Check(t, is.Equal(int64(1073741824), hostconfig.Memory))
} }
func TestParseWithMemorySwap(t *testing.T) { func TestParseWithMemorySwap(t *testing.T) {
@ -249,10 +249,10 @@ func TestParseWithMemorySwap(t *testing.T) {
testutil.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`) testutil.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
_, hostconfig := mustParse(t, "--memory-swap=1G") _, hostconfig := mustParse(t, "--memory-swap=1G")
assert.Equal(t, int64(1073741824), hostconfig.MemorySwap) assert.Check(t, is.Equal(int64(1073741824), hostconfig.MemorySwap))
_, hostconfig = mustParse(t, "--memory-swap=-1") _, hostconfig = mustParse(t, "--memory-swap=-1")
assert.Equal(t, int64(-1), hostconfig.MemorySwap) assert.Check(t, is.Equal(int64(-1), hostconfig.MemorySwap))
} }
func TestParseHostname(t *testing.T) { func TestParseHostname(t *testing.T) {
@ -373,13 +373,13 @@ func TestParseModes(t *testing.T) {
// pid ko // pid ko
flags, copts := setupRunFlags() flags, copts := setupRunFlags()
args := []string{"--pid=container:", "img", "cmd"} args := []string{"--pid=container:", "img", "cmd"}
require.NoError(t, flags.Parse(args)) assert.NilError(t, flags.Parse(args))
_, err := parse(flags, copts) _, err := parse(flags, copts)
testutil.ErrorContains(t, err, "--pid: invalid PID mode") testutil.ErrorContains(t, err, "--pid: invalid PID mode")
// pid ok // pid ok
_, hostconfig, _, err := parseRun([]string{"--pid=host", "img", "cmd"}) _, hostconfig, _, err := parseRun([]string{"--pid=host", "img", "cmd"})
require.NoError(t, err) assert.NilError(t, err)
if !hostconfig.PidMode.Valid() { if !hostconfig.PidMode.Valid() {
t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode) t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode)
} }
@ -390,7 +390,7 @@ func TestParseModes(t *testing.T) {
// uts ok // uts ok
_, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"}) _, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"})
require.NoError(t, err) assert.NilError(t, err)
if !hostconfig.UTSMode.Valid() { if !hostconfig.UTSMode.Valid() {
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode) t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
} }
@ -406,7 +406,7 @@ func TestRunFlagsParseShmSize(t *testing.T) {
// shm-size ok // shm-size ok
_, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"}) _, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"})
require.NoError(t, err) assert.NilError(t, err)
if hostconfig.ShmSize != 134217728 { if hostconfig.ShmSize != 134217728 {
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize) t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
} }

View File

@ -4,13 +4,14 @@ import (
"testing" "testing"
"github.com/docker/cli/opts" "github.com/docker/cli/opts"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestBuildContainerListOptions(t *testing.T) { func TestBuildContainerListOptions(t *testing.T) {
filters := opts.NewFilterOpt() filters := opts.NewFilterOpt()
assert.NoError(t, filters.Set("foo=bar")) assert.Check(t, filters.Set("foo=bar"))
assert.NoError(t, filters.Set("baz=foo")) assert.Check(t, filters.Set("baz=foo"))
contexts := []struct { contexts := []struct {
psOpts *psOptions psOpts *psOptions
@ -101,12 +102,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.NoError(t, err) assert.Check(t, err)
assert.Equal(t, c.expectedAll, options.All) assert.Check(t, is.Equal(c.expectedAll, options.All))
assert.Equal(t, c.expectedSize, options.Size) assert.Check(t, is.Equal(c.expectedSize, options.Size))
assert.Equal(t, c.expectedLimit, options.Limit) assert.Check(t, is.Equal(c.expectedLimit, options.Limit))
assert.Equal(t, len(c.expectedFilters), options.Filters.Len()) assert.Check(t, is.Equal(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

@ -6,7 +6,7 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
) )
func TestRunLabel(t *testing.T) { func TestRunLabel(t *testing.T) {
@ -21,5 +21,5 @@ func TestRunLabel(t *testing.T) {
cmd := NewRunCommand(cli) cmd := NewRunCommand(cli)
cmd.Flags().Set("detach", "true") cmd.Flags().Set("detach", "true")
cmd.SetArgs([]string{"--label", "foo", "busybox"}) cmd.SetArgs([]string{"--label", "foo", "busybox"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }

View File

@ -4,7 +4,7 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
) )
func TestCalculateMemUsageUnixNoCache(t *testing.T) { func TestCalculateMemUsageUnixNoCache(t *testing.T) {

View File

@ -7,8 +7,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/container"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -64,6 +65,6 @@ func TestWaitExitOrRemoved(t *testing.T) {
for _, testcase := range testcases { for _, testcase := range testcases {
statusC := waitExitOrRemoved(context.Background(), client, testcase.cid, true) statusC := waitExitOrRemoved(context.Background(), client, testcase.cid, true)
exitCode := <-statusC exitCode := <-statusC
assert.Equal(t, testcase.exitCode, exitCode) assert.Check(t, is.Equal(testcase.exitCode, exitCode))
} }
} }

View File

@ -5,7 +5,8 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestCheckpointContextFormatWrite(t *testing.T) { func TestCheckpointContextFormatWrite(t *testing.T) {
@ -47,9 +48,9 @@ checkpoint-3:
testcase.context.Output = out testcase.context.Output = out
err := CheckpointWrite(testcase.context, checkpoints) err := CheckpointWrite(testcase.context, checkpoints)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.Check(t, is.ErrorContains(err, ""), testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Check(t, is.Equal(out.String(), testcase.expected))
} }
} }
} }

View File

@ -6,7 +6,8 @@ import (
"time" "time"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestConfigContextFormatWrite(t *testing.T) { func TestConfigContextFormatWrite(t *testing.T) {
@ -55,9 +56,9 @@ id_rsa
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
testcase.context.Output = out testcase.context.Output = out
if err := ConfigWrite(testcase.context, configs); err != nil { if err := ConfigWrite(testcase.context, configs); err != nil {
assert.Error(t, err, testcase.expected) assert.Check(t, is.ErrorContains(err, ""), testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Check(t, is.Equal(out.String(), testcase.expected))
} }
} }
} }

View File

@ -10,9 +10,9 @@ 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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestContainerPsContext(t *testing.T) { func TestContainerPsContext(t *testing.T) {
@ -244,9 +244,9 @@ size: 0B
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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -305,7 +305,7 @@ func TestContainerContextWriteWithNoContainers(t *testing.T) {
for _, context := range contexts { for _, context := range contexts {
ContainerWrite(context.context, containers) ContainerWrite(context.context, containers)
assert.Equal(t, context.expected, out.String()) assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }
@ -359,8 +359,8 @@ func TestContainerContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{} var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m) err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg) assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
} }
} }
@ -378,8 +378,8 @@ func TestContainerContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string var s string
err := json.Unmarshal([]byte(line), &s) err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, containers[i].ID, s, msg) assert.Check(t, is.Equal(containers[i].ID, s), msg)
} }
} }
@ -653,6 +653,6 @@ func TestDisplayablePorts(t *testing.T) {
for _, port := range cases { for _, port := range cases {
actual := DisplayablePorts(port.ports) actual := DisplayablePorts(port.ports)
assert.Equal(t, port.expected, actual) assert.Check(t, is.Equal(port.expected, actual))
} }
} }

View File

@ -4,7 +4,8 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func compareMultipleValues(t *testing.T, value, expected string) { func compareMultipleValues(t *testing.T, value, expected string) {
@ -23,5 +24,5 @@ func compareMultipleValues(t *testing.T, value, expected string) {
keyval := strings.Split(expected, "=") keyval := strings.Split(expected, "=")
expMap[keyval[0]] = keyval[1] expMap[keyval[0]] = keyval[1]
} }
assert.Equal(t, expMap, entriesMap) assert.Check(t, is.DeepEqual(expMap, entriesMap))
} }

View File

@ -6,7 +6,8 @@ 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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestDiffContextFormatWrite(t *testing.T) { func TestDiffContextFormatWrite(t *testing.T) {
@ -51,9 +52,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }

View File

@ -4,8 +4,9 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestDiskUsageContextFormatWrite(t *testing.T) { func TestDiskUsageContextFormatWrite(t *testing.T) {
@ -101,9 +102,9 @@ Build Cache 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, testcase.expected, err.Error()) assert.Check(t, is.Equal(testcase.expected, err.Error()))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }

View File

@ -3,7 +3,8 @@ package formatter
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestEllipsis(t *testing.T) { func TestEllipsis(t *testing.T) {
@ -25,6 +26,6 @@ func TestEllipsis(t *testing.T) {
} }
for _, testcase := range testcases { for _, testcase := range testcases {
assert.Equal(t, testcase.expected, Ellipsis(testcase.source, testcase.width)) assert.Check(t, is.Equal(testcase.expected, Ellipsis(testcase.source, testcase.width)))
} }
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
type historyCase struct { type historyCase struct {
@ -218,7 +219,7 @@ imageID4 24 hours ago /bin/bash grep
for _, context := range contexts { for _, context := range contexts {
HistoryWrite(context.context, true, histories) HistoryWrite(context.context, true, histories)
assert.Equal(t, context.expected, out.String()) assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }

View File

@ -9,7 +9,8 @@ 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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestImageContext(t *testing.T) { func TestImageContext(t *testing.T) {
@ -83,7 +84,7 @@ func TestImageContext(t *testing.T) {
if strings.Contains(v, ",") { if strings.Contains(v, ",") {
compareMultipleValues(t, v, c.expValue) compareMultipleValues(t, v, c.expValue)
} else { } else {
assert.Equal(t, c.expValue, v) assert.Check(t, is.Equal(c.expValue, v))
} }
} }
} }
@ -293,9 +294,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -348,7 +349,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, context.expected, out.String()) assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }

View File

@ -10,8 +10,8 @@ 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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestNetworkContext(t *testing.T) { func TestNetworkContext(t *testing.T) {
@ -162,9 +162,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -188,8 +188,8 @@ func TestNetworkContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{} var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m) err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg) assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
} }
} }
@ -207,7 +207,7 @@ func TestNetworkContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string var s string
err := json.Unmarshal([]byte(line), &s) err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, networks[i].ID, s, msg) assert.Check(t, is.Equal(networks[i].ID, s), msg)
} }
} }

View File

@ -10,8 +10,8 @@ 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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestNodeContext(t *testing.T) { func TestNodeContext(t *testing.T) {
@ -203,9 +203,9 @@ foobar_boo Unknown
testcase.context.Output = out testcase.context.Output = out
err := NodeWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}}) err := NodeWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}})
if err != nil { if err != nil {
assert.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -255,8 +255,8 @@ func TestNodeContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{} var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m) err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, testcase.expected[i], m, msg) assert.Check(t, is.DeepEqual(testcase.expected[i], m), msg)
} }
} }
} }
@ -275,8 +275,8 @@ func TestNodeContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string var s string
err := json.Unmarshal([]byte(line), &s) err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, nodes[i].ID, s, msg) assert.Check(t, is.Equal(nodes[i].ID, s), msg)
} }
} }
@ -344,5 +344,5 @@ data
Issuer Subject: c3ViamVjdA== Issuer Subject: c3ViamVjdA==
Issuer Public Key: cHViS2V5 Issuer Public Key: cHViS2V5
` `
assert.Equal(t, expected, out.String()) assert.Check(t, is.Equal(expected, out.String()))
} }

View File

@ -8,7 +8,8 @@ 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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestPluginContext(t *testing.T) { func TestPluginContext(t *testing.T) {
@ -131,9 +132,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -158,7 +159,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.Equal(t, expectedJSONs[i], m) assert.Check(t, is.DeepEqual(expectedJSONs[i], m))
} }
} }
@ -177,6 +178,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, plugins[i].ID, s) assert.Check(t, is.Equal(plugins[i].ID, s))
} }
} }

View File

@ -7,8 +7,9 @@ import (
"testing" "testing"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestSearchContext(t *testing.T) { func TestSearchContext(t *testing.T) {
@ -154,9 +155,9 @@ result2 5
testcase.context.Output = out testcase.context.Output = out
err := SearchWrite(testcase.context, results, false, 0) err := SearchWrite(testcase.context, results, false, 0)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.Check(t, is.ErrorContains(err, ""), testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Check(t, is.Equal(out.String(), testcase.expected))
} }
} }
} }
@ -191,9 +192,9 @@ result2
testcase.context.Output = out testcase.context.Output = out
err := SearchWrite(testcase.context, results, true, 0) err := SearchWrite(testcase.context, results, true, 0)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.Check(t, is.ErrorContains(err, ""), testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Check(t, is.Equal(out.String(), testcase.expected))
} }
} }
} }
@ -226,9 +227,9 @@ result1
testcase.context.Output = out testcase.context.Output = out
err := SearchWrite(testcase.context, results, false, 6) err := SearchWrite(testcase.context, results, false, 6)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.Check(t, is.ErrorContains(err, ""), testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Check(t, is.Equal(out.String(), testcase.expected))
} }
} }
} }
@ -254,7 +255,7 @@ func TestSearchContextWriteJSON(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.Equal(t, m, expectedJSONs[i]) assert.Check(t, is.DeepEqual(m, expectedJSONs[i]))
} }
} }
@ -274,6 +275,6 @@ func TestSearchContextWriteJSONField(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, results[i].Name) assert.Check(t, is.Equal(s, results[i].Name))
} }
} }

View File

@ -6,7 +6,8 @@ import (
"time" "time"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestSecretContextFormatWrite(t *testing.T) { func TestSecretContextFormatWrite(t *testing.T) {
@ -55,9 +56,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }

View File

@ -8,9 +8,9 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestServiceContextWrite(t *testing.T) { func TestServiceContextWrite(t *testing.T) {
@ -126,9 +126,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -192,8 +192,8 @@ func TestServiceContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{} var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m) err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg) assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
} }
} }
func TestServiceContextWriteJSONField(t *testing.T) { func TestServiceContextWriteJSONField(t *testing.T) {
@ -220,8 +220,8 @@ func TestServiceContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string var s string
err := json.Unmarshal([]byte(line), &s) err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, services[i].Spec.Name, s, msg) assert.Check(t, is.Equal(services[i].Spec.Name, s), msg)
} }
} }
@ -355,5 +355,5 @@ func TestServiceContext_Ports(t *testing.T) {
}, },
} }
assert.Equal(t, "*:97-98->97-98/sctp, *:60-61->60-61/tcp, *:62->61/tcp, *:80-81->80/tcp, *:90-95->90-95/tcp, *:90-96->90-96/udp", c.Ports()) assert.Check(t, is.Equal("*:97-98->97-98/sctp, *:60-61->60-61/tcp, *:62->61/tcp, *:80-81->80/tcp, *:90-95->90-95/tcp, *:90-96->90-96/udp", c.Ports()))
} }

View File

@ -4,7 +4,8 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestStackContextWrite(t *testing.T) { func TestStackContextWrite(t *testing.T) {
@ -56,9 +57,9 @@ bar
testcase.context.Output = out testcase.context.Output = out
err := StackWrite(testcase.context, stacks) err := StackWrite(testcase.context, stacks)
if err != nil { if err != nil {
assert.Error(t, err, testcase.expected) assert.Check(t, is.ErrorContains(err, ""), testcase.expected)
} else { } else {
assert.Equal(t, out.String(), testcase.expected) assert.Check(t, is.Equal(out.String(), testcase.expected))
} }
} }
} }

View File

@ -5,7 +5,8 @@ import (
"testing" "testing"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestContainerStatsContext(t *testing.T) { func TestContainerStatsContext(t *testing.T) {
@ -116,9 +117,9 @@ container2 --
te.context.Output = &out te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "linux", false) err := ContainerStatsWrite(te.context, stats, "linux", false)
if err != nil { if err != nil {
assert.EqualError(t, err, te.expected) assert.Check(t, is.Error(err, te.expected))
} else { } else {
assert.Equal(t, te.expected, out.String()) assert.Check(t, is.Equal(te.expected, out.String()))
} }
} }
} }
@ -182,9 +183,9 @@ container2 -- --
te.context.Output = &out te.context.Output = &out
err := ContainerStatsWrite(te.context, stats, "windows", false) err := ContainerStatsWrite(te.context, stats, "windows", false)
if err != nil { if err != nil {
assert.EqualError(t, err, te.expected) assert.Check(t, is.Error(err, te.expected))
} else { } else {
assert.Equal(t, te.expected, out.String()) assert.Check(t, is.Equal(te.expected, out.String()))
} }
} }
} }
@ -221,7 +222,7 @@ func TestContainerStatsContextWriteWithNoStats(t *testing.T) {
for _, context := range contexts { for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{}, "linux", false) ContainerStatsWrite(context.context, []StatsEntry{}, "linux", false)
assert.Equal(t, context.expected, out.String()) assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }
@ -259,7 +260,7 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
for _, context := range contexts { for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{}, "windows", false) ContainerStatsWrite(context.context, []StatsEntry{}, "windows", false)
assert.Equal(t, context.expected, out.String()) assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }
@ -293,7 +294,7 @@ func TestContainerStatsContextWriteTrunc(t *testing.T) {
for _, context := range contexts { for _, context := range contexts {
ContainerStatsWrite(context.context, []StatsEntry{{ID: "b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc"}}, "linux", context.trunc) ContainerStatsWrite(context.context, []StatsEntry{{ID: "b95a83497c9161c9b444e3d70e1a9dfba0c1840d41720e146a95a08ebf938afc"}}, "linux", context.trunc)
assert.Equal(t, context.expected, out.String()) assert.Check(t, is.Equal(context.expected, out.String()))
// Clean buffer // Clean buffer
out.Reset() out.Reset()
} }

View File

@ -7,8 +7,9 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestTaskContextWrite(t *testing.T) { func TestTaskContextWrite(t *testing.T) {
@ -74,9 +75,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -100,6 +101,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, tasks[i].ID, s) assert.Check(t, is.Equal(tasks[i].ID, s))
} }
} }

View File

@ -5,7 +5,8 @@ import (
"testing" "testing"
"github.com/docker/docker/pkg/stringid" "github.com/docker/docker/pkg/stringid"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestTrustTag(t *testing.T) { func TestTrustTag(t *testing.T) {
@ -126,9 +127,9 @@ tag3 bbbbbbbb
testcase.context.Output = out testcase.context.Output = out
err := TrustTagWrite(testcase.context, signedTags) err := TrustTagWrite(testcase.context, signedTags)
if err != nil { if err != nil {
assert.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -152,8 +153,8 @@ func TestTrustTagContextEmptyWrite(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
emptyCase.context.Output = out emptyCase.context.Output = out
err := TrustTagWrite(emptyCase.context, emptySignedTags) err := TrustTagWrite(emptyCase.context, emptySignedTags)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, emptyCase.expected, out.String()) assert.Check(t, is.Equal(emptyCase.expected, out.String()))
} }
func TestSignerInfoContextEmptyWrite(t *testing.T) { func TestSignerInfoContextEmptyWrite(t *testing.T) {
@ -171,8 +172,8 @@ func TestSignerInfoContextEmptyWrite(t *testing.T) {
out := bytes.NewBufferString("") out := bytes.NewBufferString("")
emptyCase.context.Output = out emptyCase.context.Output = out
err := SignerInfoWrite(emptyCase.context, emptySignerInfo) err := SignerInfoWrite(emptyCase.context, emptySignerInfo)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, emptyCase.expected, out.String()) assert.Check(t, is.Equal(emptyCase.expected, out.String()))
} }
func TestSignerInfoContextWrite(t *testing.T) { func TestSignerInfoContextWrite(t *testing.T) {
@ -230,9 +231,9 @@ eve foobarbazquxquux, key31, key32
testcase.context.Output = out testcase.context.Output = out
err := SignerInfoWrite(testcase.context, signerInfo) err := SignerInfoWrite(testcase.context, signerInfo)
if err != nil { if err != nil {
assert.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }

View File

@ -9,8 +9,8 @@ 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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestVolumeContext(t *testing.T) { func TestVolumeContext(t *testing.T) {
@ -133,9 +133,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.EqualError(t, err, testcase.expected) assert.Check(t, is.Error(err, testcase.expected))
} else { } else {
assert.Equal(t, testcase.expected, out.String()) assert.Check(t, is.Equal(testcase.expected, out.String()))
} }
} }
} }
@ -158,8 +158,8 @@ func TestVolumeContextWriteJSON(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var m map[string]interface{} var m map[string]interface{}
err := json.Unmarshal([]byte(line), &m) err := json.Unmarshal([]byte(line), &m)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, expectedJSONs[i], m, msg) assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
} }
} }
@ -177,7 +177,7 @@ func TestVolumeContextWriteJSONField(t *testing.T) {
msg := fmt.Sprintf("Output: line %d: %s", i, line) msg := fmt.Sprintf("Output: line %d: %s", i, line)
var s string var s string
err := json.Unmarshal([]byte(line), &s) err := json.Unmarshal([]byte(line), &s)
require.NoError(t, err, msg) assert.NilError(t, err, msg)
assert.Equal(t, volumes[i].Name, s, msg) assert.Check(t, is.Equal(volumes[i].Name, s), msg)
} }
} }

View File

@ -4,10 +4,11 @@ import (
"testing" "testing"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"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 +22,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.EqualError(t, err, "unsupported type") assert.Check(t, is.Error(err, "unsupported type"))
} }
func TestResolveWithNoResolveOption(t *testing.T) { func TestResolveWithNoResolveOption(t *testing.T) {
@ -40,9 +41,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.NoError(t, err) assert.Check(t, err)
assert.Equal(t, "nodeID", id) assert.Check(t, is.Equal("nodeID", id))
assert.False(t, resolved) assert.Check(t, !resolved)
} }
func TestResolveWithCache(t *testing.T) { func TestResolveWithCache(t *testing.T) {
@ -59,11 +60,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.NoError(t, err) assert.Check(t, err)
assert.Equal(t, "node-foo", id) assert.Check(t, is.Equal("node-foo", id))
} }
assert.Equal(t, 1, inspectCounter) assert.Check(t, is.Equal(1, inspectCounter))
} }
func TestResolveNode(t *testing.T) { func TestResolveNode(t *testing.T) {
@ -103,8 +104,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.NoError(t, err) assert.Check(t, err)
assert.Equal(t, tc.expectedID, id) assert.Check(t, is.Equal(tc.expectedID, id))
} }
} }
@ -138,7 +139,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.NoError(t, err) assert.Check(t, err)
assert.Equal(t, tc.expectedID, id) assert.Check(t, is.Equal(tc.expectedID, id))
} }
} }

View File

@ -13,8 +13,8 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
const dockerfileContents = "FROM busybox" const dockerfileContents = "FROM busybox"
@ -38,7 +38,7 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (stri
defer cleanup() defer cleanup()
err := ValidateContextDirectory(contextDir, excludes) err := ValidateContextDirectory(contextDir, excludes)
require.NoError(t, err) assert.NilError(t, err)
} }
func TestGetContextFromLocalDirNoDockerfile(t *testing.T) { func TestGetContextFromLocalDirNoDockerfile(t *testing.T) {
@ -79,10 +79,10 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
defer chdirCleanup() defer chdirCleanup()
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, contextDir, absContextDir) assert.Check(t, is.Equal(contextDir, absContextDir))
assert.Equal(t, DefaultDockerfileName, relDockerfile) assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
} }
func TestGetContextFromLocalDirWithDockerfile(t *testing.T) { func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
@ -92,10 +92,10 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "") absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, contextDir, absContextDir) assert.Check(t, is.Equal(contextDir, absContextDir))
assert.Equal(t, DefaultDockerfileName, relDockerfile) assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
} }
func TestGetContextFromLocalDirLocalFile(t *testing.T) { func TestGetContextFromLocalDirLocalFile(t *testing.T) {
@ -130,10 +130,10 @@ func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName) absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, contextDir, absContextDir) assert.Check(t, is.Equal(contextDir, absContextDir))
assert.Equal(t, DefaultDockerfileName, relDockerfile) assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
} }
func TestGetContextFromReaderString(t *testing.T) { func TestGetContextFromReaderString(t *testing.T) {
@ -161,7 +161,7 @@ func TestGetContextFromReaderString(t *testing.T) {
t.Fatalf("Tar stream too long: %s", err) t.Fatalf("Tar stream too long: %s", err)
} }
require.NoError(t, tarArchive.Close()) assert.NilError(t, tarArchive.Close())
if dockerfileContents != contents { if dockerfileContents != contents {
t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents) t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents)
@ -179,15 +179,15 @@ func TestGetContextFromReaderTar(t *testing.T) {
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777) createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
tarStream, err := archive.Tar(contextDir, archive.Uncompressed) tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
require.NoError(t, err) assert.NilError(t, err)
tarArchive, relDockerfile, err := GetContextFromReader(tarStream, DefaultDockerfileName) tarArchive, relDockerfile, err := GetContextFromReader(tarStream, DefaultDockerfileName)
require.NoError(t, err) assert.NilError(t, err)
tarReader := tar.NewReader(tarArchive) tarReader := tar.NewReader(tarArchive)
header, err := tarReader.Next() header, err := tarReader.Next()
require.NoError(t, err) assert.NilError(t, err)
if header.Name != DefaultDockerfileName { if header.Name != DefaultDockerfileName {
t.Fatalf("Dockerfile name should be: %s, got: %s", DefaultDockerfileName, header.Name) t.Fatalf("Dockerfile name should be: %s, got: %s", DefaultDockerfileName, header.Name)
@ -203,7 +203,7 @@ func TestGetContextFromReaderTar(t *testing.T) {
t.Fatalf("Tar stream too long: %s", err) t.Fatalf("Tar stream too long: %s", err)
} }
require.NoError(t, tarArchive.Close()) assert.NilError(t, tarArchive.Close())
if dockerfileContents != contents { if dockerfileContents != contents {
t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents) t.Fatalf("Uncompressed tar archive does not equal: %s, got: %s", dockerfileContents, contents)
@ -243,8 +243,8 @@ func TestValidateContextDirectoryWithOneFileExcludes(t *testing.T) {
// When an error occurs, it terminates the test. // When an error occurs, it terminates the test.
func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) { func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
path, err := ioutil.TempDir(dir, prefix) path, err := ioutil.TempDir(dir, prefix)
require.NoError(t, err) assert.NilError(t, err)
return path, func() { require.NoError(t, os.RemoveAll(path)) } return path, func() { assert.NilError(t, os.RemoveAll(path)) }
} }
// createTestTempFile creates a temporary file within dir with specific contents and permissions. // createTestTempFile creates a temporary file within dir with specific contents and permissions.
@ -252,7 +252,7 @@ func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string { func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.FileMode) string {
filePath := filepath.Join(dir, filename) filePath := filepath.Join(dir, filename)
err := ioutil.WriteFile(filePath, []byte(contents), perm) err := ioutil.WriteFile(filePath, []byte(contents), perm)
require.NoError(t, err) assert.NilError(t, err)
return filePath return filePath
} }
@ -262,9 +262,9 @@ func createTestTempFile(t *testing.T, dir, filename, contents string, perm os.Fi
// When an error occurs, it terminates the test. // When an error occurs, it terminates the test.
func chdir(t *testing.T, dir string) func() { func chdir(t *testing.T, dir string) func() {
workingDirectory, err := os.Getwd() workingDirectory, err := os.Getwd()
require.NoError(t, err) assert.NilError(t, err)
require.NoError(t, os.Chdir(dir)) assert.NilError(t, os.Chdir(dir))
return func() { require.NoError(t, os.Chdir(workingDirectory)) } return func() { assert.NilError(t, os.Chdir(workingDirectory)) }
} }
func TestIsArchive(t *testing.T) { func TestIsArchive(t *testing.T) {
@ -295,6 +295,6 @@ func TestIsArchive(t *testing.T) {
}, },
} }
for _, testcase := range testcases { for _, testcase := range testcases {
assert.Equal(t, testcase.expected, IsArchive(testcase.header), testcase.doc) assert.Check(t, is.Equal(testcase.expected, IsArchive(testcase.header)), testcase.doc)
} }
} }

View File

@ -15,10 +15,10 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/gotestyourself/gotestyourself/skip" "github.com/gotestyourself/gotestyourself/skip"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -28,7 +28,7 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
defer dest.Remove() defer dest.Remove()
fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) { fakeImageBuild := func(_ context.Context, context io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error) {
assert.NoError(t, archive.Untar(context, dest.Path(), nil)) assert.Check(t, archive.Untar(context, dest.Path(), nil))
body := new(bytes.Buffer) body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
@ -48,18 +48,18 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
options.context = dir.Path() options.context = dir.Path()
err := runBuild(cli, options) err := runBuild(cli, options)
require.NoError(t, err) assert.NilError(t, err)
files, err := ioutil.ReadDir(dest.Path()) files, err := ioutil.ReadDir(dest.Path())
require.NoError(t, err) assert.NilError(t, err)
for _, fileInfo := range files { for _, fileInfo := range files {
assert.Equal(t, uint32(0), fileInfo.Sys().(*syscall.Stat_t).Uid) assert.Check(t, is.Equal(uint32(0), fileInfo.Sys().(*syscall.Stat_t).Uid))
assert.Equal(t, uint32(0), fileInfo.Sys().(*syscall.Stat_t).Gid) assert.Check(t, is.Equal(uint32(0), fileInfo.Sys().(*syscall.Stat_t).Gid))
} }
} }
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) { func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
dest, err := ioutil.TempDir("", "test-build-compress-dest") dest, err := ioutil.TempDir("", "test-build-compress-dest")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(dest) defer os.RemoveAll(dest)
var dockerfileName string var dockerfileName string
@ -67,11 +67,11 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
tee := io.TeeReader(context, buffer) tee := io.TeeReader(context, buffer)
assert.NoError(t, archive.Untar(tee, dest, nil)) assert.Check(t, archive.Untar(tee, dest, nil))
dockerfileName = options.Dockerfile dockerfileName = options.Dockerfile
header := buffer.Bytes()[:10] header := buffer.Bytes()[:10]
assert.Equal(t, archive.Gzip, archive.DetectCompression(header)) assert.Check(t, is.Equal(archive.Gzip, archive.DetectCompression(header)))
body := new(bytes.Buffer) body := new(bytes.Buffer)
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
@ -85,7 +85,7 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
cli.SetIn(command.NewInStream(ioutil.NopCloser(dockerfile))) cli.SetIn(command.NewInStream(ioutil.NopCloser(dockerfile)))
dir, err := ioutil.TempDir("", "test-build-compress") dir, err := ioutil.TempDir("", "test-build-compress")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(dir) defer os.RemoveAll(dir)
ioutil.WriteFile(filepath.Join(dir, "foo"), []byte("some content"), 0644) ioutil.WriteFile(filepath.Join(dir, "foo"), []byte("some content"), 0644)
@ -96,16 +96,16 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
options.context = dir options.context = dir
err = runBuild(cli, options) err = runBuild(cli, options)
require.NoError(t, err) assert.NilError(t, err)
files, err := ioutil.ReadDir(dest) files, err := ioutil.ReadDir(dest)
require.NoError(t, err) assert.NilError(t, err)
actual := []string{} actual := []string{}
for _, fileInfo := range files { for _, fileInfo := range files {
actual = append(actual, fileInfo.Name()) actual = append(actual, fileInfo.Name())
} }
sort.Strings(actual) sort.Strings(actual)
assert.Equal(t, []string{dockerfileName, ".dockerignore", "foo"}, actual) assert.Check(t, is.DeepEqual([]string{dockerfileName, ".dockerignore", "foo"}, actual))
} }
func TestRunBuildDockerfileOutsideContext(t *testing.T) { func TestRunBuildDockerfileOutsideContext(t *testing.T) {
@ -124,7 +124,7 @@ COPY data /data
defer df.Remove() defer df.Remove()
dest, err := ioutil.TempDir("", t.Name()) dest, err := ioutil.TempDir("", t.Name())
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(dest) defer os.RemoveAll(dest)
var dockerfileName string var dockerfileName string
@ -132,7 +132,7 @@ COPY data /data
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
tee := io.TeeReader(context, buffer) tee := io.TeeReader(context, buffer)
assert.NoError(t, archive.Untar(tee, dest, nil)) assert.Check(t, archive.Untar(tee, dest, nil))
dockerfileName = options.Dockerfile dockerfileName = options.Dockerfile
body := new(bytes.Buffer) body := new(bytes.Buffer)
@ -146,16 +146,16 @@ COPY data /data
options.dockerfileName = df.Path() options.dockerfileName = df.Path()
err = runBuild(cli, options) err = runBuild(cli, options)
require.NoError(t, err) assert.NilError(t, err)
files, err := ioutil.ReadDir(dest) files, err := ioutil.ReadDir(dest)
require.NoError(t, err) assert.NilError(t, err)
var actual []string var actual []string
for _, fileInfo := range files { for _, fileInfo := range files {
actual = append(actual, fileInfo.Name()) actual = append(actual, fileInfo.Name())
} }
sort.Strings(actual) sort.Strings(actual)
assert.Equal(t, []string{dockerfileName, ".dockerignore", "data"}, actual) assert.Check(t, is.DeepEqual([]string{dockerfileName, ".dockerignore", "data"}, actual))
} }
// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that build contexts // TestRunBuildFromLocalGitHubDirNonExistingRepo tests that build contexts
@ -166,8 +166,8 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
cmd.SetArgs([]string{"github.com/docker/no-such-repository"}) cmd.SetArgs([]string{"github.com/docker/no-such-repository"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err := cmd.Execute() err := cmd.Execute()
assert.Error(t, err) assert.Check(t, is.ErrorContains(err, ""))
assert.Contains(t, err.Error(), "unable to prepare context: unable to 'git clone'") assert.Check(t, is.Contains(err.Error(), "unable to prepare context: unable to 'git clone'"))
} }
// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that a local directory // TestRunBuildFromLocalGitHubDirNonExistingRepo tests that a local directory
@ -175,19 +175,19 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
// case. // case.
func TestRunBuildFromLocalGitHubDir(t *testing.T) { func TestRunBuildFromLocalGitHubDir(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-build-from-local-dir-") tmpDir, err := ioutil.TempDir("", "docker-build-from-local-dir-")
require.NoError(t, err) assert.NilError(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
buildDir := filepath.Join(tmpDir, "github.com", "docker", "no-such-repository") buildDir := filepath.Join(tmpDir, "github.com", "docker", "no-such-repository")
err = os.MkdirAll(buildDir, 0777) err = os.MkdirAll(buildDir, 0777)
require.NoError(t, err) assert.NilError(t, err)
err = ioutil.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644) err = ioutil.WriteFile(filepath.Join(buildDir, "Dockerfile"), []byte("FROM busybox\n"), 0644)
require.NoError(t, err) assert.NilError(t, err)
client := test.NewFakeCli(&fakeClient{}) client := test.NewFakeCli(&fakeClient{})
cmd := NewBuildCommand(client) cmd := NewBuildCommand(client)
cmd.SetArgs([]string{buildDir}) cmd.SetArgs([]string{buildDir})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err = cmd.Execute() err = cmd.Execute()
require.NoError(t, err) assert.NilError(t, err)
} }

View File

@ -9,9 +9,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types/image" "github.com/docker/docker/api/types/image"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewHistoryCommandErrors(t *testing.T) { func TestNewHistoryCommandErrors(t *testing.T) {
@ -92,7 +92,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.Check(t, err)
actual := cli.OutBuffer().String() actual := cli.OutBuffer().String()
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name)) golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
} }

View File

@ -9,8 +9,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewImportCommandErrors(t *testing.T) { func TestNewImportCommandErrors(t *testing.T) {
@ -67,7 +68,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
name: "double", name: "double",
args: []string{"-", "image:local"}, args: []string{"-", "image:local"},
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) { imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
assert.Equal(t, "image:local", ref) assert.Check(t, is.Equal("image:local", ref))
return ioutil.NopCloser(strings.NewReader("")), nil return ioutil.NopCloser(strings.NewReader("")), nil
}, },
}, },
@ -75,7 +76,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
name: "message", name: "message",
args: []string{"--message", "test message", "-"}, args: []string{"--message", "test message", "-"},
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) { imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
assert.Equal(t, "test message", options.Message) assert.Check(t, is.Equal("test message", options.Message))
return ioutil.NopCloser(strings.NewReader("")), nil return ioutil.NopCloser(strings.NewReader("")), nil
}, },
}, },
@ -83,7 +84,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
name: "change", name: "change",
args: []string{"--change", "ENV DEBUG true", "-"}, args: []string{"--change", "ENV DEBUG true", "-"},
imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) { imageImportFunc: func(source types.ImageImportSource, ref string, options types.ImageImportOptions) (io.ReadCloser, error) {
assert.Equal(t, "ENV DEBUG true", options.Changes[0]) assert.Check(t, is.Equal("ENV DEBUG true", options.Changes[0]))
return ioutil.NopCloser(strings.NewReader("")), nil return ioutil.NopCloser(strings.NewReader("")), nil
}, },
}, },
@ -92,6 +93,6 @@ func TestNewImportCommandSuccess(t *testing.T) {
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc})) cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }
} }

View File

@ -8,8 +8,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestNewInspectCommandErrors(t *testing.T) { func TestNewInspectCommandErrors(t *testing.T) {
@ -46,7 +47,7 @@ func TestNewInspectCommandSuccess(t *testing.T) {
imageCount: 1, imageCount: 1,
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
assert.Equal(t, "image", image) assert.Check(t, is.Equal("image", image))
return types.ImageInspect{}, nil, nil return types.ImageInspect{}, nil, nil
}, },
}, },
@ -66,9 +67,9 @@ func TestNewInspectCommandSuccess(t *testing.T) {
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) { imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
imageInspectInvocationCount++ imageInspectInvocationCount++
if imageInspectInvocationCount == 1 { if imageInspectInvocationCount == 1 {
assert.Equal(t, "image1", image) assert.Check(t, is.Equal("image1", image))
} else { } else {
assert.Equal(t, "image2", image) assert.Check(t, is.Equal("image2", image))
} }
return types.ImageInspect{}, nil, nil return types.ImageInspect{}, nil, nil
}, },
@ -81,8 +82,8 @@ func TestNewInspectCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.Check(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("inspect-command-success.%s.golden", tc.name))
assert.Equal(t, imageInspectInvocationCount, tc.imageCount) assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount))
} }
} }

View File

@ -9,9 +9,10 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewImagesCommandErrors(t *testing.T) { func TestNewImagesCommandErrors(t *testing.T) {
@ -65,7 +66,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
name: "match-name", name: "match-name",
args: []string{"image"}, args: []string{"image"},
imageListFunc: func(options types.ImageListOptions) ([]types.ImageSummary, error) { imageListFunc: func(options types.ImageListOptions) ([]types.ImageSummary, error) {
assert.Equal(t, "image", options.Filters.Get("reference")[0]) assert.Check(t, is.Equal("image", options.Filters.Get("reference")[0]))
return []types.ImageSummary{{}}, nil return []types.ImageSummary{{}}, nil
}, },
}, },
@ -73,7 +74,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
name: "filters", name: "filters",
args: []string{"--filter", "name=value"}, args: []string{"--filter", "name=value"},
imageListFunc: func(options types.ImageListOptions) ([]types.ImageSummary, error) { imageListFunc: func(options types.ImageListOptions) ([]types.ImageSummary, error) {
assert.Equal(t, "value", options.Filters.Get("name")[0]) assert.Check(t, is.Equal("value", options.Filters.Get("name")[0]))
return []types.ImageSummary{{}}, nil return []types.ImageSummary{{}}, nil
}, },
}, },
@ -85,14 +86,14 @@ func TestNewImagesCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.Check(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("list-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("list-command-success.%s.golden", tc.name))
} }
} }
func TestNewListCommandAlias(t *testing.T) { func TestNewListCommandAlias(t *testing.T) {
cmd := newListCommand(test.NewFakeCli(&fakeClient{})) cmd := newListCommand(test.NewFakeCli(&fakeClient{}))
assert.True(t, cmd.HasAlias("images")) assert.Check(t, cmd.HasAlias("images"))
assert.True(t, cmd.HasAlias("list")) assert.Check(t, cmd.HasAlias("list"))
assert.False(t, cmd.HasAlias("other")) assert.Check(t, !cmd.HasAlias("other"))
} }

View File

@ -10,9 +10,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewLoadCommandErrors(t *testing.T) { func TestNewLoadCommandErrors(t *testing.T) {
@ -96,7 +96,7 @@ func TestNewLoadCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.Check(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("load-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("load-command-success.%s.golden", tc.name))
} }
} }

View File

@ -9,9 +9,10 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewPruneCommandErrors(t *testing.T) { func TestNewPruneCommandErrors(t *testing.T) {
@ -55,7 +56,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
name: "all", name: "all",
args: []string{"--all"}, args: []string{"--all"},
imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) { imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) {
assert.Equal(t, "false", pruneFilter.Get("dangling")[0]) assert.Check(t, is.Equal("false", pruneFilter.Get("dangling")[0]))
return types.ImagesPruneReport{}, nil return types.ImagesPruneReport{}, nil
}, },
}, },
@ -63,7 +64,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
name: "force-deleted", name: "force-deleted",
args: []string{"--force"}, args: []string{"--force"},
imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) { imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) {
assert.Equal(t, "true", pruneFilter.Get("dangling")[0]) assert.Check(t, is.Equal("true", pruneFilter.Get("dangling")[0]))
return types.ImagesPruneReport{ return types.ImagesPruneReport{
ImagesDeleted: []types.ImageDeleteResponseItem{{Deleted: "image1"}}, ImagesDeleted: []types.ImageDeleteResponseItem{{Deleted: "image1"}},
SpaceReclaimed: 1, SpaceReclaimed: 1,
@ -74,7 +75,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
name: "force-untagged", name: "force-untagged",
args: []string{"--force"}, args: []string{"--force"},
imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) { imagesPruneFunc: func(pruneFilter filters.Args) (types.ImagesPruneReport, error) {
assert.Equal(t, "true", pruneFilter.Get("dangling")[0]) assert.Check(t, is.Equal("true", pruneFilter.Get("dangling")[0]))
return types.ImagesPruneReport{ return types.ImagesPruneReport{
ImagesDeleted: []types.ImageDeleteResponseItem{{Untagged: "image1"}}, ImagesDeleted: []types.ImageDeleteResponseItem{{Untagged: "image1"}},
SpaceReclaimed: 2, SpaceReclaimed: 2,
@ -88,7 +89,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.Check(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("prune-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("prune-command-success.%s.golden", tc.name))
} }
} }

View File

@ -10,8 +10,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestNewPullCommandErrors(t *testing.T) { func TestNewPullCommandErrors(t *testing.T) {
@ -65,7 +66,7 @@ func TestNewPullCommandSuccess(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) { imagePullFunc: func(ref string, options types.ImagePullOptions) (io.ReadCloser, error) {
assert.Equal(t, tc.expectedTag, ref, tc.name) assert.Check(t, is.Equal(tc.expectedTag, ref), tc.name)
return ioutil.NopCloser(strings.NewReader("")), nil return ioutil.NopCloser(strings.NewReader("")), nil
}, },
}) })
@ -73,7 +74,7 @@ func TestNewPullCommandSuccess(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
err := cmd.Execute() err := cmd.Execute()
assert.NoError(t, err) assert.Check(t, err)
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("pull-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("pull-command-success.%s.golden", tc.name))
} }
} }

View File

@ -9,8 +9,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNewPushCommandErrors(t *testing.T) { func TestNewPushCommandErrors(t *testing.T) {
@ -72,6 +72,6 @@ func TestNewPushCommandSuccess(t *testing.T) {
cmd := NewPushCommand(cli) cmd := NewPushCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }
} }

View File

@ -8,9 +8,10 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
type notFound struct { type notFound struct {
@ -27,9 +28,9 @@ func (n notFound) NotFound() bool {
func TestNewRemoveCommandAlias(t *testing.T) { func TestNewRemoveCommandAlias(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{})) cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
assert.True(t, cmd.HasAlias("rmi")) assert.Check(t, cmd.HasAlias("rmi"))
assert.True(t, cmd.HasAlias("remove")) assert.Check(t, cmd.HasAlias("remove"))
assert.False(t, cmd.HasAlias("other")) assert.Check(t, !cmd.HasAlias("other"))
} }
func TestNewRemoveCommandErrors(t *testing.T) { func TestNewRemoveCommandErrors(t *testing.T) {
@ -48,7 +49,7 @@ func TestNewRemoveCommandErrors(t *testing.T) {
args: []string{"-f", "image1"}, args: []string{"-f", "image1"},
expectedError: "error removing image", expectedError: "error removing image",
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image) assert.Check(t, is.Equal("image1", image))
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image") return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
}, },
}, },
@ -57,8 +58,8 @@ func TestNewRemoveCommandErrors(t *testing.T) {
args: []string{"arg1"}, args: []string{"arg1"},
expectedError: "error removing image", expectedError: "error removing image",
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.False(t, options.Force) assert.Check(t, !options.Force)
assert.True(t, options.PruneChildren) assert.Check(t, options.PruneChildren)
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image") return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
}, },
}, },
@ -86,7 +87,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name: "Image Deleted", name: "Image Deleted",
args: []string{"image1"}, args: []string{"image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image) assert.Check(t, is.Equal("image1", image))
return []types.ImageDeleteResponseItem{{Deleted: image}}, nil return []types.ImageDeleteResponseItem{{Deleted: image}}, nil
}, },
}, },
@ -94,8 +95,8 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name: "Image not found with force option", name: "Image not found with force option",
args: []string{"-f", "image1"}, args: []string{"-f", "image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image) assert.Check(t, is.Equal("image1", image))
assert.Equal(t, true, options.Force) assert.Check(t, is.Equal(true, options.Force))
return []types.ImageDeleteResponseItem{}, notFound{"image1"} return []types.ImageDeleteResponseItem{}, notFound{"image1"}
}, },
expectedStderr: "Error: No such image: image1\n", expectedStderr: "Error: No such image: image1\n",
@ -105,7 +106,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
name: "Image Untagged", name: "Image Untagged",
args: []string{"image1"}, args: []string{"image1"},
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) { imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
assert.Equal(t, "image1", image) assert.Check(t, is.Equal("image1", image))
return []types.ImageDeleteResponseItem{{Untagged: image}}, nil return []types.ImageDeleteResponseItem{{Untagged: image}}, nil
}, },
}, },
@ -126,8 +127,8 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
cmd := NewRemoveCommand(cli) cmd := NewRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, tc.expectedStderr, cli.ErrBuffer().String()) assert.Check(t, is.Equal(tc.expectedStderr, cli.ErrBuffer().String()))
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("remove-command-success.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("remove-command-success.%s.golden", tc.name))
}) })
} }

View File

@ -9,9 +9,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestNewSaveCommandErrors(t *testing.T) { func TestNewSaveCommandErrors(t *testing.T) {
@ -69,8 +69,8 @@ func TestNewSaveCommandSuccess(t *testing.T) {
args: []string{"-o", "save_tmp_file", "arg1"}, args: []string{"-o", "save_tmp_file", "arg1"},
isTerminal: true, isTerminal: true,
imageSaveFunc: func(images []string) (io.ReadCloser, error) { imageSaveFunc: func(images []string) (io.ReadCloser, error) {
require.Len(t, images, 1) assert.Assert(t, is.Len(images, 1))
assert.Equal(t, "arg1", images[0]) assert.Check(t, is.Equal("arg1", images[0]))
return ioutil.NopCloser(strings.NewReader("")), nil return ioutil.NopCloser(strings.NewReader("")), nil
}, },
deferredFunc: func() { deferredFunc: func() {
@ -81,9 +81,9 @@ func TestNewSaveCommandSuccess(t *testing.T) {
args: []string{"arg1", "arg2"}, args: []string{"arg1", "arg2"},
isTerminal: false, isTerminal: false,
imageSaveFunc: func(images []string) (io.ReadCloser, error) { imageSaveFunc: func(images []string) (io.ReadCloser, error) {
require.Len(t, images, 2) assert.Assert(t, is.Len(images, 2))
assert.Equal(t, "arg1", images[0]) assert.Check(t, is.Equal("arg1", images[0]))
assert.Equal(t, "arg2", images[1]) assert.Check(t, is.Equal("arg2", images[1]))
return ioutil.NopCloser(strings.NewReader("")), nil return ioutil.NopCloser(strings.NewReader("")), nil
}, },
}, },
@ -96,7 +96,7 @@ func TestNewSaveCommandSuccess(t *testing.T) {
})) }))
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
if tc.deferredFunc != nil { if tc.deferredFunc != nil {
tc.deferredFunc() tc.deferredFunc()
} }

View File

@ -6,7 +6,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestCliNewTagCommandErrors(t *testing.T) { func TestCliNewTagCommandErrors(t *testing.T) {
@ -28,14 +29,14 @@ func TestCliNewTagCommand(t *testing.T) {
cmd := NewTagCommand( cmd := NewTagCommand(
test.NewFakeCli(&fakeClient{ test.NewFakeCli(&fakeClient{
imageTagFunc: func(image string, ref string) error { imageTagFunc: func(image string, ref string) error {
assert.Equal(t, "image1", image) assert.Check(t, is.Equal("image1", image))
assert.Equal(t, "image2", ref) assert.Check(t, is.Equal("image2", ref))
return nil return nil
}, },
})) }))
cmd.SetArgs([]string{"image1", "image2"}) cmd.SetArgs([]string{"image1", "image2"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
value, _ := cmd.Flags().GetBool("interspersed") value, _ := cmd.Flags().GetBool("interspersed")
assert.False(t, value) assert.Check(t, !value)
} }

View File

@ -8,8 +8,8 @@ import (
"github.com/docker/cli/cli/trust" "github.com/docker/cli/cli/trust"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/theupdateframework/notary/client" "github.com/theupdateframework/notary/client"
"github.com/theupdateframework/notary/passphrase" "github.com/theupdateframework/notary/passphrase"
"github.com/theupdateframework/notary/trustpinning" "github.com/theupdateframework/notary/trustpinning"
@ -64,12 +64,12 @@ func TestNonOfficialTrustServer(t *testing.T) {
func TestAddTargetToAllSignableRolesError(t *testing.T) { func TestAddTargetToAllSignableRolesError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "notary-test-") tmpDir, err := ioutil.TempDir("", "notary-test-")
assert.NoError(t, err) assert.Check(t, err)
defer os.RemoveAll(tmpDir) defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{}) notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
require.NoError(t, err) assert.NilError(t, err)
target := client.Target{} target := client.Target{}
err = AddTargetToAllSignableRoles(notaryRepo, &target) err = AddTargetToAllSignableRoles(notaryRepo, &target)
assert.EqualError(t, err, "client is offline") assert.Check(t, is.Error(err, "client is offline"))
} }

View File

@ -6,8 +6,8 @@ import (
"testing" "testing"
"github.com/docker/cli/templates" "github.com/docker/cli/templates"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
type testElement struct { type testElement struct {
@ -243,17 +243,17 @@ func TestTemplateInspectorRawFallbackNumber(t *testing.T) {
} }
b := new(bytes.Buffer) b := new(bytes.Buffer)
tmpl, err := templates.Parse("{{.Size}} {{.Id}}") tmpl, err := templates.Parse("{{.Size}} {{.Id}}")
require.NoError(t, err) assert.NilError(t, err)
i := NewTemplateInspector(b, tmpl) i := NewTemplateInspector(b, tmpl)
for _, tc := range testcases { for _, tc := range testcases {
err = i.Inspect(typedElem, tc.raw) err = i.Inspect(typedElem, tc.raw)
require.NoError(t, err) assert.NilError(t, err)
err = i.Flush() err = i.Flush()
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, tc.exp, b.String()) assert.Check(t, is.Equal(tc.exp, b.String()))
b.Reset() b.Reset()
} }
} }

View File

@ -6,9 +6,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestManifestAnnotateError(t *testing.T) { func TestManifestAnnotateError(t *testing.T) {
@ -48,7 +48,7 @@ func TestManifestAnnotate(t *testing.T) {
namedRef := ref(t, "alpine:3.0") namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef) imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest) err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err) assert.NilError(t, err)
cmd := newAnnotateCommand(cli) cmd := newAnnotateCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/fake:0.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/fake:0.0"})
@ -65,14 +65,14 @@ func TestManifestAnnotate(t *testing.T) {
testutil.ErrorContains(t, cmd.Execute(), expectedError) testutil.ErrorContains(t, cmd.Execute(), expectedError)
cmd.Flags().Set("arch", "arm") cmd.Flags().Set("arch", "arm")
require.NoError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
cmd = newInspectCommand(cli) cmd = newInspectCommand(cli)
err = cmd.Flags().Set("verbose", "true") err = cmd.Flags().Set("verbose", "true")
require.NoError(t, err) assert.NilError(t, err)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
require.NoError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
actual := cli.OutBuffer() actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-annotate.golden") expected := golden.Get(t, "inspect-annotate.golden")
assert.Equal(t, string(expected), actual.String()) assert.Check(t, is.Equal(string(expected), actual.String()))
} }

View File

@ -8,10 +8,10 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -50,28 +50,28 @@ func TestManifestCreateAmend(t *testing.T) {
namedRef := ref(t, "alpine:3.0") namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef) imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest) err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err) assert.NilError(t, err)
namedRef = ref(t, "alpine:3.1") namedRef = ref(t, "alpine:3.1")
imageManifest = fullImageManifest(t, namedRef) imageManifest = fullImageManifest(t, namedRef)
err = store.Save(ref(t, "list:v1"), namedRef, imageManifest) err = store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err) assert.NilError(t, err)
cmd := newCreateListCommand(cli) cmd := newCreateListCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.1"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.1"})
cmd.Flags().Set("amend", "true") cmd.Flags().Set("amend", "true")
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err = cmd.Execute() err = cmd.Execute()
require.NoError(t, err) assert.NilError(t, err)
// make a new cli to clear the buffers // make a new cli to clear the buffers
cli = test.NewFakeCli(nil) cli = test.NewFakeCli(nil)
cli.SetManifestStore(store) cli.SetManifestStore(store)
inspectCmd := newInspectCommand(cli) inspectCmd := newInspectCommand(cli)
inspectCmd.SetArgs([]string{"example.com/list:v1"}) inspectCmd.SetArgs([]string{"example.com/list:v1"})
require.NoError(t, inspectCmd.Execute()) assert.NilError(t, inspectCmd.Execute())
actual := cli.OutBuffer() actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-manifest-list.golden") expected := golden.Get(t, "inspect-manifest-list.golden")
assert.Equal(t, string(expected), actual.String()) assert.Check(t, is.Equal(string(expected), actual.String()))
} }
// attempt to overwrite a saved manifest and get refused // attempt to overwrite a saved manifest and get refused
@ -84,13 +84,13 @@ func TestManifestCreateRefuseAmend(t *testing.T) {
namedRef := ref(t, "alpine:3.0") namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef) imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest) err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err) assert.NilError(t, err)
cmd := newCreateListCommand(cli) cmd := newCreateListCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err = cmd.Execute() err = cmd.Execute()
assert.EqualError(t, err, "refusing to amend an existing manifest list with no --amend flag") assert.Check(t, is.Error(err, "refusing to amend an existing manifest list with no --amend flag"))
} }
// attempt to make a manifest list without valid images // attempt to make a manifest list without valid images
@ -113,5 +113,5 @@ func TestManifestCreateNoManifest(t *testing.T) {
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
err := cmd.Execute() err := cmd.Execute()
assert.EqualError(t, err, "No such image: example.com/alpine:3.0") assert.Check(t, is.Error(err, "No such image: example.com/alpine:3.0"))
} }

View File

@ -12,24 +12,24 @@ import (
"github.com/docker/distribution" "github.com/docker/distribution"
"github.com/docker/distribution/manifest/schema2" "github.com/docker/distribution/manifest/schema2"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/opencontainers/go-digest" "github.com/opencontainers/go-digest"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
func newTempManifestStore(t *testing.T) (store.Store, func()) { func newTempManifestStore(t *testing.T) (store.Store, func()) {
tmpdir, err := ioutil.TempDir("", "test-manifest-storage") tmpdir, err := ioutil.TempDir("", "test-manifest-storage")
require.NoError(t, err) assert.NilError(t, err)
return store.NewStore(tmpdir), func() { os.RemoveAll(tmpdir) } return store.NewStore(tmpdir), func() { os.RemoveAll(tmpdir) }
} }
func ref(t *testing.T, name string) reference.Named { func ref(t *testing.T, name string) reference.Named {
named, err := reference.ParseNamed("example.com/" + name) named, err := reference.ParseNamed("example.com/" + name)
require.NoError(t, err) assert.NilError(t, err)
return named return named
} }
@ -49,7 +49,7 @@ func fullImageManifest(t *testing.T, ref reference.Named) types.ImageManifest {
}, },
}, },
}) })
require.NoError(t, err) assert.NilError(t, err)
// TODO: include image data for verbose inspect // TODO: include image data for verbose inspect
return types.NewImageManifest(ref, digest.Digest("sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd"), types.Image{OS: "linux", Architecture: "amd64"}, man) return types.NewImageManifest(ref, digest.Digest("sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d62abcd"), types.Image{OS: "linux", Architecture: "amd64"}, man)
} }
@ -65,7 +65,7 @@ func TestInspectCommandLocalManifestNotFound(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
err := cmd.Execute() err := cmd.Execute()
assert.EqualError(t, err, "No such manifest: example.com/alpine:3.0") assert.Check(t, is.Error(err, "No such manifest: example.com/alpine:3.0"))
} }
func TestInspectCommandNotFound(t *testing.T) { func TestInspectCommandNotFound(t *testing.T) {
@ -87,7 +87,7 @@ func TestInspectCommandNotFound(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/alpine:3.0"})
err := cmd.Execute() err := cmd.Execute()
assert.EqualError(t, err, "No such manifest: example.com/alpine:3.0") assert.Check(t, is.Error(err, "No such manifest: example.com/alpine:3.0"))
} }
func TestInspectCommandLocalManifest(t *testing.T) { func TestInspectCommandLocalManifest(t *testing.T) {
@ -99,14 +99,14 @@ func TestInspectCommandLocalManifest(t *testing.T) {
namedRef := ref(t, "alpine:3.0") namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef) imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest) err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err) assert.NilError(t, err)
cmd := newInspectCommand(cli) cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
require.NoError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
actual := cli.OutBuffer() actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-manifest.golden") expected := golden.Get(t, "inspect-manifest.golden")
assert.Equal(t, string(expected), actual.String()) assert.Check(t, is.Equal(string(expected), actual.String()))
} }
func TestInspectcommandRemoteManifest(t *testing.T) { func TestInspectcommandRemoteManifest(t *testing.T) {
@ -124,8 +124,8 @@ func TestInspectcommandRemoteManifest(t *testing.T) {
cmd := newInspectCommand(cli) cmd := newInspectCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"example.com/alpine:3.0"}) cmd.SetArgs([]string{"example.com/alpine:3.0"})
require.NoError(t, cmd.Execute()) assert.NilError(t, cmd.Execute())
actual := cli.OutBuffer() actual := cli.OutBuffer()
expected := golden.Get(t, "inspect-manifest.golden") expected := golden.Get(t, "inspect-manifest.golden")
assert.Equal(t, string(expected), actual.String()) assert.Check(t, is.Equal(string(expected), actual.String()))
} }

View File

@ -8,13 +8,13 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/distribution/reference" "github.com/docker/distribution/reference"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/require"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
func newFakeRegistryClient(t *testing.T) *fakeRegistryClient { func newFakeRegistryClient(t *testing.T) *fakeRegistryClient {
require.NoError(t, nil) assert.NilError(t, nil)
return &fakeRegistryClient{ return &fakeRegistryClient{
getManifestFunc: func(_ context.Context, _ reference.Named) (manifesttypes.ImageManifest, error) { getManifestFunc: func(_ context.Context, _ reference.Named) (manifesttypes.ImageManifest, error) {
@ -64,10 +64,10 @@ func TestManifestPush(t *testing.T) {
namedRef := ref(t, "alpine:3.0") namedRef := ref(t, "alpine:3.0")
imageManifest := fullImageManifest(t, namedRef) imageManifest := fullImageManifest(t, namedRef)
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest) err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
require.NoError(t, err) assert.NilError(t, err)
cmd := newPushListCommand(cli) cmd := newPushListCommand(cli)
cmd.SetArgs([]string{"example.com/list:v1"}) cmd.SetArgs([]string{"example.com/list:v1"})
err = cmd.Execute() err = cmd.Execute()
require.NoError(t, err) assert.NilError(t, err)
} }

View File

@ -7,8 +7,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types/network" "github.com/docker/docker/api/types/network"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -54,7 +55,7 @@ func TestNetworkConnectWithFlags(t *testing.T) {
} }
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error { networkConnectFunc: func(ctx context.Context, networkID, container string, config *network.EndpointSettings) error {
assert.Equal(t, expectedOpts, config.IPAMConfig, "not expected driver error") assert.Check(t, is.DeepEqual(expectedOpts, config.IPAMConfig), "not expected driver error")
return nil return nil
}, },
}) })
@ -66,5 +67,5 @@ func TestNetworkConnectWithFlags(t *testing.T) {
cmd.Flags().Set("ip-range", "192.168.4.0/24") cmd.Flags().Set("ip-range", "192.168.4.0/24")
cmd.Flags().Set("gateway", "192.168.4.1/24") cmd.Flags().Set("gateway", "192.168.4.1/24")
cmd.Flags().Set("subnet", "192.168.4.0/24") cmd.Flags().Set("subnet", "192.168.4.0/24")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }

View File

@ -9,9 +9,9 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -136,7 +136,7 @@ func TestNetworkCreateErrors(t *testing.T) {
) )
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
for key, value := range tc.flags { for key, value := range tc.flags {
require.NoError(t, cmd.Flags().Set(key, value)) assert.NilError(t, cmd.Flags().Set(key, value))
} }
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError) testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
@ -155,8 +155,8 @@ func TestNetworkCreateWithFlags(t *testing.T) {
} }
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
networkCreateFunc: func(ctx context.Context, name string, createBody types.NetworkCreate) (types.NetworkCreateResponse, error) { networkCreateFunc: func(ctx context.Context, name string, createBody types.NetworkCreate) (types.NetworkCreateResponse, error) {
assert.Equal(t, expectedDriver, createBody.Driver, "not expected driver error") assert.Check(t, is.Equal(expectedDriver, createBody.Driver), "not expected driver error")
assert.Equal(t, expectedOpts, createBody.IPAM.Config, "not expected driver error") assert.Check(t, is.DeepEqual(expectedOpts, createBody.IPAM.Config), "not expected driver error")
return types.NetworkCreateResponse{ return types.NetworkCreateResponse{
ID: name, ID: name,
}, nil }, nil
@ -170,6 +170,6 @@ func TestNetworkCreateWithFlags(t *testing.T) {
cmd.Flags().Set("ip-range", "192.168.4.0/24") cmd.Flags().Set("ip-range", "192.168.4.0/24")
cmd.Flags().Set("gateway", "192.168.4.1/24") cmd.Flags().Set("gateway", "192.168.4.1/24")
cmd.Flags().Set("subnet", "192.168.4.0/24") cmd.Flags().Set("subnet", "192.168.4.0/24")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "banana", strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("banana", strings.TrimSpace(cli.OutBuffer().String())))
} }

View File

@ -12,9 +12,10 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -54,7 +55,7 @@ func TestNetworkListWithFlags(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{ cli := test.NewFakeCli(&fakeClient{
networkListFunc: func(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) { networkListFunc: func(ctx context.Context, options types.NetworkListOptions) ([]types.NetworkResource, error) {
assert.Equal(t, expectedOpts, options, "not expected options error") assert.Check(t, is.DeepEqual(expectedOpts, options), "not expected options error")
return []types.NetworkResource{*NetworkResource(NetworkResourceID("123454321"), return []types.NetworkResource{*NetworkResource(NetworkResourceID("123454321"),
NetworkResourceName("network_1"), NetworkResourceName("network_1"),
NetworkResourceDriver("09.7.01"), NetworkResourceDriver("09.7.01"),
@ -64,6 +65,6 @@ func TestNetworkListWithFlags(t *testing.T) {
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("filter", "image.name=ubuntu") cmd.Flags().Set("filter", "image.name=ubuntu")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, strings.TrimSpace(cli.OutBuffer().String()), "network-list.golden") golden.Assert(t, strings.TrimSpace(cli.OutBuffer().String()), "network-list.golden")
} }

View File

@ -6,11 +6,11 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
"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/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
) )
func TestNodeDemoteErrors(t *testing.T) { func TestNodeDemoteErrors(t *testing.T) {
@ -64,7 +64,7 @@ func TestNodeDemoteNoChange(t *testing.T) {
}, },
})) }))
cmd.SetArgs([]string{"nodeID"}) cmd.SetArgs([]string{"nodeID"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }
func TestNodeDemoteMultipleNode(t *testing.T) { func TestNodeDemoteMultipleNode(t *testing.T) {
@ -81,5 +81,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
}, },
})) }))
cmd.SetArgs([]string{"nodeID1", "nodeID2"}) cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }

View File

@ -12,8 +12,8 @@ import (
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestNodeInspectErrors(t *testing.T) { func TestNodeInspectErrors(t *testing.T) {
@ -113,7 +113,7 @@ func TestNodeInspectPretty(t *testing.T) {
cmd := newInspectCommand(cli) cmd := newInspectCommand(cli)
cmd.SetArgs([]string{"nodeID"}) cmd.SetArgs([]string{"nodeID"})
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-inspect-pretty.%s.golden", tc.name))
} }
} }

View File

@ -8,11 +8,12 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"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/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/stretchr/testify/assert"
) )
func TestNodeListErrorOnAPIFailure(t *testing.T) { func TestNodeListErrorOnAPIFailure(t *testing.T) {
@ -48,7 +49,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.EqualError(t, cmd.Execute(), tc.expectedError) assert.Check(t, is.Error(cmd.Execute(), tc.expectedError))
} }
} }
@ -71,7 +72,7 @@ func TestNodeList(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-sort.golden") golden.Assert(t, cli.OutBuffer().String(), "node-list-sort.golden")
} }
@ -85,8 +86,8 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, cli.OutBuffer().String(), "nodeID1\n") assert.Check(t, is.Equal(cli.OutBuffer().String(), "nodeID1\n"))
} }
func TestNodeListDefaultFormatFromConfig(t *testing.T) { func TestNodeListDefaultFormatFromConfig(t *testing.T) {
@ -110,7 +111,7 @@ func TestNodeListDefaultFormatFromConfig(t *testing.T) {
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}", NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-format-from-config.golden") golden.Assert(t, cli.OutBuffer().String(), "node-list-format-from-config.golden")
} }
@ -135,6 +136,6 @@ func TestNodeListFormat(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}") cmd.Flags().Set("format", "{{.Hostname}}: {{.ManagerStatus}}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "node-list-format-flag.golden") golden.Assert(t, cli.OutBuffer().String(), "node-list-format-flag.golden")
} }

View File

@ -6,11 +6,11 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
"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/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
) )
func TestNodePromoteErrors(t *testing.T) { func TestNodePromoteErrors(t *testing.T) {
@ -64,7 +64,7 @@ func TestNodePromoteNoChange(t *testing.T) {
}, },
})) }))
cmd.SetArgs([]string{"nodeID"}) cmd.SetArgs([]string{"nodeID"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }
func TestNodePromoteMultipleNode(t *testing.T) { func TestNodePromoteMultipleNode(t *testing.T) {
@ -81,5 +81,5 @@ func TestNodePromoteMultipleNode(t *testing.T) {
}, },
})) }))
cmd.SetArgs([]string{"nodeID1", "nodeID2"}) cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NoError(t, cmd.Execute()) assert.Check(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/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestNodePsErrors(t *testing.T) { func TestNodePsErrors(t *testing.T) {
@ -60,7 +61,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.EqualError(t, cmd.Execute(), tc.expectedError) assert.Check(t, is.Error(cmd.Execute(), tc.expectedError))
} }
} }
@ -122,7 +123,7 @@ 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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-ps.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("node-ps.%s.golden", tc.name))
} }
} }

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestNodeRemoveErrors(t *testing.T) { func TestNodeRemoveErrors(t *testing.T) {
@ -41,5 +41,5 @@ func TestNodeRemoveErrors(t *testing.T) {
func TestNodeRemoveMultiple(t *testing.T) { func TestNodeRemoveMultiple(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{})) cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
cmd.SetArgs([]string{"nodeID1", "nodeID2"}) cmd.SetArgs([]string{"nodeID1", "nodeID2"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }

View File

@ -6,11 +6,11 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/gotestyourself/gotestyourself/assert"
"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/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/stretchr/testify/assert"
) )
func TestNodeUpdateErrors(t *testing.T) { func TestNodeUpdateErrors(t *testing.T) {
@ -165,6 +165,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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
} }
} }

View File

@ -9,8 +9,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/stretchr/testify/assert"
) )
func TestCreateErrors(t *testing.T) { func TestCreateErrors(t *testing.T) {
@ -109,6 +110,6 @@ func TestCreatePlugin(t *testing.T) {
cmd := newCreateCommand(cli) cmd := newCreateCommand(cli)
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()}) cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String()) assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
} }

View File

@ -8,7 +8,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestPluginDisableErrors(t *testing.T) { func TestPluginDisableErrors(t *testing.T) {
@ -53,6 +54,6 @@ func TestPluginDisable(t *testing.T) {
}) })
cmd := newDisableCommand(cli) cmd := newDisableCommand(cli)
cmd.SetArgs([]string{"plugin-foo"}) cmd.SetArgs([]string{"plugin-foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String()) assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
} }

View File

@ -8,7 +8,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestPluginEnableErrors(t *testing.T) { func TestPluginEnableErrors(t *testing.T) {
@ -65,6 +66,6 @@ func TestPluginEnable(t *testing.T) {
cmd := newEnableCommand(cli) cmd := newEnableCommand(cli)
cmd.SetArgs([]string{"plugin-foo"}) cmd.SetArgs([]string{"plugin-foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String()) assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
} }

View File

@ -8,7 +8,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestRemoveErrors(t *testing.T) { func TestRemoveErrors(t *testing.T) {
@ -50,8 +51,8 @@ func TestRemove(t *testing.T) {
}) })
cmd := newRemoveCommand(cli) cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"plugin-foo"}) cmd.SetArgs([]string{"plugin-foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String()) assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
} }
func TestRemoveWithForceOption(t *testing.T) { func TestRemoveWithForceOption(t *testing.T) {
@ -65,7 +66,7 @@ func TestRemoveWithForceOption(t *testing.T) {
cmd := newRemoveCommand(cli) cmd := newRemoveCommand(cli)
cmd.SetArgs([]string{"plugin-foo"}) cmd.SetArgs([]string{"plugin-foo"})
cmd.Flags().Set("force", "true") cmd.Flags().Set("force", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.True(t, force) assert.Check(t, force)
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String()) assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
} }

View File

@ -11,7 +11,8 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
registrytypes "github.com/docker/docker/api/types/registry" registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/client" "github.com/docker/docker/client"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
const userErr = "userunknownError" const userErr = "userunknownError"
@ -63,9 +64,9 @@ func TestLoginWithCredStoreCreds(t *testing.T) {
cli.SetErr(errBuf) cli.SetErr(errBuf)
loginWithCredStoreCreds(ctx, cli, &tc.inputAuthConfig) loginWithCredStoreCreds(ctx, cli, &tc.inputAuthConfig)
outputString := cli.OutBuffer().String() outputString := cli.OutBuffer().String()
assert.Equal(t, tc.expectedMsg, outputString) assert.Check(t, is.Equal(tc.expectedMsg, outputString))
errorString := errBuf.String() errorString := errBuf.String()
assert.Equal(t, tc.expectedErr, errorString) assert.Check(t, is.Equal(tc.expectedErr, errorString))
} }
} }
@ -140,12 +141,12 @@ func TestRunLogin(t *testing.T) {
} }
loginErr := runLogin(cli, tc.inputLoginOption) loginErr := runLogin(cli, tc.inputLoginOption)
if tc.expectedErr != "" { if tc.expectedErr != "" {
assert.Equal(t, tc.expectedErr, loginErr.Error()) assert.Check(t, is.Equal(tc.expectedErr, loginErr.Error()))
} else { } else {
assert.Nil(t, loginErr) assert.Check(t, loginErr)
savedCred, credStoreErr := cli.ConfigFile().GetCredentialsStore(tc.inputStoredCred.ServerAddress).Get(tc.inputStoredCred.ServerAddress) savedCred, credStoreErr := cli.ConfigFile().GetCredentialsStore(tc.inputStoredCred.ServerAddress).Get(tc.inputStoredCred.ServerAddress)
assert.Nil(t, credStoreErr) assert.Check(t, credStoreErr)
assert.Equal(t, tc.expectedSavedCred, savedCred) assert.Check(t, is.DeepEqual(tc.expectedSavedCred, savedCred))
} }
} }
} }

View File

@ -5,8 +5,9 @@ import (
"fmt" "fmt"
"testing" "testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
// Prevents a circular import with "github.com/docker/cli/internal/test" // Prevents a circular import with "github.com/docker/cli/internal/test"
@ -80,12 +81,12 @@ func TestElectAuthServer(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
cli := test.NewFakeCli(&fakeClient{infoFunc: tc.infoFunc}) cli := test.NewFakeCli(&fakeClient{infoFunc: tc.infoFunc})
server := ElectAuthServer(context.Background(), cli) server := ElectAuthServer(context.Background(), cli)
assert.Equal(t, tc.expectedAuthServer, server) assert.Check(t, is.Equal(tc.expectedAuthServer, server))
actual := cli.ErrBuffer().String() actual := cli.ErrBuffer().String()
if tc.expectedWarning == "" { if tc.expectedWarning == "" {
assert.Empty(t, actual) assert.Check(t, is.Len(actual, 0))
} else { } else {
assert.Contains(t, actual, tc.expectedWarning) assert.Check(t, is.Contains(actual, tc.expectedWarning))
} }
} }
} }
@ -136,11 +137,11 @@ func TestGetDefaultAuthConfig(t *testing.T) {
serverAddress := tc.inputServerAddress serverAddress := tc.inputServerAddress
authconfig, err := GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/") authconfig, err := GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/")
if tc.expectedErr != "" { if tc.expectedErr != "" {
assert.NotNil(t, err) assert.Check(t, err != nil)
assert.Equal(t, tc.expectedErr, err.Error()) assert.Check(t, is.Equal(tc.expectedErr, err.Error()))
} else { } else {
assert.Nil(t, err) assert.Check(t, err)
assert.Equal(t, tc.expectedAuthConfig, *authconfig) assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, *authconfig))
} }
} }
} }

View File

@ -11,8 +11,9 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"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"
@ -52,7 +53,7 @@ func TestSecretCreateErrors(t *testing.T) {
func TestSecretCreateWithName(t *testing.T) { func TestSecretCreateWithName(t *testing.T) {
name := "foo" name := "foo"
data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile)) data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile))
assert.NoError(t, err) assert.Check(t, err)
expected := swarm.SecretSpec{ expected := swarm.SecretSpec{
Annotations: swarm.Annotations{ Annotations: swarm.Annotations{
@ -75,8 +76,8 @@ 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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }
func TestSecretCreateWithDriver(t *testing.T) { func TestSecretCreateWithDriver(t *testing.T) {
@ -104,8 +105,8 @@ func TestSecretCreateWithDriver(t *testing.T) {
cmd := newSecretCreateCommand(cli) cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name}) cmd.SetArgs([]string{name})
cmd.Flags().Set("driver", expectedDriver.Name) cmd.Flags().Set("driver", expectedDriver.Name)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }
func TestSecretCreateWithTemplatingDriver(t *testing.T) { func TestSecretCreateWithTemplatingDriver(t *testing.T) {
@ -133,8 +134,8 @@ func TestSecretCreateWithTemplatingDriver(t *testing.T) {
cmd := newSecretCreateCommand(cli) cmd := newSecretCreateCommand(cli)
cmd.SetArgs([]string{name}) cmd.SetArgs([]string{name})
cmd.Flags().Set("template-driver", expectedDriver.Name) cmd.Flags().Set("template-driver", expectedDriver.Name)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }
func TestSecretCreateWithLabels(t *testing.T) { func TestSecretCreateWithLabels(t *testing.T) {
@ -164,6 +165,6 @@ 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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String())) assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
} }

View File

@ -12,8 +12,8 @@ import (
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestSecretInspectErrors(t *testing.T) { func TestSecretInspectErrors(t *testing.T) {
@ -98,7 +98,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
}) })
cmd := newSecretInspectCommand(cli) cmd := newSecretInspectCommand(cli)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-without-format.%s.golden", tc.name))
} }
} }
@ -135,7 +135,7 @@ func TestSecretInspectWithFormat(t *testing.T) {
cmd := newSecretInspectCommand(cli) cmd := newSecretInspectCommand(cli)
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.Flags().Set("format", tc.format) cmd.Flags().Set("format", tc.format)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-with-format.%s.golden", tc.name))
} }
} }
@ -168,7 +168,7 @@ func TestSecretInspectPretty(t *testing.T) {
cmd := newSecretInspectCommand(cli) cmd := newSecretInspectCommand(cli)
cmd.SetArgs([]string{"secretID"}) cmd.SetArgs([]string{"secretID"})
cmd.Flags().Set("pretty", "true") cmd.Flags().Set("pretty", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-pretty.%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("secret-inspect-pretty.%s.golden", tc.name))
} }
} }

View File

@ -13,8 +13,9 @@ import (
// Import builders to get the builder function as package function // Import builders to get the builder function as package function
. "github.com/docker/cli/internal/test/builders" . "github.com/docker/cli/internal/test/builders"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
) )
func TestSecretListErrors(t *testing.T) { func TestSecretListErrors(t *testing.T) {
@ -74,7 +75,7 @@ func TestSecretList(t *testing.T) {
}, },
}) })
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-sort.golden") golden.Assert(t, cli.OutBuffer().String(), "secret-list-sort.golden")
} }
@ -91,7 +92,7 @@ func TestSecretListWithQuietOption(t *testing.T) {
}) })
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-quiet-option.golden") golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-quiet-option.golden")
} }
@ -110,7 +111,7 @@ func TestSecretListWithConfigFormat(t *testing.T) {
SecretFormat: "{{ .Name }} {{ .Labels }}", SecretFormat: "{{ .Name }} {{ .Labels }}",
}) })
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-config-format.golden") golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-config-format.golden")
} }
@ -127,15 +128,15 @@ func TestSecretListWithFormat(t *testing.T) {
}) })
cmd := newSecretListCommand(cli) cmd := newSecretListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}") cmd.Flags().Set("format", "{{ .Name }} {{ .Labels }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-format.golden") golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-format.golden")
} }
func TestSecretListWithFilter(t *testing.T) { func TestSecretListWithFilter(t *testing.T) {
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, "foo", options.Filters.Get("name")[0], "foo") assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]), "foo")
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0]) assert.Check(t, is.Equal("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"),
@ -155,6 +156,6 @@ 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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-filter.golden") golden.Assert(t, cli.OutBuffer().String(), "secret-list-with-filter.golden")
} }

View File

@ -7,8 +7,9 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSecretRemoveErrors(t *testing.T) { func TestSecretRemoveErrors(t *testing.T) {
@ -52,9 +53,9 @@ func TestSecretRemoveWithName(t *testing.T) {
}) })
cmd := newSecretRemoveCommand(cli) cmd := newSecretRemoveCommand(cli)
cmd.SetArgs(names) cmd.SetArgs(names)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")) assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
assert.Equal(t, names, removedSecrets) assert.Check(t, is.DeepEqual(names, removedSecrets))
} }
func TestSecretRemoveContinueAfterError(t *testing.T) { func TestSecretRemoveContinueAfterError(t *testing.T) {
@ -74,6 +75,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
cmd := newSecretRemoveCommand(cli) cmd := newSecretRemoveCommand(cli)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(names) cmd.SetArgs(names)
assert.EqualError(t, cmd.Execute(), "error removing secret: foo") assert.Check(t, is.Error(cmd.Execute(), "error removing secret: foo"))
assert.Equal(t, names, removedSecrets) assert.Check(t, is.DeepEqual(names, removedSecrets))
} }

View File

@ -3,7 +3,8 @@ package service
import ( import (
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestValidateSingleGenericResource(t *testing.T) { func TestValidateSingleGenericResource(t *testing.T) {
@ -12,11 +13,11 @@ func TestValidateSingleGenericResource(t *testing.T) {
for _, v := range incorrect { for _, v := range incorrect {
_, err := ValidateSingleGenericResource(v) _, err := ValidateSingleGenericResource(v)
assert.Error(t, err) assert.Check(t, is.ErrorContains(err, ""))
} }
for _, v := range correct { for _, v := range correct {
_, err := ValidateSingleGenericResource(v) _, err := ValidateSingleGenericResource(v)
assert.NoError(t, err) assert.Check(t, err)
} }
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/cli/command/formatter"
"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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) string { func formatServiceInspect(t *testing.T, format formatter.Format, now time.Time) string {
@ -130,5 +131,5 @@ func TestJSONFormatWithNoUpdateConfig(t *testing.T) {
if err := json.Unmarshal([]byte(s2), &m2); err != nil { if err := json.Unmarshal([]byte(s2), &m2); err != nil {
t.Fatal(err) t.Fatal(err)
} }
assert.Equal(t, m1, m2) assert.Check(t, is.DeepEqual(m1, m2))
} }

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"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/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -23,6 +23,6 @@ func TestServiceListOrder(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{.Name}}") cmd.Flags().Set("format", "{{.Name}}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "service-list-sort.golden") golden.Assert(t, cli.OutBuffer().String(), "service-list-sort.golden")
} }

View File

@ -10,45 +10,45 @@ import (
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"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"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestMemBytesString(t *testing.T) { func TestMemBytesString(t *testing.T) {
var mem opts.MemBytes = 1048576 var mem opts.MemBytes = 1048576
assert.Equal(t, "1MiB", mem.String()) assert.Check(t, is.Equal("1MiB", mem.String()))
} }
func TestMemBytesSetAndValue(t *testing.T) { func TestMemBytesSetAndValue(t *testing.T) {
var mem opts.MemBytes var mem opts.MemBytes
assert.NoError(t, mem.Set("5kb")) assert.Check(t, mem.Set("5kb"))
assert.Equal(t, int64(5120), mem.Value()) assert.Check(t, is.Equal(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, "6.100", cpus.String()) assert.Check(t, is.Equal("6.100", cpus.String()))
} }
func TestNanoCPUsSetAndValue(t *testing.T) { func TestNanoCPUsSetAndValue(t *testing.T) {
var cpus opts.NanoCPUs var cpus opts.NanoCPUs
assert.NoError(t, cpus.Set("0.35")) assert.Check(t, cpus.Set("0.35"))
assert.Equal(t, int64(350000000), cpus.Value()) assert.Check(t, is.Equal(int64(350000000), cpus.Value()))
} }
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, "2345678", opt.String()) assert.Check(t, is.Equal("2345678", opt.String()))
opt = Uint64Opt{} opt = Uint64Opt{}
assert.Equal(t, "", opt.String()) assert.Check(t, is.Equal("", opt.String()))
} }
func TestUint64OptSetAndValue(t *testing.T) { func TestUint64OptSetAndValue(t *testing.T) {
var opt Uint64Opt var opt Uint64Opt
assert.NoError(t, opt.Set("14445")) assert.Check(t, opt.Set("14445"))
assert.Equal(t, uint64(14445), *opt.Value()) assert.Check(t, is.Equal(uint64(14445), *opt.Value()))
} }
func TestHealthCheckOptionsToHealthConfig(t *testing.T) { func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
@ -61,14 +61,14 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
retries: 10, retries: 10,
} }
config, err := opt.toHealthConfig() config, err := opt.toHealthConfig()
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, &container.HealthConfig{ assert.Check(t, is.DeepEqual(&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,
}, config) }, config))
} }
func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) { func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
@ -76,10 +76,10 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
noHealthcheck: true, noHealthcheck: true,
} }
config, err := opt.toHealthConfig() config, err := opt.toHealthConfig()
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, &container.HealthConfig{ assert.Check(t, is.DeepEqual(&container.HealthConfig{
Test: []string{"NONE"}, Test: []string{"NONE"},
}, config) }, config))
} }
func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) { func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
@ -88,7 +88,7 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
noHealthcheck: true, noHealthcheck: true,
} }
_, err := opt.toHealthConfig() _, err := opt.toHealthConfig()
assert.EqualError(t, err, "--no-healthcheck conflicts with --health-* options") assert.Check(t, is.Error(err, "--no-healthcheck conflicts with --health-* options"))
} }
func TestResourceOptionsToResourceRequirements(t *testing.T) { func TestResourceOptionsToResourceRequirements(t *testing.T) {
@ -109,7 +109,7 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
for _, opt := range incorrectOptions { for _, opt := range incorrectOptions {
_, err := opt.ToResourceRequirements() _, err := opt.ToResourceRequirements()
assert.Error(t, err) assert.Check(t, is.ErrorContains(err, ""))
} }
correctOptions := []resourceOptions{ correctOptions := []resourceOptions{
@ -123,8 +123,8 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
for _, opt := range correctOptions { for _, opt := range correctOptions {
r, err := opt.ToResourceRequirements() r, err := opt.ToResourceRequirements()
assert.NoError(t, err) assert.Check(t, err)
assert.Len(t, r.Reservations.GenericResources, len(opt.resGenericResources)) assert.Check(t, is.Len(r.Reservations.GenericResources, len(opt.resGenericResources)))
} }
} }
@ -159,6 +159,6 @@ func TestToServiceNetwork(t *testing.T) {
ctx := context.Background() ctx := context.Background()
flags := newCreateCommand(nil).Flags() flags := newCreateCommand(nil).Flags()
service, err := o.ToService(ctx, client, flags) service, err := o.ToService(ctx, client, flags)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id111"}, {Target: "id555"}, {Target: "id999"}}, service.TaskTemplate.Networks) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id111"}, {Target: "id555"}, {Target: "id999"}}, service.TaskTemplate.Networks))
} }

View File

@ -7,7 +7,8 @@ import (
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/pkg/progress" "github.com/docker/docker/pkg/progress"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
type mockProgress struct { type mockProgress struct {
@ -36,9 +37,9 @@ func (u updaterTester) testUpdater(tasks []swarm.Task, expectedConvergence bool,
u.p.clear() u.p.clear()
converged, err := u.updater.update(u.service, tasks, u.activeNodes, u.rollback) converged, err := u.updater.update(u.service, tasks, u.activeNodes, u.rollback)
assert.NoError(u.t, err) assert.Check(u.t, err)
assert.Equal(u.t, expectedConvergence, converged) assert.Check(u.t, is.Equal(expectedConvergence, converged))
assert.Equal(u.t, expectedProgress, u.p.p) assert.Check(u.t, is.DeepEqual(expectedProgress, u.p.p))
} }
func TestReplicatedProgressUpdaterOneReplica(t *testing.T) { func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {

View File

@ -8,8 +8,8 @@ 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/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -26,22 +26,22 @@ func TestCreateFilter(t *testing.T) {
} }
filter := opts.NewFilterOpt() filter := opts.NewFilterOpt()
require.NoError(t, filter.Set("node=somenode")) assert.NilError(t, filter.Set("node=somenode"))
options := psOptions{ options := psOptions{
services: []string{"idmatch", "idprefix", "namematch", "notfound"}, services: []string{"idmatch", "idprefix", "namematch", "notfound"},
filter: filter, filter: filter,
} }
actual, notfound, err := createFilter(context.Background(), client, options) actual, notfound, err := createFilter(context.Background(), client, options)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, notfound, []string{"no such service: notfound"}) assert.Check(t, is.DeepEqual(notfound, []string{"no such service: notfound"}))
expected := filters.NewArgs() expected := filters.NewArgs()
expected.Add("service", "idmatch") expected.Add("service", "idmatch")
expected.Add("service", "idprefixmatch") expected.Add("service", "idprefixmatch")
expected.Add("service", "cccccccc") expected.Add("service", "cccccccc")
expected.Add("node", "somenode") expected.Add("node", "somenode")
assert.Equal(t, expected, actual) assert.Check(t, is.DeepEqual(expected, actual))
} }
func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) { func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) {
@ -58,7 +58,7 @@ func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) {
filter: opts.NewFilterOpt(), filter: opts.NewFilterOpt(),
} }
_, _, err := createFilter(context.Background(), client, options) _, _, err := createFilter(context.Background(), client, options)
assert.EqualError(t, err, "multiple services found with provided prefix: aaa") assert.Check(t, is.Error(err, "multiple services found with provided prefix: aaa"))
} }
func TestCreateFilterNoneFound(t *testing.T) { func TestCreateFilterNoneFound(t *testing.T) {
@ -68,7 +68,7 @@ func TestCreateFilterNoneFound(t *testing.T) {
filter: opts.NewFilterOpt(), filter: opts.NewFilterOpt(),
} }
_, _, err := createFilter(context.Background(), client, options) _, _, err := createFilter(context.Background(), client, options)
assert.EqualError(t, err, "no such service: foo\nno such service: notfound") assert.Check(t, is.Error(err, "no such service: foo\nno such service: notfound"))
} }
func TestRunPSWarnsOnNotFound(t *testing.T) { func TestRunPSWarnsOnNotFound(t *testing.T) {
@ -87,7 +87,7 @@ func TestRunPSWarnsOnNotFound(t *testing.T) {
format: "{{.ID}}", format: "{{.ID}}",
} }
err := runPS(cli, options) err := runPS(cli, options)
assert.EqualError(t, err, "no such service: bar") assert.Check(t, is.Error(err, "no such service: bar"))
} }
func TestRunPSQuiet(t *testing.T) { func TestRunPSQuiet(t *testing.T) {
@ -102,8 +102,8 @@ func TestRunPSQuiet(t *testing.T) {
cli := test.NewFakeCli(client) cli := test.NewFakeCli(client)
err := runPS(cli, psOptions{services: []string{"foo"}, quiet: true, filter: opts.NewFilterOpt()}) err := runPS(cli, psOptions{services: []string{"foo"}, quiet: true, filter: opts.NewFilterOpt()})
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, "sxabyp0obqokwekpun4rjo0b3\n", cli.OutBuffer().String()) assert.Check(t, is.Equal("sxabyp0obqokwekpun4rjo0b3\n", cli.OutBuffer().String()))
} }
func TestUpdateNodeFilter(t *testing.T) { func TestUpdateNodeFilter(t *testing.T) {
@ -125,5 +125,5 @@ func TestUpdateNodeFilter(t *testing.T) {
expected.Add("node", "one") expected.Add("node", "one")
expected.Add("node", "two") expected.Add("node", "two")
expected.Add("node", selfNodeID) expected.Add("node", selfNodeID)
assert.Equal(t, expected, filter) assert.Check(t, is.DeepEqual(expected, filter))
} }

View File

@ -10,7 +10,8 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -50,8 +51,8 @@ func TestRollback(t *testing.T) {
cmd.SetArgs(tc.args) cmd.SetArgs(tc.args)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(cli.ErrBuffer().String()), tc.expectedDockerCliErr) assert.Check(t, is.Equal(strings.TrimSpace(cli.ErrBuffer().String()), tc.expectedDockerCliErr))
} }
} }

View File

@ -12,8 +12,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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -30,7 +30,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.Equal(t, []string{"the", "new args"}, cspec.Args) assert.Check(t, is.DeepEqual([]string{"the", "new args"}, cspec.Args))
} }
func TestUpdateLabels(t *testing.T) { func TestUpdateLabels(t *testing.T) {
@ -44,9 +44,9 @@ func TestUpdateLabels(t *testing.T) {
} }
updateLabels(flags, &labels) updateLabels(flags, &labels)
assert.Len(t, labels, 2) assert.Check(t, is.Len(labels, 2))
assert.Equal(t, "value", labels["tokeep"]) assert.Check(t, is.Equal("value", labels["tokeep"]))
assert.Equal(t, "newlabel", labels["toadd"]) assert.Check(t, is.Equal("newlabel", labels["toadd"]))
} }
func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) { func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
@ -55,7 +55,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.Len(t, labels, 1) assert.Check(t, is.Len(labels, 1))
} }
func TestUpdatePlacementConstraints(t *testing.T) { func TestUpdatePlacementConstraints(t *testing.T) {
@ -68,9 +68,9 @@ func TestUpdatePlacementConstraints(t *testing.T) {
} }
updatePlacementConstraints(flags, placement) updatePlacementConstraints(flags, placement)
require.Len(t, placement.Constraints, 2) assert.Assert(t, is.Len(placement.Constraints, 2))
assert.Equal(t, "container=tokeep", placement.Constraints[0]) assert.Check(t, is.Equal("container=tokeep", placement.Constraints[0]))
assert.Equal(t, "node=toadd", placement.Constraints[1]) assert.Check(t, is.Equal("node=toadd", placement.Constraints[1]))
} }
func TestUpdatePlacementPrefs(t *testing.T) { func TestUpdatePlacementPrefs(t *testing.T) {
@ -94,9 +94,9 @@ func TestUpdatePlacementPrefs(t *testing.T) {
} }
updatePlacementPreferences(flags, placement) updatePlacementPreferences(flags, placement)
require.Len(t, placement.Preferences, 2) assert.Assert(t, is.Len(placement.Preferences, 2))
assert.Equal(t, "node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor) assert.Check(t, is.Equal("node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor))
assert.Equal(t, "node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor) assert.Check(t, is.Equal("node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor))
} }
func TestUpdateEnvironment(t *testing.T) { func TestUpdateEnvironment(t *testing.T) {
@ -107,11 +107,11 @@ func TestUpdateEnvironment(t *testing.T) {
envs := []string{"toremove=theenvtoremove", "tokeep=value"} envs := []string{"toremove=theenvtoremove", "tokeep=value"}
updateEnvironment(flags, &envs) updateEnvironment(flags, &envs)
require.Len(t, envs, 2) assert.Assert(t, is.Len(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, "toadd=newenv", envs[0]) assert.Check(t, is.Equal("toadd=newenv", envs[0]))
assert.Equal(t, "tokeep=value", envs[1]) assert.Check(t, is.Equal("tokeep=value", envs[1]))
} }
func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) { func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
@ -123,7 +123,7 @@ func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
envs := []string{"foo=value"} envs := []string{"foo=value"}
updateEnvironment(flags, &envs) updateEnvironment(flags, &envs)
assert.Len(t, envs, 0) assert.Check(t, is.Len(envs, 0))
} }
func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) { func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
@ -134,8 +134,8 @@ func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
envs := []string{"A=c"} envs := []string{"A=c"}
updateEnvironment(flags, &envs) updateEnvironment(flags, &envs)
require.Len(t, envs, 1) assert.Assert(t, is.Len(envs, 1))
assert.Equal(t, "A=b", envs[0]) assert.Check(t, is.Equal("A=b", envs[0]))
} }
func TestUpdateGroups(t *testing.T) { func TestUpdateGroups(t *testing.T) {
@ -149,10 +149,10 @@ func TestUpdateGroups(t *testing.T) {
groups := []string{"bar", "root"} groups := []string{"bar", "root"}
updateGroups(flags, &groups) updateGroups(flags, &groups)
require.Len(t, groups, 3) assert.Assert(t, is.Len(groups, 3))
assert.Equal(t, "bar", groups[0]) assert.Check(t, is.Equal("bar", groups[0]))
assert.Equal(t, "foo", groups[1]) assert.Check(t, is.Equal("foo", groups[1]))
assert.Equal(t, "wheel", groups[2]) assert.Check(t, is.Equal("wheel", groups[2]))
} }
func TestUpdateDNSConfig(t *testing.T) { func TestUpdateDNSConfig(t *testing.T) {
@ -188,17 +188,17 @@ func TestUpdateDNSConfig(t *testing.T) {
updateDNSConfig(flags, &config) updateDNSConfig(flags, &config)
require.Len(t, config.Nameservers, 3) assert.Assert(t, is.Len(config.Nameservers, 3))
assert.Equal(t, "1.1.1.1", config.Nameservers[0]) assert.Check(t, is.Equal("1.1.1.1", config.Nameservers[0]))
assert.Equal(t, "2001:db8:abc8::1", config.Nameservers[1]) assert.Check(t, is.Equal("2001:db8:abc8::1", config.Nameservers[1]))
assert.Equal(t, "5.5.5.5", config.Nameservers[2]) assert.Check(t, is.Equal("5.5.5.5", config.Nameservers[2]))
require.Len(t, config.Search, 2) assert.Assert(t, is.Len(config.Search, 2))
assert.Equal(t, "example.com", config.Search[0]) assert.Check(t, is.Equal("example.com", config.Search[0]))
assert.Equal(t, "localdomain", config.Search[1]) assert.Check(t, is.Equal("localdomain", config.Search[1]))
require.Len(t, config.Options, 1) assert.Assert(t, is.Len(config.Options, 1))
assert.Equal(t, config.Options[0], "ndots:9") assert.Check(t, is.Equal(config.Options[0], "ndots:9"))
} }
func TestUpdateMounts(t *testing.T) { func TestUpdateMounts(t *testing.T) {
@ -212,9 +212,9 @@ func TestUpdateMounts(t *testing.T) {
} }
updateMounts(flags, &mounts) updateMounts(flags, &mounts)
require.Len(t, mounts, 2) assert.Assert(t, is.Len(mounts, 2))
assert.Equal(t, "/toadd", mounts[0].Target) assert.Check(t, is.Equal("/toadd", mounts[0].Target))
assert.Equal(t, "/tokeep", mounts[1].Target) assert.Check(t, is.Equal("/tokeep", mounts[1].Target))
} }
func TestUpdateMountsWithDuplicateMounts(t *testing.T) { func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
@ -228,10 +228,10 @@ func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
} }
updateMounts(flags, &mounts) updateMounts(flags, &mounts)
require.Len(t, mounts, 3) assert.Assert(t, is.Len(mounts, 3))
assert.Equal(t, "/tokeep1", mounts[0].Target) assert.Check(t, is.Equal("/tokeep1", mounts[0].Target))
assert.Equal(t, "/tokeep2", mounts[1].Target) assert.Check(t, is.Equal("/tokeep2", mounts[1].Target))
assert.Equal(t, "/toadd", mounts[2].Target) assert.Check(t, is.Equal("/toadd", mounts[2].Target))
} }
func TestUpdatePorts(t *testing.T) { func TestUpdatePorts(t *testing.T) {
@ -245,13 +245,13 @@ func TestUpdatePorts(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.NoError(t, err) assert.Check(t, err)
require.Len(t, portConfigs, 2) assert.Assert(t, is.Len(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, 555, targetPorts[0]) assert.Check(t, is.Equal(555, targetPorts[0]))
assert.Equal(t, 1000, targetPorts[1]) assert.Check(t, is.Equal(1000, targetPorts[1]))
} }
func TestUpdatePortsDuplicate(t *testing.T) { func TestUpdatePortsDuplicate(t *testing.T) {
@ -269,9 +269,9 @@ func TestUpdatePortsDuplicate(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.NoError(t, err) assert.Check(t, err)
require.Len(t, portConfigs, 1) assert.Assert(t, is.Len(portConfigs, 1))
assert.Equal(t, uint32(80), portConfigs[0].TargetPort) assert.Check(t, is.Equal(uint32(80), portConfigs[0].TargetPort))
} }
func TestUpdateHealthcheckTable(t *testing.T) { func TestUpdateHealthcheckTable(t *testing.T) {
@ -345,9 +345,9 @@ func TestUpdateHealthcheckTable(t *testing.T) {
} }
err := updateHealthcheck(flags, cspec) err := updateHealthcheck(flags, cspec)
if c.err != "" { if c.err != "" {
assert.EqualError(t, err, c.err) assert.Check(t, is.Error(err, c.err))
} else { } else {
assert.NoError(t, err) assert.Check(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)
} }
@ -370,8 +370,8 @@ func TestUpdateHosts(t *testing.T) {
expected := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 ipv6.net"} expected := []string{"1.2.3.4 example.com", "4.3.2.1 example.org", "2001:db8:abc8::1 ipv6.net"}
err := updateHosts(flags, &hosts) err := updateHosts(flags, &hosts)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, expected, hosts) assert.Check(t, is.DeepEqual(expected, hosts))
} }
func TestUpdateHostsPreservesOrder(t *testing.T) { func TestUpdateHostsPreservesOrder(t *testing.T) {
@ -382,8 +382,8 @@ func TestUpdateHostsPreservesOrder(t *testing.T) {
hosts := []string{} hosts := []string{}
err := updateHosts(flags, &hosts) err := updateHosts(flags, &hosts)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, []string{"127.0.0.2 foobar", "127.0.0.1 foobar", "127.0.0.3 foobar"}, hosts) assert.Check(t, is.DeepEqual([]string{"127.0.0.2 foobar", "127.0.0.1 foobar", "127.0.0.3 foobar"}, hosts))
} }
func TestUpdatePortsRmWithProtocol(t *testing.T) { func TestUpdatePortsRmWithProtocol(t *testing.T) {
@ -404,10 +404,10 @@ func TestUpdatePortsRmWithProtocol(t *testing.T) {
} }
err := updatePorts(flags, &portConfigs) err := updatePorts(flags, &portConfigs)
assert.NoError(t, err) assert.Check(t, err)
require.Len(t, portConfigs, 2) assert.Assert(t, is.Len(portConfigs, 2))
assert.Equal(t, uint32(81), portConfigs[0].TargetPort) assert.Check(t, is.Equal(uint32(81), portConfigs[0].TargetPort))
assert.Equal(t, uint32(82), portConfigs[1].TargetPort) assert.Check(t, is.Equal(uint32(82), portConfigs[1].TargetPort))
} }
type secretAPIClientMock struct { type secretAPIClientMock struct {
@ -461,11 +461,11 @@ func TestUpdateSecretUpdateInPlace(t *testing.T) {
updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets) updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets)
assert.NoError(t, err) assert.Check(t, err)
require.Len(t, updatedSecrets, 1) assert.Assert(t, is.Len(updatedSecrets, 1))
assert.Equal(t, "tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID) assert.Check(t, is.Equal("tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID))
assert.Equal(t, "foo", updatedSecrets[0].SecretName) assert.Check(t, is.Equal("foo", updatedSecrets[0].SecretName))
assert.Equal(t, "foo2", updatedSecrets[0].File.Name) assert.Check(t, is.Equal("foo2", updatedSecrets[0].File.Name))
} }
func TestUpdateReadOnly(t *testing.T) { func TestUpdateReadOnly(t *testing.T) {
@ -480,18 +480,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.True(t, cspec.ReadOnly) assert.Check(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.True(t, cspec.ReadOnly) assert.Check(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.False(t, cspec.ReadOnly) assert.Check(t, !cspec.ReadOnly)
} }
func TestUpdateStopSignal(t *testing.T) { func TestUpdateStopSignal(t *testing.T) {
@ -506,74 +506,74 @@ 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, "SIGUSR1", cspec.StopSignal) assert.Check(t, is.Equal("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, "SIGUSR1", cspec.StopSignal) assert.Check(t, is.Equal("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, "SIGWINCH", cspec.StopSignal) assert.Check(t, is.Equal("SIGWINCH", cspec.StopSignal))
} }
func TestUpdateIsolationValid(t *testing.T) { func TestUpdateIsolationValid(t *testing.T) {
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
err := flags.Set("isolation", "process") err := flags.Set("isolation", "process")
require.NoError(t, err) assert.NilError(t, err)
spec := swarm.ServiceSpec{ spec := swarm.ServiceSpec{
TaskTemplate: swarm.TaskSpec{ TaskTemplate: swarm.TaskSpec{
ContainerSpec: &swarm.ContainerSpec{}, ContainerSpec: &swarm.ContainerSpec{},
}, },
} }
err = updateService(context.Background(), nil, flags, &spec) err = updateService(context.Background(), nil, flags, &spec)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, container.IsolationProcess, spec.TaskTemplate.ContainerSpec.Isolation) assert.Check(t, is.Equal(container.IsolationProcess, spec.TaskTemplate.ContainerSpec.Isolation))
} }
func TestUpdateIsolationInvalid(t *testing.T) { func TestUpdateIsolationInvalid(t *testing.T) {
// validation depends on daemon os / version so validation should be done on the daemon side // validation depends on daemon os / version so validation should be done on the daemon side
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
err := flags.Set("isolation", "test") err := flags.Set("isolation", "test")
require.NoError(t, err) assert.NilError(t, err)
spec := swarm.ServiceSpec{ spec := swarm.ServiceSpec{
TaskTemplate: swarm.TaskSpec{ TaskTemplate: swarm.TaskSpec{
ContainerSpec: &swarm.ContainerSpec{}, ContainerSpec: &swarm.ContainerSpec{},
}, },
} }
err = updateService(context.Background(), nil, flags, &spec) err = updateService(context.Background(), nil, flags, &spec)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, container.Isolation("test"), spec.TaskTemplate.ContainerSpec.Isolation) assert.Check(t, is.Equal(container.Isolation("test"), spec.TaskTemplate.ContainerSpec.Isolation))
} }
func TestAddGenericResources(t *testing.T) { func TestAddGenericResources(t *testing.T) {
task := &swarm.TaskSpec{} task := &swarm.TaskSpec{}
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
assert.Nil(t, addGenericResources(flags, task)) assert.Check(t, addGenericResources(flags, task))
flags.Set(flagGenericResourcesAdd, "foo=1") flags.Set(flagGenericResourcesAdd, "foo=1")
assert.NoError(t, addGenericResources(flags, task)) assert.Check(t, addGenericResources(flags, task))
assert.Len(t, task.Resources.Reservations.GenericResources, 1) assert.Check(t, is.Len(task.Resources.Reservations.GenericResources, 1))
// Checks that foo isn't added a 2nd time // Checks that foo isn't added a 2nd time
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
flags.Set(flagGenericResourcesAdd, "bar=1") flags.Set(flagGenericResourcesAdd, "bar=1")
assert.NoError(t, addGenericResources(flags, task)) assert.Check(t, addGenericResources(flags, task))
assert.Len(t, task.Resources.Reservations.GenericResources, 2) assert.Check(t, is.Len(task.Resources.Reservations.GenericResources, 2))
} }
func TestRemoveGenericResources(t *testing.T) { func TestRemoveGenericResources(t *testing.T) {
task := &swarm.TaskSpec{} task := &swarm.TaskSpec{}
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
assert.Nil(t, removeGenericResources(flags, task)) assert.Check(t, removeGenericResources(flags, task))
flags.Set(flagGenericResourcesRemove, "foo") flags.Set(flagGenericResourcesRemove, "foo")
assert.Error(t, removeGenericResources(flags, task)) assert.Check(t, is.ErrorContains(removeGenericResources(flags, task), ""))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
flags.Set(flagGenericResourcesAdd, "foo=1") flags.Set(flagGenericResourcesAdd, "foo=1")
@ -584,8 +584,8 @@ func TestRemoveGenericResources(t *testing.T) {
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
flags.Set(flagGenericResourcesRemove, "foo") flags.Set(flagGenericResourcesRemove, "foo")
assert.NoError(t, removeGenericResources(flags, task)) assert.Check(t, removeGenericResources(flags, task))
assert.Len(t, task.Resources.Reservations.GenericResources, 1) assert.Check(t, is.Len(task.Resources.Reservations.GenericResources, 1))
} }
func TestUpdateNetworks(t *testing.T) { func TestUpdateNetworks(t *testing.T) {
@ -618,38 +618,38 @@ func TestUpdateNetworks(t *testing.T) {
flags := newUpdateCommand(nil).Flags() flags := newUpdateCommand(nil).Flags()
err := flags.Set(flagNetworkAdd, "aaa-network") err := flags.Set(flagNetworkAdd, "aaa-network")
require.NoError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
err = flags.Set(flagNetworkAdd, "aaa-network") err = flags.Set(flagNetworkAdd, "aaa-network")
require.NoError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
assert.EqualError(t, err, "service is already attached to network aaa-network") assert.Check(t, is.Error(err, "service is already attached to network aaa-network"))
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
err = flags.Set(flagNetworkAdd, "id555") err = flags.Set(flagNetworkAdd, "id555")
require.NoError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
assert.EqualError(t, err, "service is already attached to network id555") assert.Check(t, is.Error(err, "service is already attached to network id555"))
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
err = flags.Set(flagNetworkRemove, "id999") err = flags.Set(flagNetworkRemove, "id999")
require.NoError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}}, svc.TaskTemplate.Networks) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}}, svc.TaskTemplate.Networks))
flags = newUpdateCommand(nil).Flags() flags = newUpdateCommand(nil).Flags()
err = flags.Set(flagNetworkAdd, "mmm-network") err = flags.Set(flagNetworkAdd, "mmm-network")
require.NoError(t, err) assert.NilError(t, err)
err = flags.Set(flagNetworkRemove, "aaa-network") err = flags.Set(flagNetworkRemove, "aaa-network")
require.NoError(t, err) assert.NilError(t, err)
err = updateService(ctx, client, flags, &svc) err = updateService(ctx, client, flags, &svc)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks) assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks))
} }

View File

@ -5,7 +5,7 @@ import (
composetypes "github.com/docker/cli/cli/compose/types" composetypes "github.com/docker/cli/cli/compose/types"
apiv1beta1 "github.com/docker/cli/kubernetes/compose/v1beta1" apiv1beta1 "github.com/docker/cli/kubernetes/compose/v1beta1"
"github.com/stretchr/testify/require" "github.com/gotestyourself/gotestyourself/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
) )
@ -24,8 +24,8 @@ func TestLoadStack(t *testing.T) {
}, },
}, },
}) })
require.NoError(t, err) assert.NilError(t, err)
require.Equal(t, &apiv1beta1.Stack{ assert.DeepEqual(t, &apiv1beta1.Stack{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "foo", Name: "foo",
}, },

View File

@ -10,9 +10,9 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestListErrors(t *testing.T) { func TestListErrors(t *testing.T) {
@ -72,7 +72,7 @@ func TestListWithFormat(t *testing.T) {
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
cmd.Flags().Set("format", "{{ .Name }}") cmd.Flags().Set("format", "{{ .Name }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-list-with-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-list-with-format.golden")
} }
@ -88,7 +88,7 @@ func TestListWithoutFormat(t *testing.T) {
}, },
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-list-without-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-list-without-format.golden")
} }
@ -141,7 +141,7 @@ func TestListOrder(t *testing.T) {
}, },
}) })
cmd := newListCommand(cli) cmd := newListCommand(cli)
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), uc.golden) golden.Assert(t, cli.OutBuffer().String(), uc.golden)
} }
} }

View File

@ -6,9 +6,9 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/fs" "github.com/gotestyourself/gotestyourself/fs"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
) )
func TestGetConfigDetails(t *testing.T) { func TestGetConfigDetails(t *testing.T) {
@ -22,11 +22,11 @@ services:
defer file.Remove() defer file.Remove()
details, err := getConfigDetails([]string{file.Path()}, nil) details, err := getConfigDetails([]string{file.Path()}, nil)
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, filepath.Dir(file.Path()), details.WorkingDir) assert.Check(t, is.Equal(filepath.Dir(file.Path()), details.WorkingDir))
require.Len(t, details.ConfigFiles, 1) assert.Assert(t, is.Len(details.ConfigFiles, 1))
assert.Equal(t, "3.0", details.ConfigFiles[0].Config["version"]) assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
assert.Len(t, details.Environment, len(os.Environ())) assert.Check(t, is.Len(details.Environment, len(os.Environ())))
} }
func TestGetConfigDetailsStdin(t *testing.T) { func TestGetConfigDetailsStdin(t *testing.T) {
@ -37,11 +37,11 @@ services:
image: alpine:3.5 image: alpine:3.5
` `
details, err := getConfigDetails([]string{"-"}, strings.NewReader(content)) details, err := getConfigDetails([]string{"-"}, strings.NewReader(content))
require.NoError(t, err) assert.NilError(t, err)
cwd, err := os.Getwd() cwd, err := os.Getwd()
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, cwd, details.WorkingDir) assert.Check(t, is.Equal(cwd, details.WorkingDir))
require.Len(t, details.ConfigFiles, 1) assert.Assert(t, is.Len(details.ConfigFiles, 1))
assert.Equal(t, "3.0", details.ConfigFiles[0].Config["version"]) assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
assert.Len(t, details.Environment, len(os.Environ())) assert.Check(t, is.Len(details.Environment, len(os.Environ())))
} }

View File

@ -12,9 +12,10 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestStackPsErrors(t *testing.T) { func TestStackPsErrors(t *testing.T) {
@ -61,9 +62,9 @@ func TestStackPsEmptyStack(t *testing.T) {
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute()) assert.Check(t, is.ErrorContains(cmd.Execute(), ""))
assert.EqualError(t, cmd.Execute(), "nothing found in stack: foo") assert.Check(t, is.Error(cmd.Execute(), "nothing found in stack: foo"))
assert.Equal(t, "", fakeCli.OutBuffer().String()) assert.Check(t, is.Equal("", fakeCli.OutBuffer().String()))
} }
func TestStackPsWithQuietOption(t *testing.T) { func TestStackPsWithQuietOption(t *testing.T) {
@ -75,7 +76,7 @@ func TestStackPsWithQuietOption(t *testing.T) {
cmd := newPsCommand(cli) cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-quiet-option.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-quiet-option.golden")
} }
@ -90,7 +91,7 @@ func TestStackPsWithNoTruncOption(t *testing.T) {
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("no-trunc", "true") cmd.Flags().Set("no-trunc", "true")
cmd.Flags().Set("format", "{{ .ID }}") cmd.Flags().Set("format", "{{ .ID }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-trunc-option.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-trunc-option.golden")
} }
@ -109,7 +110,7 @@ func TestStackPsWithNoResolveOption(t *testing.T) {
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("no-resolve", "true") cmd.Flags().Set("no-resolve", "true")
cmd.Flags().Set("format", "{{ .Node }}") cmd.Flags().Set("format", "{{ .Node }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-resolve-option.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-no-resolve-option.golden")
} }
@ -122,7 +123,7 @@ func TestStackPsWithFormat(t *testing.T) {
cmd := newPsCommand(cli) cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("format", "{{ .Name }}") cmd.Flags().Set("format", "{{ .Name }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-format.golden")
} }
@ -137,7 +138,7 @@ func TestStackPsWithConfigFormat(t *testing.T) {
}) })
cmd := newPsCommand(cli) cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-config-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-ps-with-config-format.golden")
} }
@ -159,6 +160,6 @@ func TestStackPsWithoutFormat(t *testing.T) {
}) })
cmd := newPsCommand(cli) cmd := newPsCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-ps-without-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-ps-without-format.golden")
} }

View File

@ -7,7 +7,8 @@ import (
"testing" "testing"
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func fakeClientForRemoveStackTest(version string) *fakeClient { func fakeClientForRemoveStackTest(version string) *fakeClient {
@ -45,11 +46,11 @@ func TestRemoveStackVersion124DoesNotRemoveConfigsOrSecrets(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(client)) cmd := newRemoveCommand(test.NewFakeCli(client))
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, buildObjectIDs(client.services), client.removedServices) assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks) assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
assert.Len(t, client.removedSecrets, 0) assert.Check(t, is.Len(client.removedSecrets, 0))
assert.Len(t, client.removedConfigs, 0) assert.Check(t, is.Len(client.removedConfigs, 0))
} }
func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) { func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
@ -57,11 +58,11 @@ func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(client)) cmd := newRemoveCommand(test.NewFakeCli(client))
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, buildObjectIDs(client.services), client.removedServices) assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks) assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets) assert.Check(t, is.DeepEqual(buildObjectIDs(client.secrets), client.removedSecrets))
assert.Len(t, client.removedConfigs, 0) assert.Check(t, is.Len(client.removedConfigs, 0))
} }
func TestRemoveStackVersion130RemovesEverything(t *testing.T) { func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
@ -69,11 +70,11 @@ func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
cmd := newRemoveCommand(test.NewFakeCli(client)) cmd := newRemoveCommand(test.NewFakeCli(client))
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, buildObjectIDs(client.services), client.removedServices) assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks) assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets) assert.Check(t, is.DeepEqual(buildObjectIDs(client.secrets), client.removedSecrets))
assert.Equal(t, buildObjectIDs(client.configs), client.removedConfigs) assert.Check(t, is.DeepEqual(buildObjectIDs(client.configs), client.removedConfigs))
} }
func TestRemoveStackSkipEmpty(t *testing.T) { func TestRemoveStackSkipEmpty(t *testing.T) {
@ -100,19 +101,19 @@ func TestRemoveStackSkipEmpty(t *testing.T) {
cmd := newRemoveCommand(fakeCli) cmd := newRemoveCommand(fakeCli)
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
expectedList := []string{"Removing service bar_service1", expectedList := []string{"Removing service bar_service1",
"Removing service bar_service2", "Removing service bar_service2",
"Removing secret bar_secret1", "Removing secret bar_secret1",
"Removing config bar_config1", "Removing config bar_config1",
"Removing network bar_network1\n", "Removing network bar_network1\n",
} }
assert.Equal(t, strings.Join(expectedList, "\n"), fakeCli.OutBuffer().String()) assert.Check(t, is.Equal(strings.Join(expectedList, "\n"), fakeCli.OutBuffer().String()))
assert.Contains(t, fakeCli.ErrBuffer().String(), "Nothing found in stack: foo\n") assert.Check(t, is.Contains(fakeCli.ErrBuffer().String(), "Nothing found in stack: foo\n"))
assert.Equal(t, allServiceIDs, fakeClient.removedServices) assert.Check(t, is.DeepEqual(allServiceIDs, fakeClient.removedServices))
assert.Equal(t, allNetworkIDs, fakeClient.removedNetworks) assert.Check(t, is.DeepEqual(allNetworkIDs, fakeClient.removedNetworks))
assert.Equal(t, allSecretIDs, fakeClient.removedSecrets) assert.Check(t, is.DeepEqual(allSecretIDs, fakeClient.removedSecrets))
assert.Equal(t, allConfigIDs, fakeClient.removedConfigs) assert.Check(t, is.DeepEqual(allConfigIDs, fakeClient.removedConfigs))
} }
func TestRemoveContinueAfterError(t *testing.T) { func TestRemoveContinueAfterError(t *testing.T) {
@ -149,9 +150,9 @@ func TestRemoveContinueAfterError(t *testing.T) {
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs([]string{"foo", "bar"}) cmd.SetArgs([]string{"foo", "bar"})
assert.EqualError(t, cmd.Execute(), "Failed to remove some resources from stack: foo") assert.Check(t, is.Error(cmd.Execute(), "Failed to remove some resources from stack: foo"))
assert.Equal(t, allServiceIDs, removedServices) assert.Check(t, is.DeepEqual(allServiceIDs, removedServices))
assert.Equal(t, allNetworkIDs, cli.removedNetworks) assert.Check(t, is.DeepEqual(allNetworkIDs, cli.removedNetworks))
assert.Equal(t, allSecretIDs, cli.removedSecrets) assert.Check(t, is.DeepEqual(allSecretIDs, cli.removedSecrets))
assert.Equal(t, allConfigIDs, cli.removedConfigs) assert.Check(t, is.DeepEqual(allConfigIDs, cli.removedConfigs))
} }

View File

@ -11,9 +11,10 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestStackServicesErrors(t *testing.T) { func TestStackServicesErrors(t *testing.T) {
@ -88,9 +89,9 @@ func TestStackServicesEmptyServiceList(t *testing.T) {
}) })
cmd := newServicesCommand(fakeCli) cmd := newServicesCommand(fakeCli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, "", fakeCli.OutBuffer().String()) assert.Check(t, is.Equal("", fakeCli.OutBuffer().String()))
assert.Equal(t, "Nothing found in stack: foo\n", fakeCli.ErrBuffer().String()) assert.Check(t, is.Equal("Nothing found in stack: foo\n", fakeCli.ErrBuffer().String()))
} }
func TestStackServicesWithQuietOption(t *testing.T) { func TestStackServicesWithQuietOption(t *testing.T) {
@ -102,7 +103,7 @@ func TestStackServicesWithQuietOption(t *testing.T) {
cmd := newServicesCommand(cli) cmd := newServicesCommand(cli)
cmd.Flags().Set("quiet", "true") cmd.Flags().Set("quiet", "true")
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-quiet-option.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-quiet-option.golden")
} }
@ -117,7 +118,7 @@ func TestStackServicesWithFormat(t *testing.T) {
cmd := newServicesCommand(cli) cmd := newServicesCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
cmd.Flags().Set("format", "{{ .Name }}") cmd.Flags().Set("format", "{{ .Name }}")
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-format.golden")
} }
@ -134,7 +135,7 @@ func TestStackServicesWithConfigFormat(t *testing.T) {
}) })
cmd := newServicesCommand(cli) cmd := newServicesCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-config-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-services-with-config-format.golden")
} }
@ -157,6 +158,6 @@ func TestStackServicesWithoutFormat(t *testing.T) {
}) })
cmd := newServicesCommand(cli) cmd := newServicesCommand(cli)
cmd.SetArgs([]string{"foo"}) cmd.SetArgs([]string{"foo"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), "stack-services-without-format.golden") golden.Assert(t, cli.OutBuffer().String(), "stack-services-without-format.golden")
} }

View File

@ -6,7 +6,8 @@ import (
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func TestLoadBundlefileErrors(t *testing.T) { func TestLoadBundlefileErrors(t *testing.T) {
@ -33,7 +34,7 @@ func TestLoadBundlefileErrors(t *testing.T) {
for _, tc := range testCases { for _, tc := range testCases {
_, err := loadBundlefile(&bytes.Buffer{}, tc.namespace, tc.path) _, err := loadBundlefile(&bytes.Buffer{}, tc.namespace, tc.path)
assert.Error(t, err, tc.expectedError) assert.Check(t, is.ErrorContains(err, ""), tc.expectedError)
} }
} }
@ -44,6 +45,6 @@ func TestLoadBundlefile(t *testing.T) {
path := filepath.Join("testdata", "bundlefile_with_two_services.dab") path := filepath.Join("testdata", "bundlefile_with_two_services.dab")
bundleFile, err := loadBundlefile(buf, namespace, path) bundleFile, err := loadBundlefile(buf, namespace, path)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, len(bundleFile.Services), 2) assert.Check(t, is.Equal(len(bundleFile.Services), 2))
} }

View File

@ -6,8 +6,8 @@ import (
"github.com/docker/cli/internal/test/network" "github.com/docker/cli/internal/test/network"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/gotestyourself/gotestyourself/assert"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -57,7 +57,7 @@ func TestValidateExternalNetworks(t *testing.T) {
networks := []string{testcase.network} networks := []string{testcase.network}
err := validateExternalNetworks(context.Background(), fakeClient, networks) err := validateExternalNetworks(context.Background(), fakeClient, networks)
if testcase.expectedMsg == "" { if testcase.expectedMsg == "" {
assert.NoError(t, err) assert.Check(t, err)
} else { } else {
testutil.ErrorContains(t, err, testcase.expectedMsg) testutil.ErrorContains(t, err, testcase.expectedMsg)
} }

View File

@ -7,7 +7,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"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/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -22,7 +23,7 @@ func TestPruneServices(t *testing.T) {
dockerCli := test.NewFakeCli(client) dockerCli := test.NewFakeCli(client)
pruneServices(ctx, dockerCli, namespace, services) pruneServices(ctx, dockerCli, namespace, services)
assert.Equal(t, buildObjectIDs([]string{objectName("foo", "remove")}), client.removedServices) assert.Check(t, is.DeepEqual(buildObjectIDs([]string{objectName("foo", "remove")}), client.removedServices))
} }
// TestServiceUpdateResolveImageChanged tests that the service's // TestServiceUpdateResolveImageChanged tests that the service's
@ -93,9 +94,9 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) {
}, },
} }
err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged) err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged)
assert.NoError(t, err) assert.Check(t, err)
assert.Equal(t, testcase.expectedQueryRegistry, receivedOptions.QueryRegistry) assert.Check(t, is.Equal(testcase.expectedQueryRegistry, receivedOptions.QueryRegistry))
assert.Equal(t, testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image) assert.Check(t, is.Equal(testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image))
receivedService = swarm.ServiceSpec{} receivedService = swarm.ServiceSpec{}
receivedOptions = types.ServiceUpdateOptions{} receivedOptions = types.ServiceUpdateOptions{}

View File

@ -10,8 +10,8 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
"github.com/stretchr/testify/assert" "github.com/gotestyourself/gotestyourself/assert"
"github.com/stretchr/testify/require" is "github.com/gotestyourself/gotestyourself/assert/cmp"
) )
func swarmSpecWithFullCAConfig() *swarm.Spec { func swarmSpecWithFullCAConfig() *swarm.Spec {
@ -35,13 +35,13 @@ func swarmSpecWithFullCAConfig() *swarm.Spec {
func TestDisplayTrustRootNoRoot(t *testing.T) { func TestDisplayTrustRootNoRoot(t *testing.T) {
buffer := new(bytes.Buffer) buffer := new(bytes.Buffer)
err := displayTrustRoot(buffer, swarm.Swarm{}) err := displayTrustRoot(buffer, swarm.Swarm{})
assert.EqualError(t, err, "No CA information available") assert.Check(t, is.Error(err, "No CA information available"))
} }
func TestDisplayTrustRootInvalidFlags(t *testing.T) { func TestDisplayTrustRootInvalidFlags(t *testing.T) {
// we need an actual PEMfile to test // we need an actual PEMfile to test
tmpfile, err := ioutil.TempFile("", "pemfile") tmpfile, err := ioutil.TempFile("", "pemfile")
assert.NoError(t, err) assert.Check(t, err)
defer os.Remove(tmpfile.Name()) defer os.Remove(tmpfile.Name())
tmpfile.Write([]byte(` tmpfile.Write([]byte(`
-----BEGIN CERTIFICATE----- -----BEGIN CERTIFICATE-----
@ -95,7 +95,7 @@ PQQDAgNIADBFAiEAqD3Kb2rgsy6NoTk+zEgcUi/aGBCsvQDG3vML1PXN8j0CIBjj
}, nil }, nil
}, },
})) }))
assert.NoError(t, cmd.Flags().Parse(args)) assert.Check(t, cmd.Flags().Parse(args))
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
testutil.ErrorContains(t, cmd.Execute(), "flag requires the `--rotate` flag to update the CA") testutil.ErrorContains(t, cmd.Execute(), "flag requires the `--rotate` flag to update the CA")
} }
@ -109,8 +109,8 @@ func TestDisplayTrustRoot(t *testing.T) {
TLSInfo: swarm.TLSInfo{TrustRoot: trustRoot}, TLSInfo: swarm.TLSInfo{TrustRoot: trustRoot},
}, },
}) })
require.NoError(t, err) assert.NilError(t, err)
assert.Equal(t, trustRoot+"\n", buffer.String()) assert.Check(t, is.Equal(trustRoot+"\n", buffer.String()))
} }
func TestUpdateSwarmSpecDefaultRotate(t *testing.T) { func TestUpdateSwarmSpecDefaultRotate(t *testing.T) {
@ -122,7 +122,7 @@ func TestUpdateSwarmSpecDefaultRotate(t *testing.T) {
expected.CAConfig.ForceRotate = 2 expected.CAConfig.ForceRotate = 2
expected.CAConfig.SigningCACert = "" expected.CAConfig.SigningCACert = ""
expected.CAConfig.SigningCAKey = "" expected.CAConfig.SigningCAKey = ""
assert.Equal(t, expected, spec) assert.Check(t, is.DeepEqual(expected, spec))
} }
func TestUpdateSwarmSpecPartial(t *testing.T) { func TestUpdateSwarmSpecPartial(t *testing.T) {
@ -134,7 +134,7 @@ func TestUpdateSwarmSpecPartial(t *testing.T) {
expected := swarmSpecWithFullCAConfig() expected := swarmSpecWithFullCAConfig()
expected.CAConfig.SigningCACert = "cacert" expected.CAConfig.SigningCACert = "cacert"
assert.Equal(t, expected, spec) assert.Check(t, is.DeepEqual(expected, spec))
} }
func TestUpdateSwarmSpecFullFlags(t *testing.T) { func TestUpdateSwarmSpecFullFlags(t *testing.T) {
@ -151,5 +151,5 @@ func TestUpdateSwarmSpecFullFlags(t *testing.T) {
expected.CAConfig.SigningCACert = "cacert" expected.CAConfig.SigningCACert = "cacert"
expected.CAConfig.SigningCAKey = "cakey" expected.CAConfig.SigningCAKey = "cakey"
expected.CAConfig.NodeCertExpiry = 3 * time.Minute expected.CAConfig.NodeCertExpiry = 3 * time.Minute
assert.Equal(t, expected, spec) assert.Check(t, is.DeepEqual(expected, spec))
} }

View File

@ -8,9 +8,10 @@ import (
"github.com/docker/cli/internal/test" "github.com/docker/cli/internal/test"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/gotestyourself/gotestyourself/golden" "github.com/gotestyourself/gotestyourself/golden"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSwarmInitErrorOnAPIFailure(t *testing.T) { func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
@ -74,7 +75,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.EqualError(t, cmd.Execute(), tc.expectedError) assert.Check(t, is.Error(cmd.Execute(), tc.expectedError))
} }
} }
@ -119,7 +120,7 @@ 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.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("init-%s.golden", tc.name)) golden.Assert(t, cli.OutBuffer().String(), fmt.Sprintf("init-%s.golden", tc.name))
} }
} }

View File

@ -9,8 +9,9 @@ import (
"github.com/docker/cli/internal/test/testutil" "github.com/docker/cli/internal/test/testutil"
"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/gotestyourself/gotestyourself/assert"
is "github.com/gotestyourself/gotestyourself/assert/cmp"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/stretchr/testify/assert"
) )
func TestSwarmJoinErrors(t *testing.T) { func TestSwarmJoinErrors(t *testing.T) {
@ -94,7 +95,7 @@ func TestSwarmJoin(t *testing.T) {
}) })
cmd := newJoinCommand(cli) cmd := newJoinCommand(cli)
cmd.SetArgs([]string{"remote"}) cmd.SetArgs([]string{"remote"})
assert.NoError(t, cmd.Execute()) assert.Check(t, cmd.Execute())
assert.Equal(t, strings.TrimSpace(cli.OutBuffer().String()), tc.expected) assert.Check(t, is.Equal(strings.TrimSpace(cli.OutBuffer().String()), tc.expected))
} }
} }

Some files were not shown because too many files have changed in this diff Show More