mirror of https://github.com/docker/cli.git
Merge pull request #879 from dnephin/update-assertions
Replace testify assertions with gotestyourself/assert
This commit is contained in:
commit
a0b19f0ec2
|
@ -5,7 +5,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestLoadFileV01Success(t *testing.T) {
|
||||
|
@ -25,9 +26,9 @@ func TestLoadFileV01Success(t *testing.T) {
|
|||
}`)
|
||||
|
||||
bundle, err := LoadFile(reader)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "0.1", bundle.Version)
|
||||
assert.Len(t, bundle.Services, 2)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal("0.1", bundle.Version))
|
||||
assert.Check(t, is.Len(bundle.Services, 2))
|
||||
}
|
||||
|
||||
func TestLoadFileSyntaxError(t *testing.T) {
|
||||
|
@ -37,7 +38,7 @@ func TestLoadFileSyntaxError(t *testing.T) {
|
|||
}`)
|
||||
|
||||
_, 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) {
|
||||
|
@ -52,7 +53,7 @@ func TestLoadFileTypeError(t *testing.T) {
|
|||
}`)
|
||||
|
||||
_, 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) {
|
||||
|
@ -66,12 +67,12 @@ func TestPrint(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
assert.NoError(t, Print(&buffer, bundle))
|
||||
assert.Check(t, Print(&buffer, bundle))
|
||||
output := buffer.String()
|
||||
assert.Contains(t, output, "\"Image\": \"image\"")
|
||||
assert.Contains(t, output,
|
||||
assert.Check(t, is.Contains(output, "\"Image\": \"image\""))
|
||||
assert.Check(t, is.Contains(output,
|
||||
`"Command": [
|
||||
"echo",
|
||||
"something"
|
||||
]`)
|
||||
]`))
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCheckpointCreateErrors(t *testing.T) {
|
||||
|
@ -63,10 +64,10 @@ func TestCheckpointCreateWithOptions(t *testing.T) {
|
|||
cmd.SetArgs([]string{"container-foo", checkpoint})
|
||||
cmd.Flags().Set("leave-running", "true")
|
||||
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "container-foo", containerID)
|
||||
assert.Equal(t, checkpoint, checkpointID)
|
||||
assert.Equal(t, "/dir/foo", checkpointDir)
|
||||
assert.Equal(t, false, exit)
|
||||
assert.Equal(t, checkpoint, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("container-foo", containerID))
|
||||
assert.Check(t, is.Equal(checkpoint, checkpointID))
|
||||
assert.Check(t, is.Equal("/dir/foo", checkpointDir))
|
||||
assert.Check(t, is.Equal(false, exit))
|
||||
assert.Check(t, is.Equal(checkpoint, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCheckpointListErrors(t *testing.T) {
|
||||
|
@ -60,8 +61,8 @@ func TestCheckpointListWithOptions(t *testing.T) {
|
|||
cmd := newListCommand(cli)
|
||||
cmd.SetArgs([]string{"container-foo"})
|
||||
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "container-foo", containerID)
|
||||
assert.Equal(t, "/dir/foo", checkpointDir)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("container-foo", containerID))
|
||||
assert.Check(t, is.Equal("/dir/foo", checkpointDir))
|
||||
golden.Assert(t, cli.OutBuffer().String(), "checkpoint-list-with-options.golden")
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCheckpointRemoveErrors(t *testing.T) {
|
||||
|
@ -58,8 +59,8 @@ func TestCheckpointRemoveWithOptions(t *testing.T) {
|
|||
cmd := newRemoveCommand(cli)
|
||||
cmd.SetArgs([]string{"container-foo", "checkpoint-bar"})
|
||||
cmd.Flags().Set("checkpoint-dir", "/dir/foo")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "container-foo", containerID)
|
||||
assert.Equal(t, "checkpoint-bar", checkpointID)
|
||||
assert.Equal(t, "/dir/foo", checkpointDir)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("container-foo", containerID))
|
||||
assert.Check(t, is.Equal("checkpoint-bar", checkpointID))
|
||||
assert.Check(t, is.Equal("/dir/foo", checkpointDir))
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ import (
|
|||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/fs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -28,15 +28,15 @@ func TestNewAPIClientFromFlags(t *testing.T) {
|
|||
},
|
||||
}
|
||||
apiclient, err := NewAPIClientFromFlags(opts, configFile)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, host, apiclient.DaemonHost())
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(host, apiclient.DaemonHost()))
|
||||
|
||||
expectedHeaders := map[string]string{
|
||||
"My-Header": "Custom-Value",
|
||||
"User-Agent": UserAgent(),
|
||||
}
|
||||
assert.Equal(t, expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders())
|
||||
assert.Equal(t, api.DefaultVersion, apiclient.ClientVersion())
|
||||
assert.Check(t, is.DeepEqual(expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders()))
|
||||
assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
|
||||
}
|
||||
|
||||
func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
||||
|
@ -46,20 +46,20 @@ func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
|
|||
opts := &flags.CommonOptions{}
|
||||
configFile := &configfile.ConfigFile{}
|
||||
apiclient, err := NewAPIClientFromFlags(opts, configFile)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, customVersion, apiclient.ClientVersion())
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(customVersion, apiclient.ClientVersion()))
|
||||
}
|
||||
|
||||
// TODO: use gotestyourself/env.Patch
|
||||
func patchEnvVariable(t *testing.T, key, value string) func() {
|
||||
oldValue, ok := os.LookupEnv(key)
|
||||
require.NoError(t, os.Setenv(key, value))
|
||||
assert.NilError(t, os.Setenv(key, value))
|
||||
return func() {
|
||||
if !ok {
|
||||
require.NoError(t, os.Unsetenv(key))
|
||||
assert.NilError(t, os.Unsetenv(key))
|
||||
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.initializeFromClient()
|
||||
assert.Equal(t, testcase.expectedServer, cli.serverInfo)
|
||||
assert.Equal(t, testcase.negotiated, apiclient.negotiated)
|
||||
assert.Check(t, is.DeepEqual(testcase.expectedServer, cli.serverInfo))
|
||||
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}
|
||||
cliconfig.SetDir(dir.Path())
|
||||
err := cli.Initialize(flags.NewClientOptions())
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(testcase.expectedExperimentalCLI, cli.ClientInfo().HasExperimental))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -267,9 +267,9 @@ func TestOrchestratorSwitch(t *testing.T) {
|
|||
options.Common.Orchestrator = testcase.flagOrchestrator
|
||||
}
|
||||
err := cli.Initialize(options)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes())
|
||||
assert.Equal(t, testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator))
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(testcase.expectedKubernetes, cli.ClientInfo().HasKubernetes()))
|
||||
assert.Check(t, is.Equal(testcase.expectedOrchestrator, string(cli.ClientInfo().Orchestrator)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ func TestGetClientWithPassword(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,10 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const configDataFile = "config-create-with-name.golden"
|
||||
|
@ -70,9 +71,9 @@ func TestConfigCreateWithName(t *testing.T) {
|
|||
|
||||
cmd := newConfigCreateCommand(cli)
|
||||
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
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) {
|
||||
|
@ -83,7 +84,7 @@ func TestConfigCreateWithLabels(t *testing.T) {
|
|||
name := "foo"
|
||||
|
||||
data, err := ioutil.ReadFile(filepath.Join("testdata", configDataFile))
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
|
||||
expected := swarm.ConfigSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
|
@ -109,8 +110,8 @@ func TestConfigCreateWithLabels(t *testing.T) {
|
|||
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
|
||||
cmd.Flags().Set("label", "lbl1=Label-foo")
|
||||
cmd.Flags().Set("label", "lbl2=Label-bar")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
||||
func TestConfigCreateWithTemplatingDriver(t *testing.T) {
|
||||
|
@ -138,6 +139,6 @@ func TestConfigCreateWithTemplatingDriver(t *testing.T) {
|
|||
cmd := newConfigCreateCommand(cli)
|
||||
cmd.SetArgs([]string{name, filepath.Join("testdata", configDataFile)})
|
||||
cmd.Flags().Set("template-driver", expectedDriver.Name)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfigInspectErrors(t *testing.T) {
|
||||
|
@ -96,7 +96,7 @@ func TestConfigInspectWithoutFormat(t *testing.T) {
|
|||
cli := test.NewFakeCli(&fakeClient{configInspectFunc: tc.configInspectFunc})
|
||||
cmd := newConfigInspectCommand(cli)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ func TestConfigInspectWithFormat(t *testing.T) {
|
|||
cmd := newConfigInspectCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ func TestConfigInspectPretty(t *testing.T) {
|
|||
|
||||
cmd.SetArgs([]string{"configID"})
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ import (
|
|||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfigListErrors(t *testing.T) {
|
||||
|
@ -72,7 +73,7 @@ func TestConfigList(t *testing.T) {
|
|||
},
|
||||
})
|
||||
cmd := newConfigListCommand(cli)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "config-list-sort.golden")
|
||||
}
|
||||
|
||||
|
@ -89,7 +90,7 @@ func TestConfigListWithQuietOption(t *testing.T) {
|
|||
})
|
||||
cmd := newConfigListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,7 @@ func TestConfigListWithConfigFormat(t *testing.T) {
|
|||
ConfigFormat: "{{ .Name }} {{ .Labels }}",
|
||||
})
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -125,15 +126,15 @@ func TestConfigListWithFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newConfigListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
func TestConfigListWithFilter(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
configListFunc: func(options types.ConfigListOptions) ([]swarm.Config, error) {
|
||||
assert.Equal(t, "foo", options.Filters.Get("name")[0])
|
||||
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])
|
||||
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]))
|
||||
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
|
||||
return []swarm.Config{
|
||||
*Config(ConfigID("ID-foo"),
|
||||
ConfigName("foo"),
|
||||
|
@ -153,6 +154,6 @@ func TestConfigListWithFilter(t *testing.T) {
|
|||
cmd := newConfigListCommand(cli)
|
||||
cmd.Flags().Set("filter", "name=foo")
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfigRemoveErrors(t *testing.T) {
|
||||
|
@ -52,9 +53,9 @@ func TestConfigRemoveWithName(t *testing.T) {
|
|||
})
|
||||
cmd := newConfigRemoveCommand(cli)
|
||||
cmd.SetArgs(names)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n"))
|
||||
assert.Equal(t, names, removedConfigs)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
|
||||
assert.Check(t, is.DeepEqual(names, removedConfigs))
|
||||
}
|
||||
|
||||
func TestConfigRemoveContinueAfterError(t *testing.T) {
|
||||
|
@ -74,6 +75,6 @@ func TestConfigRemoveContinueAfterError(t *testing.T) {
|
|||
cmd := newConfigRemoveCommand(cli)
|
||||
cmd.SetArgs(names)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
assert.EqualError(t, cmd.Execute(), "error removing config: foo")
|
||||
assert.Equal(t, names, removedConfigs)
|
||||
assert.Check(t, is.Error(cmd.Execute(), "error removing config: foo"))
|
||||
assert.Check(t, is.DeepEqual(names, removedConfigs))
|
||||
}
|
||||
|
|
|
@ -7,11 +7,11 @@ import (
|
|||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewAttachCommandErrors(t *testing.T) {
|
||||
|
@ -74,7 +74,7 @@ func TestNewAttachCommandErrors(t *testing.T) {
|
|||
cmd := NewAttachCommand(test.NewFakeCli(&fakeClient{inspectFunc: tc.containerInspectFunc}))
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,9 +101,7 @@ func TestGetExitStatus(t *testing.T) {
|
|||
},
|
||||
{
|
||||
result: &container.ContainerWaitOKBody{
|
||||
Error: &container.ContainerWaitOKBodyError{
|
||||
expectedErr.Error(),
|
||||
},
|
||||
Error: &container.ContainerWaitOKBodyError{expectedErr.Error()},
|
||||
},
|
||||
expectedError: expectedErr,
|
||||
},
|
||||
|
@ -123,6 +121,10 @@ func TestGetExitStatus(t *testing.T) {
|
|||
resultC <- *testcase.result
|
||||
}
|
||||
err := getExitStatus(errC, resultC)
|
||||
assert.Equal(t, testcase.expectedError, err)
|
||||
if testcase.expectedError == nil {
|
||||
assert.Check(t, err)
|
||||
} else {
|
||||
assert.Check(t, is.Error(err, testcase.expectedError.Error()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,10 +12,10 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRunCopyWithInvalidArguments(t *testing.T) {
|
||||
|
@ -44,7 +44,7 @@ func TestRunCopyWithInvalidArguments(t *testing.T) {
|
|||
for _, testcase := range testcases {
|
||||
t.Run(testcase.doc, func(t *testing.T) {
|
||||
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{
|
||||
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
|
||||
},
|
||||
}
|
||||
options := copyOptions{source: "container:/path", destination: "-"}
|
||||
cli := test.NewFakeCli(fakeClient)
|
||||
err := runCopy(cli, options)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tarContent, cli.OutBuffer().String())
|
||||
assert.Equal(t, "", cli.ErrBuffer().String())
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(tarContent, cli.OutBuffer().String()))
|
||||
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
|
||||
}
|
||||
|
||||
func TestRunCopyFromContainerToFilesystem(t *testing.T) {
|
||||
|
@ -73,7 +73,7 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
|
|||
|
||||
fakeClient := &fakeClient{
|
||||
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{})
|
||||
return readCloser, types.ContainerPathStat{}, err
|
||||
},
|
||||
|
@ -81,13 +81,13 @@ func TestRunCopyFromContainerToFilesystem(t *testing.T) {
|
|||
options := copyOptions{source: "container:/path", destination: destDir.Path()}
|
||||
cli := test.NewFakeCli(fakeClient)
|
||||
err := runCopy(cli, options)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "", cli.OutBuffer().String())
|
||||
assert.Equal(t, "", cli.ErrBuffer().String())
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal("", cli.OutBuffer().String()))
|
||||
assert.Check(t, is.Equal("", cli.ErrBuffer().String()))
|
||||
|
||||
content, err := ioutil.ReadFile(destDir.Join("file1"))
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "content\n", string(content))
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal("content\n", string(content)))
|
||||
}
|
||||
|
||||
func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.T) {
|
||||
|
@ -97,7 +97,7 @@ func TestRunCopyFromContainerToFilesystemMissingDestinationDirectory(t *testing.
|
|||
|
||||
fakeClient := &fakeClient{
|
||||
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{})
|
||||
return readCloser, types.ContainerPathStat{}, err
|
||||
},
|
||||
|
@ -181,8 +181,8 @@ func TestSplitCpArg(t *testing.T) {
|
|||
skip.IfCondition(t, testcase.os != "" && testcase.os != runtime.GOOS)
|
||||
|
||||
container, path := splitCpArg(testcase.path)
|
||||
assert.Equal(t, testcase.expectedContainer, container)
|
||||
assert.Equal(t, testcase.expectedPath, path)
|
||||
assert.Check(t, is.Equal(testcase.expectedContainer, container))
|
||||
assert.Check(t, is.Equal(testcase.expectedPath, path))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,23 +10,23 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/fs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCIDFileNoOPWithNoFilename(t *testing.T) {
|
||||
file, err := newCIDFile("")
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, &cidFile{}, file)
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, &cidFile{}, file, cmp.AllowUnexported(cidFile{}))
|
||||
|
||||
assert.NoError(t, file.Write("id"))
|
||||
assert.NoError(t, file.Close())
|
||||
assert.Check(t, file.Write("id"))
|
||||
assert.Check(t, file.Close())
|
||||
}
|
||||
|
||||
func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
|
||||
|
@ -34,7 +34,7 @@ func TestNewCIDFileWhenFileAlreadyExists(t *testing.T) {
|
|||
defer tempfile.Remove()
|
||||
|
||||
_, err := newCIDFile(tempfile.Path())
|
||||
testutil.ErrorContains(t, err, "Container ID file found")
|
||||
assert.ErrorContains(t, err, "Container ID file found")
|
||||
}
|
||||
|
||||
func TestCIDFileCloseWithNoWrite(t *testing.T) {
|
||||
|
@ -43,12 +43,12 @@ func TestCIDFileCloseWithNoWrite(t *testing.T) {
|
|||
|
||||
path := tempdir.Join("cidfile")
|
||||
file, err := newCIDFile(path)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, file.path, path)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(file.path, path))
|
||||
|
||||
assert.NoError(t, file.Close())
|
||||
assert.Check(t, file.Close())
|
||||
_, err = os.Stat(path)
|
||||
assert.True(t, os.IsNotExist(err))
|
||||
assert.Check(t, os.IsNotExist(err))
|
||||
}
|
||||
|
||||
func TestCIDFileCloseWithWrite(t *testing.T) {
|
||||
|
@ -57,18 +57,18 @@ func TestCIDFileCloseWithWrite(t *testing.T) {
|
|||
|
||||
path := tempdir.Join("cidfile")
|
||||
file, err := newCIDFile(path)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
content := "id"
|
||||
assert.NoError(t, file.Write(content))
|
||||
assert.Check(t, file.Write(content))
|
||||
|
||||
actual, err := ioutil.ReadFile(path)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, content, string(actual))
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(content, string(actual)))
|
||||
|
||||
assert.NoError(t, file.Close())
|
||||
assert.Check(t, file.Close())
|
||||
_, err = os.Stat(path)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func TestCreateContainerPullsImageIfMissing(t *testing.T) {
|
||||
|
@ -108,11 +108,11 @@ func TestCreateContainerPullsImageIfMissing(t *testing.T) {
|
|||
HostConfig: &container.HostConfig{},
|
||||
}
|
||||
body, err := createContainer(context.Background(), cli, config, "name", runtime.GOOS)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
expected := container.ContainerCreateCreatedBody{ID: containerID}
|
||||
assert.Equal(t, expected, *body)
|
||||
assert.Check(t, is.DeepEqual(expected, *body))
|
||||
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{}
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -106,7 +107,7 @@ func TestParseExec(t *testing.T) {
|
|||
|
||||
for _, testcase := range testcases {
|
||||
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 != "" {
|
||||
testutil.ErrorContains(t, err, testcase.expectedError)
|
||||
} else {
|
||||
if !assert.NoError(t, err) {
|
||||
if !assert.Check(t, err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
assert.Equal(t, testcase.expectedOut, cli.OutBuffer().String())
|
||||
assert.Equal(t, testcase.expectedErr, cli.ErrBuffer().String())
|
||||
assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
|
||||
assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -192,12 +193,12 @@ func TestGetExecExitStatus(t *testing.T) {
|
|||
for _, testcase := range testcases {
|
||||
client := &fakeClient{
|
||||
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
|
||||
},
|
||||
}
|
||||
err := getExecExitStatus(context.Background(), client, execID)
|
||||
assert.Equal(t, testcase.expectedError, err)
|
||||
assert.Check(t, is.Equal(testcase.expectedError, err))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
)
|
||||
|
||||
|
@ -69,7 +69,7 @@ func TestContainerListWithoutFormat(t *testing.T) {
|
|||
},
|
||||
})
|
||||
cmd := newListCommand(cli)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "container-list-without-format.golden")
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ func TestContainerListNoTrunc(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ func TestContainerListNamesMultipleTime(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -116,20 +116,20 @@ func TestContainerListFormatTemplateWithArg(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
func TestContainerListFormatSizeSetsOption(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
containerListFunc: func(options types.ContainerListOptions) ([]types.Container, error) {
|
||||
assert.True(t, options.Size)
|
||||
assert.Check(t, options.Size)
|
||||
return []types.Container{}, nil
|
||||
},
|
||||
})
|
||||
cmd := newListCommand(cli)
|
||||
cmd.Flags().Set("format", `{{.Size}}`)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
||||
func TestContainerListWithConfigFormat(t *testing.T) {
|
||||
|
@ -145,7 +145,7 @@ func TestContainerListWithConfigFormat(t *testing.T) {
|
|||
PsFormat: "{{ .Names }} {{ .Image }} {{ .Labels }}",
|
||||
})
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -160,6 +160,6 @@ func TestContainerListWithFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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) {
|
||||
|
@ -51,12 +52,12 @@ func TestRunLogs(t *testing.T) {
|
|||
if testcase.expectedError != "" {
|
||||
testutil.ErrorContains(t, err, testcase.expectedError)
|
||||
} else {
|
||||
if !assert.NoError(t, err) {
|
||||
if !assert.Check(t, err) {
|
||||
return
|
||||
}
|
||||
}
|
||||
assert.Equal(t, testcase.expectedOut, cli.OutBuffer().String())
|
||||
assert.Equal(t, testcase.expectedErr, cli.ErrBuffer().String())
|
||||
assert.Check(t, is.Equal(testcase.expectedOut, cli.OutBuffer().String()))
|
||||
assert.Check(t, is.Equal(testcase.expectedErr, cli.ErrBuffer().String()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ import (
|
|||
"github.com/docker/docker/api/types/container"
|
||||
networktypes "github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/go-connections/nat"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/pflag"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestValidateAttach(t *testing.T) {
|
||||
|
@ -67,12 +67,12 @@ func setupRunFlags() (*pflag.FlagSet, *containerOptions) {
|
|||
|
||||
func parseMustError(t *testing.T, args string) {
|
||||
_, _, _, err := parseRun(strings.Split(args+" ubuntu bash", " "))
|
||||
assert.Error(t, err, args)
|
||||
assert.ErrorContains(t, err, "", args)
|
||||
}
|
||||
|
||||
func mustParse(t *testing.T, args string) (*container.Config, *container.HostConfig) {
|
||||
config, hostConfig, _, err := parseRun(append(strings.Split(args, " "), "ubuntu", "bash"))
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
return config, hostConfig
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ func TestRunFlagsParseWithMemory(t *testing.T) {
|
|||
testutil.ErrorContains(t, err, `invalid argument "invalid" for "-m, --memory" flag`)
|
||||
|
||||
_, 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) {
|
||||
|
@ -249,10 +249,10 @@ func TestParseWithMemorySwap(t *testing.T) {
|
|||
testutil.ErrorContains(t, err, `invalid argument "invalid" for "--memory-swap" flag`)
|
||||
|
||||
_, 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")
|
||||
assert.Equal(t, int64(-1), hostconfig.MemorySwap)
|
||||
assert.Check(t, is.Equal(int64(-1), hostconfig.MemorySwap))
|
||||
}
|
||||
|
||||
func TestParseHostname(t *testing.T) {
|
||||
|
@ -373,13 +373,13 @@ func TestParseModes(t *testing.T) {
|
|||
// pid ko
|
||||
flags, copts := setupRunFlags()
|
||||
args := []string{"--pid=container:", "img", "cmd"}
|
||||
require.NoError(t, flags.Parse(args))
|
||||
assert.NilError(t, flags.Parse(args))
|
||||
_, err := parse(flags, copts)
|
||||
testutil.ErrorContains(t, err, "--pid: invalid PID mode")
|
||||
|
||||
// pid ok
|
||||
_, hostconfig, _, err := parseRun([]string{"--pid=host", "img", "cmd"})
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
if !hostconfig.PidMode.Valid() {
|
||||
t.Fatalf("Expected a valid PidMode, got %v", hostconfig.PidMode)
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ func TestParseModes(t *testing.T) {
|
|||
|
||||
// uts ok
|
||||
_, hostconfig, _, err = parseRun([]string{"--uts=host", "img", "cmd"})
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
if !hostconfig.UTSMode.Valid() {
|
||||
t.Fatalf("Expected a valid UTSMode, got %v", hostconfig.UTSMode)
|
||||
}
|
||||
|
@ -406,7 +406,7 @@ func TestRunFlagsParseShmSize(t *testing.T) {
|
|||
|
||||
// shm-size ok
|
||||
_, hostconfig, _, err := parseRun([]string{"--shm-size=128m", "img", "cmd"})
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
if hostconfig.ShmSize != 134217728 {
|
||||
t.Fatalf("Expected a valid ShmSize, got %d", hostconfig.ShmSize)
|
||||
}
|
||||
|
|
|
@ -4,13 +4,14 @@ import (
|
|||
"testing"
|
||||
|
||||
"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) {
|
||||
filters := opts.NewFilterOpt()
|
||||
assert.NoError(t, filters.Set("foo=bar"))
|
||||
assert.NoError(t, filters.Set("baz=foo"))
|
||||
assert.Check(t, filters.Set("foo=bar"))
|
||||
assert.Check(t, filters.Set("baz=foo"))
|
||||
|
||||
contexts := []struct {
|
||||
psOpts *psOptions
|
||||
|
@ -101,12 +102,12 @@ func TestBuildContainerListOptions(t *testing.T) {
|
|||
|
||||
for _, c := range contexts {
|
||||
options, err := buildContainerListOptions(c.psOpts)
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
|
||||
assert.Equal(t, c.expectedAll, options.All)
|
||||
assert.Equal(t, c.expectedSize, options.Size)
|
||||
assert.Equal(t, c.expectedLimit, options.Limit)
|
||||
assert.Equal(t, len(c.expectedFilters), options.Filters.Len())
|
||||
assert.Check(t, is.Equal(c.expectedAll, options.All))
|
||||
assert.Check(t, is.Equal(c.expectedSize, options.Size))
|
||||
assert.Check(t, is.Equal(c.expectedLimit, options.Limit))
|
||||
assert.Check(t, is.Equal(len(c.expectedFilters), options.Filters.Len()))
|
||||
|
||||
for k, v := range c.expectedFilters {
|
||||
f := options.Filters
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
)
|
||||
|
||||
func TestRunLabel(t *testing.T) {
|
||||
|
@ -21,5 +21,5 @@ func TestRunLabel(t *testing.T) {
|
|||
cmd := NewRunCommand(cli)
|
||||
cmd.Flags().Set("detach", "true")
|
||||
cmd.SetArgs([]string{"--label", "foo", "busybox"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
)
|
||||
|
||||
func TestCalculateMemUsageUnixNoCache(t *testing.T) {
|
||||
|
@ -15,7 +16,7 @@ func TestCalculateMemUsageUnixNoCache(t *testing.T) {
|
|||
result := calculateMemUsageUnixNoCache(stats)
|
||||
|
||||
// Then
|
||||
assert.InDelta(t, 100.0, result, 1e-6)
|
||||
assert.Assert(t, inDelta(100.0, result, 1e-6))
|
||||
}
|
||||
|
||||
func TestCalculateMemPercentUnixNoCache(t *testing.T) {
|
||||
|
@ -27,10 +28,20 @@ func TestCalculateMemPercentUnixNoCache(t *testing.T) {
|
|||
// When and Then
|
||||
t.Run("Limit is set", func(t *testing.T) {
|
||||
result := calculateMemPercentUnixNoCache(someLimit, used)
|
||||
assert.InDelta(t, 70.0, result, 1e-6)
|
||||
assert.Assert(t, inDelta(70.0, result, 1e-6))
|
||||
})
|
||||
t.Run("No limit, no cgroup data", func(t *testing.T) {
|
||||
result := calculateMemPercentUnixNoCache(noLimit, used)
|
||||
assert.InDelta(t, 0.0, result, 1e-6)
|
||||
assert.Assert(t, inDelta(0.0, result, 1e-6))
|
||||
})
|
||||
}
|
||||
|
||||
func inDelta(x, y, delta float64) func() (bool, string) {
|
||||
return func() (bool, string) {
|
||||
diff := x - y
|
||||
if diff < -delta || diff > delta {
|
||||
return false, fmt.Sprintf("%f != %f within %f", x, y, delta)
|
||||
}
|
||||
return true, ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api"
|
||||
"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/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -64,6 +65,6 @@ func TestWaitExitOrRemoved(t *testing.T) {
|
|||
for _, testcase := range testcases {
|
||||
statusC := waitExitOrRemoved(context.Background(), client, testcase.cid, true)
|
||||
exitCode := <-statusC
|
||||
assert.Equal(t, testcase.exitCode, exitCode)
|
||||
assert.Check(t, is.Equal(testcase.exitCode, exitCode))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
)
|
||||
|
||||
func TestCheckpointContextFormatWrite(t *testing.T) {
|
||||
|
@ -46,10 +46,7 @@ checkpoint-3:
|
|||
out := bytes.NewBufferString("")
|
||||
testcase.context.Output = out
|
||||
err := CheckpointWrite(testcase.context, checkpoints)
|
||||
if err != nil {
|
||||
assert.Error(t, err, testcase.expected)
|
||||
} else {
|
||||
assert.NilError(t, err)
|
||||
assert.Equal(t, out.String(), testcase.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"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) {
|
||||
|
@ -55,9 +56,9 @@ id_rsa
|
|||
out := bytes.NewBufferString("")
|
||||
testcase.context.Output = out
|
||||
if err := ConfigWrite(testcase.context, configs); err != nil {
|
||||
assert.Error(t, err, testcase.expected)
|
||||
assert.ErrorContains(t, err, testcase.expected)
|
||||
} else {
|
||||
assert.Equal(t, out.String(), testcase.expected)
|
||||
assert.Check(t, is.Equal(out.String(), testcase.expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestContainerPsContext(t *testing.T) {
|
||||
|
@ -244,9 +244,9 @@ size: 0B
|
|||
testcase.context.Output = out
|
||||
err := ContainerWrite(testcase.context, containers)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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 {
|
||||
ContainerWrite(context.context, containers)
|
||||
assert.Equal(t, context.expected, out.String())
|
||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
||||
// Clean buffer
|
||||
out.Reset()
|
||||
}
|
||||
|
@ -359,8 +359,8 @@ func TestContainerContextWriteJSON(t *testing.T) {
|
|||
msg := fmt.Sprintf("Output: line %d: %s", i, line)
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(line), &m)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, expectedJSONs[i], m, msg)
|
||||
assert.NilError(t, err, 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)
|
||||
var s string
|
||||
err := json.Unmarshal([]byte(line), &s)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, containers[i].ID, s, msg)
|
||||
assert.NilError(t, err, msg)
|
||||
assert.Check(t, is.Equal(containers[i].ID, s), msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -653,6 +653,6 @@ func TestDisplayablePorts(t *testing.T) {
|
|||
|
||||
for _, port := range cases {
|
||||
actual := DisplayablePorts(port.ports)
|
||||
assert.Equal(t, port.expected, actual)
|
||||
assert.Check(t, is.Equal(port.expected, actual))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ import (
|
|||
"strings"
|
||||
"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) {
|
||||
|
@ -23,5 +24,5 @@ func compareMultipleValues(t *testing.T, value, expected string) {
|
|||
keyval := strings.Split(expected, "=")
|
||||
expMap[keyval[0]] = keyval[1]
|
||||
}
|
||||
assert.Equal(t, expMap, entriesMap)
|
||||
assert.Check(t, is.DeepEqual(expMap, entriesMap))
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"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) {
|
||||
|
@ -51,9 +52,9 @@ D: /usr/app/old_app.js
|
|||
testcase.context.Output = out
|
||||
err := DiffWrite(testcase.context, diffs)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} else {
|
||||
assert.Equal(t, testcase.expected, out.String())
|
||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,9 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestDiskUsageContextFormatWrite(t *testing.T) {
|
||||
|
@ -101,9 +102,9 @@ Build Cache 0B
|
|||
out := bytes.NewBufferString("")
|
||||
testcase.context.Output = out
|
||||
if err := testcase.context.Write(); err != nil {
|
||||
assert.Equal(t, testcase.expected, err.Error())
|
||||
assert.Check(t, is.Equal(testcase.expected, err.Error()))
|
||||
} else {
|
||||
assert.Equal(t, testcase.expected, out.String())
|
||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ package formatter
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestEllipsis(t *testing.T) {
|
||||
|
@ -25,6 +26,6 @@ func TestEllipsis(t *testing.T) {
|
|||
}
|
||||
|
||||
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)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"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 {
|
||||
|
@ -218,7 +219,7 @@ imageID4 24 hours ago /bin/bash grep
|
|||
|
||||
for _, context := range contexts {
|
||||
HistoryWrite(context.context, true, histories)
|
||||
assert.Equal(t, context.expected, out.String())
|
||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
||||
// Clean buffer
|
||||
out.Reset()
|
||||
}
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"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) {
|
||||
|
@ -83,7 +84,7 @@ func TestImageContext(t *testing.T) {
|
|||
if strings.Contains(v, ",") {
|
||||
compareMultipleValues(t, v, c.expValue)
|
||||
} 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
|
||||
err := ImageWrite(testcase.context, images)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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 {
|
||||
ImageWrite(context.context, images)
|
||||
assert.Equal(t, context.expected, out.String())
|
||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
||||
// Clean buffer
|
||||
out.Reset()
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestNetworkContext(t *testing.T) {
|
||||
|
@ -162,9 +162,9 @@ foobar_bar 2017-01-01 00:00:00 +0000 UTC
|
|||
testcase.context.Output = out
|
||||
err := NetworkWrite(testcase.context, networks)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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)
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(line), &m)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, expectedJSONs[i], m, msg)
|
||||
assert.NilError(t, err, 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)
|
||||
var s string
|
||||
err := json.Unmarshal([]byte(line), &s)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, networks[i].ID, s, msg)
|
||||
assert.NilError(t, err, msg)
|
||||
assert.Check(t, is.Equal(networks[i].ID, s), msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestNodeContext(t *testing.T) {
|
||||
|
@ -203,9 +203,9 @@ foobar_boo Unknown
|
|||
testcase.context.Output = out
|
||||
err := NodeWrite(testcase.context, nodes, types.Info{Swarm: swarm.Info{Cluster: &testcase.clusterInfo}})
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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)
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(line), &m)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, testcase.expected[i], m, msg)
|
||||
assert.NilError(t, err, 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)
|
||||
var s string
|
||||
err := json.Unmarshal([]byte(line), &s)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, nodes[i].ID, s, msg)
|
||||
assert.NilError(t, err, msg)
|
||||
assert.Check(t, is.Equal(nodes[i].ID, s), msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,5 +344,5 @@ data
|
|||
Issuer Subject: c3ViamVjdA==
|
||||
Issuer Public Key: cHViS2V5
|
||||
`
|
||||
assert.Equal(t, expected, out.String())
|
||||
assert.Check(t, is.Equal(expected, out.String()))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"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) {
|
||||
|
@ -131,9 +132,9 @@ foobar_bar
|
|||
testcase.context.Output = out
|
||||
err := PluginWrite(testcase.context, plugins)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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 {
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, plugins[i].ID, s)
|
||||
assert.Check(t, is.Equal(plugins[i].ID, s))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
"testing"
|
||||
|
||||
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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSearchContext(t *testing.T) {
|
||||
|
@ -154,9 +155,9 @@ result2 5
|
|||
testcase.context.Output = out
|
||||
err := SearchWrite(testcase.context, results, false, 0)
|
||||
if err != nil {
|
||||
assert.Error(t, err, testcase.expected)
|
||||
assert.Check(t, is.ErrorContains(err, testcase.expected))
|
||||
} 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
|
||||
err := SearchWrite(testcase.context, results, true, 0)
|
||||
if err != nil {
|
||||
assert.Error(t, err, testcase.expected)
|
||||
assert.Check(t, is.ErrorContains(err, testcase.expected))
|
||||
} 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
|
||||
err := SearchWrite(testcase.context, results, false, 6)
|
||||
if err != nil {
|
||||
assert.Error(t, err, testcase.expected)
|
||||
assert.Check(t, is.ErrorContains(err, testcase.expected))
|
||||
} 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 {
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, s, results[i].Name)
|
||||
assert.Check(t, is.Equal(s, results[i].Name))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
"time"
|
||||
|
||||
"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) {
|
||||
|
@ -55,9 +56,9 @@ id_rsa
|
|||
out := bytes.NewBufferString("")
|
||||
testcase.context.Output = out
|
||||
if err := SecretWrite(testcase.context, secrets); err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} else {
|
||||
assert.Equal(t, testcase.expected, out.String())
|
||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"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/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestServiceContextWrite(t *testing.T) {
|
||||
|
@ -126,9 +126,9 @@ bar
|
|||
testcase.context.Output = out
|
||||
err := ServiceListWrite(testcase.context, services, info)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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)
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(line), &m)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, expectedJSONs[i], m, msg)
|
||||
assert.NilError(t, err, msg)
|
||||
assert.Check(t, is.DeepEqual(expectedJSONs[i], m), msg)
|
||||
}
|
||||
}
|
||||
func TestServiceContextWriteJSONField(t *testing.T) {
|
||||
|
@ -220,8 +220,8 @@ func TestServiceContextWriteJSONField(t *testing.T) {
|
|||
msg := fmt.Sprintf("Output: line %d: %s", i, line)
|
||||
var s string
|
||||
err := json.Unmarshal([]byte(line), &s)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, services[i].Spec.Name, s, msg)
|
||||
assert.NilError(t, err, 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()))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,8 @@ import (
|
|||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestStackContextWrite(t *testing.T) {
|
||||
|
@ -56,9 +57,9 @@ bar
|
|||
testcase.context.Output = out
|
||||
err := StackWrite(testcase.context, stacks)
|
||||
if err != nil {
|
||||
assert.Error(t, err, testcase.expected)
|
||||
assert.Check(t, is.ErrorContains(err, testcase.expected))
|
||||
} else {
|
||||
assert.Equal(t, out.String(), testcase.expected)
|
||||
assert.Check(t, is.Equal(out.String(), testcase.expected))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"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) {
|
||||
|
@ -116,9 +117,9 @@ container2 --
|
|||
te.context.Output = &out
|
||||
err := ContainerStatsWrite(te.context, stats, "linux", false)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, te.expected)
|
||||
assert.Check(t, is.Error(err, te.expected))
|
||||
} 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
|
||||
err := ContainerStatsWrite(te.context, stats, "windows", false)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, te.expected)
|
||||
assert.Check(t, is.Error(err, te.expected))
|
||||
} 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 {
|
||||
ContainerStatsWrite(context.context, []StatsEntry{}, "linux", false)
|
||||
assert.Equal(t, context.expected, out.String())
|
||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
||||
// Clean buffer
|
||||
out.Reset()
|
||||
}
|
||||
|
@ -259,7 +260,7 @@ func TestContainerStatsContextWriteWithNoStatsWindows(t *testing.T) {
|
|||
|
||||
for _, context := range contexts {
|
||||
ContainerStatsWrite(context.context, []StatsEntry{}, "windows", false)
|
||||
assert.Equal(t, context.expected, out.String())
|
||||
assert.Check(t, is.Equal(context.expected, out.String()))
|
||||
// Clean buffer
|
||||
out.Reset()
|
||||
}
|
||||
|
@ -293,7 +294,7 @@ func TestContainerStatsContextWriteTrunc(t *testing.T) {
|
|||
|
||||
for _, context := range contexts {
|
||||
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
|
||||
out.Reset()
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestTaskContextWrite(t *testing.T) {
|
||||
|
@ -74,9 +75,9 @@ foobar_bar foo2
|
|||
testcase.context.Output = out
|
||||
err := TaskWrite(testcase.context, tasks, names, nodes)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, tasks[i].ID, s)
|
||||
assert.Check(t, is.Equal(tasks[i].ID, s))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"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) {
|
||||
|
@ -126,9 +127,9 @@ tag3 bbbbbbbb
|
|||
testcase.context.Output = out
|
||||
err := TrustTagWrite(testcase.context, signedTags)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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("")
|
||||
emptyCase.context.Output = out
|
||||
err := TrustTagWrite(emptyCase.context, emptySignedTags)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, emptyCase.expected, out.String())
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(emptyCase.expected, out.String()))
|
||||
}
|
||||
|
||||
func TestSignerInfoContextEmptyWrite(t *testing.T) {
|
||||
|
@ -171,8 +172,8 @@ func TestSignerInfoContextEmptyWrite(t *testing.T) {
|
|||
out := bytes.NewBufferString("")
|
||||
emptyCase.context.Output = out
|
||||
err := SignerInfoWrite(emptyCase.context, emptySignerInfo)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, emptyCase.expected, out.String())
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(emptyCase.expected, out.String()))
|
||||
}
|
||||
|
||||
func TestSignerInfoContextWrite(t *testing.T) {
|
||||
|
@ -230,9 +231,9 @@ eve foobarbazquxquux, key31, key32
|
|||
testcase.context.Output = out
|
||||
err := SignerInfoWrite(testcase.context, signerInfo)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} else {
|
||||
assert.Equal(t, testcase.expected, out.String())
|
||||
assert.Check(t, is.Equal(testcase.expected, out.String()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestVolumeContext(t *testing.T) {
|
||||
|
@ -133,9 +133,9 @@ foobar_bar
|
|||
testcase.context.Output = out
|
||||
err := VolumeWrite(testcase.context, volumes)
|
||||
if err != nil {
|
||||
assert.EqualError(t, err, testcase.expected)
|
||||
assert.Check(t, is.Error(err, testcase.expected))
|
||||
} 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)
|
||||
var m map[string]interface{}
|
||||
err := json.Unmarshal([]byte(line), &m)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, expectedJSONs[i], m, msg)
|
||||
assert.NilError(t, err, 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)
|
||||
var s string
|
||||
err := json.Unmarshal([]byte(line), &s)
|
||||
require.NoError(t, err, msg)
|
||||
assert.Equal(t, volumes[i].Name, s, msg)
|
||||
assert.NilError(t, err, msg)
|
||||
assert.Check(t, is.Equal(volumes[i].Name, s), msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,10 +4,11 @@ import (
|
|||
"testing"
|
||||
|
||||
"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
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -21,7 +22,7 @@ func TestResolveError(t *testing.T) {
|
|||
idResolver := New(cli, false)
|
||||
_, 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) {
|
||||
|
@ -40,9 +41,9 @@ func TestResolveWithNoResolveOption(t *testing.T) {
|
|||
idResolver := New(cli, true)
|
||||
id, err := idResolver.Resolve(context.Background(), swarm.Node{}, "nodeID")
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "nodeID", id)
|
||||
assert.False(t, resolved)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal("nodeID", id))
|
||||
assert.Check(t, !resolved)
|
||||
}
|
||||
|
||||
func TestResolveWithCache(t *testing.T) {
|
||||
|
@ -59,11 +60,11 @@ func TestResolveWithCache(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
for i := 0; i < 2; i++ {
|
||||
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "node-foo", id)
|
||||
assert.Check(t, err)
|
||||
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) {
|
||||
|
@ -103,8 +104,8 @@ func TestResolveNode(t *testing.T) {
|
|||
idResolver := New(cli, false)
|
||||
id, err := idResolver.Resolve(ctx, swarm.Node{}, tc.nodeID)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedID, id)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(tc.expectedID, id))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -138,7 +139,7 @@ func TestResolveService(t *testing.T) {
|
|||
idResolver := New(cli, false)
|
||||
id, err := idResolver.Resolve(ctx, swarm.Service{}, tc.serviceID)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedID, id)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(tc.expectedID, id))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
const dockerfileContents = "FROM busybox"
|
||||
|
@ -38,7 +38,7 @@ func testValidateContextDirectory(t *testing.T, prepare func(t *testing.T) (stri
|
|||
defer cleanup()
|
||||
|
||||
err := ValidateContextDirectory(contextDir, excludes)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
||||
func TestGetContextFromLocalDirNoDockerfile(t *testing.T) {
|
||||
|
@ -79,10 +79,10 @@ func TestGetContextFromLocalDirWithNoDirectory(t *testing.T) {
|
|||
defer chdirCleanup()
|
||||
|
||||
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, contextDir, absContextDir)
|
||||
assert.Equal(t, DefaultDockerfileName, relDockerfile)
|
||||
assert.Check(t, is.Equal(contextDir, absContextDir))
|
||||
assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
|
||||
}
|
||||
|
||||
func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
|
||||
|
@ -92,10 +92,10 @@ func TestGetContextFromLocalDirWithDockerfile(t *testing.T) {
|
|||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
|
||||
|
||||
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, "")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, contextDir, absContextDir)
|
||||
assert.Equal(t, DefaultDockerfileName, relDockerfile)
|
||||
assert.Check(t, is.Equal(contextDir, absContextDir))
|
||||
assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
|
||||
}
|
||||
|
||||
func TestGetContextFromLocalDirLocalFile(t *testing.T) {
|
||||
|
@ -130,10 +130,10 @@ func TestGetContextFromLocalDirWithCustomDockerfile(t *testing.T) {
|
|||
createTestTempFile(t, contextDir, DefaultDockerfileName, dockerfileContents, 0777)
|
||||
|
||||
absContextDir, relDockerfile, err := GetContextFromLocalDir(contextDir, DefaultDockerfileName)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
assert.Equal(t, contextDir, absContextDir)
|
||||
assert.Equal(t, DefaultDockerfileName, relDockerfile)
|
||||
assert.Check(t, is.Equal(contextDir, absContextDir))
|
||||
assert.Check(t, is.Equal(DefaultDockerfileName, relDockerfile))
|
||||
}
|
||||
|
||||
func TestGetContextFromReaderString(t *testing.T) {
|
||||
|
@ -161,7 +161,7 @@ func TestGetContextFromReaderString(t *testing.T) {
|
|||
t.Fatalf("Tar stream too long: %s", err)
|
||||
}
|
||||
|
||||
require.NoError(t, tarArchive.Close())
|
||||
assert.NilError(t, tarArchive.Close())
|
||||
|
||||
if 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)
|
||||
|
||||
tarStream, err := archive.Tar(contextDir, archive.Uncompressed)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
tarArchive, relDockerfile, err := GetContextFromReader(tarStream, DefaultDockerfileName)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
tarReader := tar.NewReader(tarArchive)
|
||||
|
||||
header, err := tarReader.Next()
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
if header.Name != DefaultDockerfileName {
|
||||
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)
|
||||
}
|
||||
|
||||
require.NoError(t, tarArchive.Close())
|
||||
assert.NilError(t, tarArchive.Close())
|
||||
|
||||
if 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.
|
||||
func createTestTempDir(t *testing.T, dir, prefix string) (string, func()) {
|
||||
path, err := ioutil.TempDir(dir, prefix)
|
||||
require.NoError(t, err)
|
||||
return path, func() { require.NoError(t, os.RemoveAll(path)) }
|
||||
assert.NilError(t, err)
|
||||
return path, func() { assert.NilError(t, os.RemoveAll(path)) }
|
||||
}
|
||||
|
||||
// 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 {
|
||||
filePath := filepath.Join(dir, filename)
|
||||
err := ioutil.WriteFile(filePath, []byte(contents), perm)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
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.
|
||||
func chdir(t *testing.T, dir string) func() {
|
||||
workingDirectory, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, os.Chdir(dir))
|
||||
return func() { require.NoError(t, os.Chdir(workingDirectory)) }
|
||||
assert.NilError(t, err)
|
||||
assert.NilError(t, os.Chdir(dir))
|
||||
return func() { assert.NilError(t, os.Chdir(workingDirectory)) }
|
||||
}
|
||||
|
||||
func TestIsArchive(t *testing.T) {
|
||||
|
@ -295,6 +295,6 @@ func TestIsArchive(t *testing.T) {
|
|||
},
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,10 +15,10 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/skip"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -28,7 +28,7 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
|
|||
defer dest.Remove()
|
||||
|
||||
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)
|
||||
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
|
||||
|
@ -48,18 +48,18 @@ func TestRunBuildResetsUidAndGidInContext(t *testing.T) {
|
|||
options.context = dir.Path()
|
||||
|
||||
err := runBuild(cli, options)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
files, err := ioutil.ReadDir(dest.Path())
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
for _, fileInfo := range files {
|
||||
assert.Equal(t, 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).Uid))
|
||||
assert.Check(t, is.Equal(uint32(0), fileInfo.Sys().(*syscall.Stat_t).Gid))
|
||||
}
|
||||
}
|
||||
func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
||||
dest, err := ioutil.TempDir("", "test-build-compress-dest")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dest)
|
||||
|
||||
var dockerfileName string
|
||||
|
@ -67,11 +67,11 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
|||
buffer := new(bytes.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
|
||||
|
||||
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)
|
||||
return types.ImageBuildResponse{Body: ioutil.NopCloser(body)}, nil
|
||||
|
@ -85,7 +85,7 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
|||
cli.SetIn(command.NewInStream(ioutil.NopCloser(dockerfile)))
|
||||
|
||||
dir, err := ioutil.TempDir("", "test-build-compress")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
ioutil.WriteFile(filepath.Join(dir, "foo"), []byte("some content"), 0644)
|
||||
|
@ -96,16 +96,16 @@ func TestRunBuildDockerfileFromStdinWithCompress(t *testing.T) {
|
|||
options.context = dir
|
||||
|
||||
err = runBuild(cli, options)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
files, err := ioutil.ReadDir(dest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
actual := []string{}
|
||||
for _, fileInfo := range files {
|
||||
actual = append(actual, fileInfo.Name())
|
||||
}
|
||||
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) {
|
||||
|
@ -124,7 +124,7 @@ COPY data /data
|
|||
defer df.Remove()
|
||||
|
||||
dest, err := ioutil.TempDir("", t.Name())
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(dest)
|
||||
|
||||
var dockerfileName string
|
||||
|
@ -132,7 +132,7 @@ COPY data /data
|
|||
buffer := new(bytes.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
|
||||
|
||||
body := new(bytes.Buffer)
|
||||
|
@ -146,16 +146,16 @@ COPY data /data
|
|||
options.dockerfileName = df.Path()
|
||||
|
||||
err = runBuild(cli, options)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
files, err := ioutil.ReadDir(dest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
var actual []string
|
||||
for _, fileInfo := range files {
|
||||
actual = append(actual, fileInfo.Name())
|
||||
}
|
||||
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
|
||||
|
@ -166,8 +166,7 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
|||
cmd.SetArgs([]string{"github.com/docker/no-such-repository"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
err := cmd.Execute()
|
||||
assert.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "unable to prepare context: unable to 'git clone'")
|
||||
assert.ErrorContains(t, err, "unable to prepare context: unable to 'git clone'")
|
||||
}
|
||||
|
||||
// TestRunBuildFromLocalGitHubDirNonExistingRepo tests that a local directory
|
||||
|
@ -175,19 +174,19 @@ func TestRunBuildFromGitHubSpecialCase(t *testing.T) {
|
|||
// case.
|
||||
func TestRunBuildFromLocalGitHubDir(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "docker-build-from-local-dir-")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
buildDir := filepath.Join(tmpDir, "github.com", "docker", "no-such-repository")
|
||||
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)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
client := test.NewFakeCli(&fakeClient{})
|
||||
cmd := NewBuildCommand(client)
|
||||
cmd.SetArgs([]string{buildDir})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
err = cmd.Execute()
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types/image"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewHistoryCommandErrors(t *testing.T) {
|
||||
|
@ -47,7 +47,6 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
|||
testCases := []struct {
|
||||
name string
|
||||
args []string
|
||||
outputRegex string
|
||||
imageHistoryFunc func(img string) ([]image.HistoryResponseItem, error)
|
||||
}{
|
||||
{
|
||||
|
@ -64,16 +63,17 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
|||
name: "quiet",
|
||||
args: []string{"--quiet", "image:tag"},
|
||||
},
|
||||
// TODO: This test is failing since the output does not contain an RFC3339 date
|
||||
//{
|
||||
// name: "non-human",
|
||||
// args: []string{"--human=false", "image:tag"},
|
||||
// outputRegex: "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}", // RFC3339 date format match
|
||||
//},
|
||||
{
|
||||
name: "non-human-header",
|
||||
name: "non-human",
|
||||
args: []string{"--human=false", "image:tag"},
|
||||
outputRegex: "CREATED\\sAT",
|
||||
imageHistoryFunc: func(img string) ([]image.HistoryResponseItem, error) {
|
||||
return []image.HistoryResponseItem{{
|
||||
ID: "abcdef",
|
||||
Created: time.Date(2017, 1, 1, 12, 0, 3, 0, time.UTC).Unix(),
|
||||
CreatedBy: "rose",
|
||||
Comment: "new history item!",
|
||||
}}, nil
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "quiet-no-trunc",
|
||||
|
@ -92,12 +92,8 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
err := cmd.Execute()
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
actual := cli.OutBuffer().String()
|
||||
if tc.outputRegex == "" {
|
||||
golden.Assert(t, actual, fmt.Sprintf("history-command-success.%s.golden", tc.name))
|
||||
} else {
|
||||
assert.Regexp(t, tc.outputRegex, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewImportCommandErrors(t *testing.T) {
|
||||
|
@ -67,7 +68,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
|||
name: "double",
|
||||
args: []string{"-", "image:local"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -75,7 +76,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
|||
name: "message",
|
||||
args: []string{"--message", "test message", "-"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -83,7 +84,7 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
|||
name: "change",
|
||||
args: []string{"--change", "ENV DEBUG true", "-"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -92,6 +93,6 @@ func TestNewImportCommandSuccess(t *testing.T) {
|
|||
cmd := NewImportCommand(test.NewFakeCli(&fakeClient{imageImportFunc: tc.imageImportFunc}))
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewInspectCommandErrors(t *testing.T) {
|
||||
|
@ -46,7 +47,7 @@ func TestNewInspectCommandSuccess(t *testing.T) {
|
|||
imageCount: 1,
|
||||
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
|
||||
imageInspectInvocationCount++
|
||||
assert.Equal(t, "image", image)
|
||||
assert.Check(t, is.Equal("image", image))
|
||||
return types.ImageInspect{}, nil, nil
|
||||
},
|
||||
},
|
||||
|
@ -66,9 +67,9 @@ func TestNewInspectCommandSuccess(t *testing.T) {
|
|||
imageInspectFunc: func(image string) (types.ImageInspect, []byte, error) {
|
||||
imageInspectInvocationCount++
|
||||
if imageInspectInvocationCount == 1 {
|
||||
assert.Equal(t, "image1", image)
|
||||
assert.Check(t, is.Equal("image1", image))
|
||||
} else {
|
||||
assert.Equal(t, "image2", image)
|
||||
assert.Check(t, is.Equal("image2", image))
|
||||
}
|
||||
return types.ImageInspect{}, nil, nil
|
||||
},
|
||||
|
@ -81,8 +82,8 @@ func TestNewInspectCommandSuccess(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
assert.Equal(t, imageInspectInvocationCount, tc.imageCount)
|
||||
assert.Check(t, is.Equal(imageInspectInvocationCount, tc.imageCount))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewImagesCommandErrors(t *testing.T) {
|
||||
|
@ -65,7 +66,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
|
|||
name: "match-name",
|
||||
args: []string{"image"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -73,7 +74,7 @@ func TestNewImagesCommandSuccess(t *testing.T) {
|
|||
name: "filters",
|
||||
args: []string{"--filter", "name=value"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -85,14 +86,14 @@ func TestNewImagesCommandSuccess(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewListCommandAlias(t *testing.T) {
|
||||
cmd := newListCommand(test.NewFakeCli(&fakeClient{}))
|
||||
assert.True(t, cmd.HasAlias("images"))
|
||||
assert.True(t, cmd.HasAlias("list"))
|
||||
assert.False(t, cmd.HasAlias("other"))
|
||||
assert.Check(t, cmd.HasAlias("images"))
|
||||
assert.Check(t, cmd.HasAlias("list"))
|
||||
assert.Check(t, !cmd.HasAlias("other"))
|
||||
}
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewLoadCommandErrors(t *testing.T) {
|
||||
|
@ -96,7 +96,7 @@ func TestNewLoadCommandSuccess(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,9 +9,10 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewPruneCommandErrors(t *testing.T) {
|
||||
|
@ -55,7 +56,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
|
|||
name: "all",
|
||||
args: []string{"--all"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -63,7 +64,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
|
|||
name: "force-deleted",
|
||||
args: []string{"--force"},
|
||||
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{
|
||||
ImagesDeleted: []types.ImageDeleteResponseItem{{Deleted: "image1"}},
|
||||
SpaceReclaimed: 1,
|
||||
|
@ -74,7 +75,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
|
|||
name: "force-untagged",
|
||||
args: []string{"--force"},
|
||||
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{
|
||||
ImagesDeleted: []types.ImageDeleteResponseItem{{Untagged: "image1"}},
|
||||
SpaceReclaimed: 2,
|
||||
|
@ -88,7 +89,7 @@ func TestNewPruneCommandSuccess(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewPullCommandErrors(t *testing.T) {
|
||||
|
@ -65,7 +66,7 @@ func TestNewPullCommandSuccess(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
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
|
||||
},
|
||||
})
|
||||
|
@ -73,7 +74,7 @@ func TestNewPullCommandSuccess(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewPushCommandErrors(t *testing.T) {
|
||||
|
@ -72,6 +72,6 @@ func TestNewPushCommandSuccess(t *testing.T) {
|
|||
cmd := NewPushCommand(cli)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
type notFound struct {
|
||||
|
@ -27,9 +28,9 @@ func (n notFound) NotFound() bool {
|
|||
|
||||
func TestNewRemoveCommandAlias(t *testing.T) {
|
||||
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
|
||||
assert.True(t, cmd.HasAlias("rmi"))
|
||||
assert.True(t, cmd.HasAlias("remove"))
|
||||
assert.False(t, cmd.HasAlias("other"))
|
||||
assert.Check(t, cmd.HasAlias("rmi"))
|
||||
assert.Check(t, cmd.HasAlias("remove"))
|
||||
assert.Check(t, !cmd.HasAlias("other"))
|
||||
}
|
||||
|
||||
func TestNewRemoveCommandErrors(t *testing.T) {
|
||||
|
@ -48,7 +49,7 @@ func TestNewRemoveCommandErrors(t *testing.T) {
|
|||
args: []string{"-f", "image1"},
|
||||
expectedError: "error removing image",
|
||||
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")
|
||||
},
|
||||
},
|
||||
|
@ -57,8 +58,8 @@ func TestNewRemoveCommandErrors(t *testing.T) {
|
|||
args: []string{"arg1"},
|
||||
expectedError: "error removing image",
|
||||
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
|
||||
assert.False(t, options.Force)
|
||||
assert.True(t, options.PruneChildren)
|
||||
assert.Check(t, !options.Force)
|
||||
assert.Check(t, options.PruneChildren)
|
||||
return []types.ImageDeleteResponseItem{}, errors.Errorf("error removing image")
|
||||
},
|
||||
},
|
||||
|
@ -86,7 +87,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
|||
name: "Image Deleted",
|
||||
args: []string{"image1"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -94,8 +95,8 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
|||
name: "Image not found with force option",
|
||||
args: []string{"-f", "image1"},
|
||||
imageRemoveFunc: func(image string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error) {
|
||||
assert.Equal(t, "image1", image)
|
||||
assert.Equal(t, true, options.Force)
|
||||
assert.Check(t, is.Equal("image1", image))
|
||||
assert.Check(t, is.Equal(true, options.Force))
|
||||
return []types.ImageDeleteResponseItem{}, notFound{"image1"}
|
||||
},
|
||||
expectedStderr: "Error: No such image: image1\n",
|
||||
|
@ -105,7 +106,7 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
|||
name: "Image Untagged",
|
||||
args: []string{"image1"},
|
||||
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
|
||||
},
|
||||
},
|
||||
|
@ -126,8 +127,8 @@ func TestNewRemoveCommandSuccess(t *testing.T) {
|
|||
cmd := NewRemoveCommand(cli)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, tc.expectedStderr, cli.ErrBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
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))
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"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/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewSaveCommandErrors(t *testing.T) {
|
||||
|
@ -69,8 +69,8 @@ func TestNewSaveCommandSuccess(t *testing.T) {
|
|||
args: []string{"-o", "save_tmp_file", "arg1"},
|
||||
isTerminal: true,
|
||||
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
||||
require.Len(t, images, 1)
|
||||
assert.Equal(t, "arg1", images[0])
|
||||
assert.Assert(t, is.Len(images, 1))
|
||||
assert.Check(t, is.Equal("arg1", images[0]))
|
||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
||||
},
|
||||
deferredFunc: func() {
|
||||
|
@ -81,9 +81,9 @@ func TestNewSaveCommandSuccess(t *testing.T) {
|
|||
args: []string{"arg1", "arg2"},
|
||||
isTerminal: false,
|
||||
imageSaveFunc: func(images []string) (io.ReadCloser, error) {
|
||||
require.Len(t, images, 2)
|
||||
assert.Equal(t, "arg1", images[0])
|
||||
assert.Equal(t, "arg2", images[1])
|
||||
assert.Assert(t, is.Len(images, 2))
|
||||
assert.Check(t, is.Equal("arg1", images[0]))
|
||||
assert.Check(t, is.Equal("arg2", images[1]))
|
||||
return ioutil.NopCloser(strings.NewReader("")), nil
|
||||
},
|
||||
},
|
||||
|
@ -96,7 +96,7 @@ func TestNewSaveCommandSuccess(t *testing.T) {
|
|||
}))
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(tc.args)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
if tc.deferredFunc != nil {
|
||||
tc.deferredFunc()
|
||||
}
|
||||
|
|
|
@ -6,7 +6,8 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"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) {
|
||||
|
@ -28,14 +29,14 @@ func TestCliNewTagCommand(t *testing.T) {
|
|||
cmd := NewTagCommand(
|
||||
test.NewFakeCli(&fakeClient{
|
||||
imageTagFunc: func(image string, ref string) error {
|
||||
assert.Equal(t, "image1", image)
|
||||
assert.Equal(t, "image2", ref)
|
||||
assert.Check(t, is.Equal("image1", image))
|
||||
assert.Check(t, is.Equal("image2", ref))
|
||||
return nil
|
||||
},
|
||||
}))
|
||||
cmd.SetArgs([]string{"image1", "image2"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
value, _ := cmd.Flags().GetBool("interspersed")
|
||||
assert.False(t, value)
|
||||
assert.Check(t, !value)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
IMAGE CREATED AT CREATED BY SIZE COMMENT
|
||||
abcdef 2017-01-01T12:00:03Z rose 0 new history item!
|
|
@ -8,8 +8,8 @@ import (
|
|||
"github.com/docker/cli/cli/trust"
|
||||
registrytypes "github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/theupdateframework/notary/client"
|
||||
"github.com/theupdateframework/notary/passphrase"
|
||||
"github.com/theupdateframework/notary/trustpinning"
|
||||
|
@ -64,12 +64,12 @@ func TestNonOfficialTrustServer(t *testing.T) {
|
|||
|
||||
func TestAddTargetToAllSignableRolesError(t *testing.T) {
|
||||
tmpDir, err := ioutil.TempDir("", "notary-test-")
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
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{}
|
||||
err = AddTargetToAllSignableRoles(notaryRepo, &target)
|
||||
assert.EqualError(t, err, "client is offline")
|
||||
assert.Check(t, is.Error(err, "client is offline"))
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/docker/cli/templates"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
type testElement struct {
|
||||
|
@ -243,17 +243,17 @@ func TestTemplateInspectorRawFallbackNumber(t *testing.T) {
|
|||
}
|
||||
b := new(bytes.Buffer)
|
||||
tmpl, err := templates.Parse("{{.Size}} {{.Id}}")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
i := NewTemplateInspector(b, tmpl)
|
||||
for _, tc := range testcases {
|
||||
err = i.Inspect(typedElem, tc.raw)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"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/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestManifestAnnotateError(t *testing.T) {
|
||||
|
@ -48,7 +48,7 @@ func TestManifestAnnotate(t *testing.T) {
|
|||
namedRef := ref(t, "alpine:3.0")
|
||||
imageManifest := fullImageManifest(t, namedRef)
|
||||
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cmd := newAnnotateCommand(cli)
|
||||
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)
|
||||
|
||||
cmd.Flags().Set("arch", "arm")
|
||||
require.NoError(t, cmd.Execute())
|
||||
assert.NilError(t, cmd.Execute())
|
||||
|
||||
cmd = newInspectCommand(cli)
|
||||
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"})
|
||||
require.NoError(t, cmd.Execute())
|
||||
assert.NilError(t, cmd.Execute())
|
||||
actual := cli.OutBuffer()
|
||||
expected := golden.Get(t, "inspect-annotate.golden")
|
||||
assert.Equal(t, string(expected), actual.String())
|
||||
assert.Check(t, is.Equal(string(expected), actual.String()))
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -50,28 +50,28 @@ func TestManifestCreateAmend(t *testing.T) {
|
|||
namedRef := ref(t, "alpine:3.0")
|
||||
imageManifest := fullImageManifest(t, namedRef)
|
||||
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
namedRef = ref(t, "alpine:3.1")
|
||||
imageManifest = fullImageManifest(t, namedRef)
|
||||
err = store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cmd := newCreateListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.1"})
|
||||
cmd.Flags().Set("amend", "true")
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
err = cmd.Execute()
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
// make a new cli to clear the buffers
|
||||
cli = test.NewFakeCli(nil)
|
||||
cli.SetManifestStore(store)
|
||||
inspectCmd := newInspectCommand(cli)
|
||||
inspectCmd.SetArgs([]string{"example.com/list:v1"})
|
||||
require.NoError(t, inspectCmd.Execute())
|
||||
assert.NilError(t, inspectCmd.Execute())
|
||||
actual := cli.OutBuffer()
|
||||
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
|
||||
|
@ -84,13 +84,13 @@ func TestManifestCreateRefuseAmend(t *testing.T) {
|
|||
namedRef := ref(t, "alpine:3.0")
|
||||
imageManifest := fullImageManifest(t, namedRef)
|
||||
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cmd := newCreateListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
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
|
||||
|
@ -113,5 +113,5 @@ func TestManifestCreateNoManifest(t *testing.T) {
|
|||
cmd.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
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"))
|
||||
}
|
||||
|
|
|
@ -12,24 +12,24 @@ import (
|
|||
"github.com/docker/distribution"
|
||||
"github.com/docker/distribution/manifest/schema2"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func newTempManifestStore(t *testing.T) (store.Store, func()) {
|
||||
tmpdir, err := ioutil.TempDir("", "test-manifest-storage")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
return store.NewStore(tmpdir), func() { os.RemoveAll(tmpdir) }
|
||||
}
|
||||
|
||||
func ref(t *testing.T, name string) reference.Named {
|
||||
named, err := reference.ParseNamed("example.com/" + name)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
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
|
||||
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.SetArgs([]string{"example.com/list:v1", "example.com/alpine:3.0"})
|
||||
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) {
|
||||
|
@ -87,7 +87,7 @@ func TestInspectCommandNotFound(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs([]string{"example.com/alpine:3.0"})
|
||||
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) {
|
||||
|
@ -99,14 +99,14 @@ func TestInspectCommandLocalManifest(t *testing.T) {
|
|||
namedRef := ref(t, "alpine:3.0")
|
||||
imageManifest := fullImageManifest(t, namedRef)
|
||||
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cmd := newInspectCommand(cli)
|
||||
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()
|
||||
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) {
|
||||
|
@ -124,8 +124,8 @@ func TestInspectcommandRemoteManifest(t *testing.T) {
|
|||
cmd := newInspectCommand(cli)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs([]string{"example.com/alpine:3.0"})
|
||||
require.NoError(t, cmd.Execute())
|
||||
assert.NilError(t, cmd.Execute())
|
||||
actual := cli.OutBuffer()
|
||||
expected := golden.Get(t, "inspect-manifest.golden")
|
||||
assert.Equal(t, string(expected), actual.String())
|
||||
assert.Check(t, is.Equal(string(expected), actual.String()))
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func newFakeRegistryClient(t *testing.T) *fakeRegistryClient {
|
||||
require.NoError(t, nil)
|
||||
assert.NilError(t, nil)
|
||||
|
||||
return &fakeRegistryClient{
|
||||
getManifestFunc: func(_ context.Context, _ reference.Named) (manifesttypes.ImageManifest, error) {
|
||||
|
@ -64,10 +64,10 @@ func TestManifestPush(t *testing.T) {
|
|||
namedRef := ref(t, "alpine:3.0")
|
||||
imageManifest := fullImageManifest(t, namedRef)
|
||||
err := store.Save(ref(t, "list:v1"), namedRef, imageManifest)
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
|
||||
cmd := newPushListCommand(cli)
|
||||
cmd.SetArgs([]string{"example.com/list:v1"})
|
||||
err = cmd.Execute()
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -54,7 +55,7 @@ func TestNetworkConnectWithFlags(t *testing.T) {
|
|||
}
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
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
|
||||
},
|
||||
})
|
||||
|
@ -66,5 +67,5 @@ func TestNetworkConnectWithFlags(t *testing.T) {
|
|||
cmd.Flags().Set("ip-range", "192.168.4.0/24")
|
||||
cmd.Flags().Set("gateway", "192.168.4.1/24")
|
||||
cmd.Flags().Set("subnet", "192.168.4.0/24")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
|
|
@ -9,9 +9,9 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -136,7 +136,7 @@ func TestNetworkCreateErrors(t *testing.T) {
|
|||
)
|
||||
cmd.SetArgs(tc.args)
|
||||
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)
|
||||
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
|
@ -155,8 +155,8 @@ func TestNetworkCreateWithFlags(t *testing.T) {
|
|||
}
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
networkCreateFunc: func(ctx context.Context, name string, createBody types.NetworkCreate) (types.NetworkCreateResponse, error) {
|
||||
assert.Equal(t, expectedDriver, createBody.Driver, "not expected driver error")
|
||||
assert.Equal(t, expectedOpts, createBody.IPAM.Config, "not expected driver error")
|
||||
assert.Check(t, is.Equal(expectedDriver, createBody.Driver), "not expected driver error")
|
||||
assert.Check(t, is.DeepEqual(expectedOpts, createBody.IPAM.Config), "not expected driver error")
|
||||
return types.NetworkCreateResponse{
|
||||
ID: name,
|
||||
}, nil
|
||||
|
@ -170,6 +170,6 @@ func TestNetworkCreateWithFlags(t *testing.T) {
|
|||
cmd.Flags().Set("ip-range", "192.168.4.0/24")
|
||||
cmd.Flags().Set("gateway", "192.168.4.1/24")
|
||||
cmd.Flags().Set("subnet", "192.168.4.0/24")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "banana", strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("banana", strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
package network
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"io/ioutil"
|
||||
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/cli/internal/test"
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -38,23 +37,18 @@ func TestNetworkListErrors(t *testing.T) {
|
|||
}),
|
||||
)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
testutil.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
|
||||
assert.ErrorContains(t, cmd.Execute(), tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetworkListWithFlags(t *testing.T) {
|
||||
|
||||
filterArgs := filters.NewArgs()
|
||||
filterArgs.Add("image.name", "ubuntu")
|
||||
|
||||
expectedOpts := types.NetworkListOptions{
|
||||
Filters: filterArgs,
|
||||
Filters: filters.NewArgs(filters.Arg("image.name", "ubuntu")),
|
||||
}
|
||||
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
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, cmp.AllowUnexported(filters.Args{})))
|
||||
return []types.NetworkResource{*NetworkResource(NetworkResourceID("123454321"),
|
||||
NetworkResourceName("network_1"),
|
||||
NetworkResourceDriver("09.7.01"),
|
||||
|
@ -64,6 +58,6 @@ func TestNetworkListWithFlags(t *testing.T) {
|
|||
cmd := newListCommand(cli)
|
||||
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeDemoteErrors(t *testing.T) {
|
||||
|
@ -64,7 +64,7 @@ func TestNodeDemoteNoChange(t *testing.T) {
|
|||
},
|
||||
}))
|
||||
cmd.SetArgs([]string{"nodeID"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
||||
func TestNodeDemoteMultipleNode(t *testing.T) {
|
||||
|
@ -81,5 +81,5 @@ func TestNodeDemoteMultipleNode(t *testing.T) {
|
|||
},
|
||||
}))
|
||||
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeInspectErrors(t *testing.T) {
|
||||
|
@ -113,7 +113,7 @@ func TestNodeInspectPretty(t *testing.T) {
|
|||
cmd := newInspectCommand(cli)
|
||||
cmd.SetArgs([]string{"nodeID"})
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,11 +8,12 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/pkg/errors"
|
||||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeListErrorOnAPIFailure(t *testing.T) {
|
||||
|
@ -48,7 +49,7 @@ func TestNodeListErrorOnAPIFailure(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "node-list-sort.golden")
|
||||
}
|
||||
|
||||
|
@ -85,8 +86,8 @@ func TestNodeListQuietShouldOnlyPrintIDs(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
cmd.Flags().Set("quiet", "true")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, cli.OutBuffer().String(), "nodeID1\n")
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal(cli.OutBuffer().String(), "nodeID1\n"))
|
||||
}
|
||||
|
||||
func TestNodeListDefaultFormatFromConfig(t *testing.T) {
|
||||
|
@ -110,7 +111,7 @@ func TestNodeListDefaultFormatFromConfig(t *testing.T) {
|
|||
NodesFormat: "{{.ID}}: {{.Hostname}} {{.Status}}/{{.ManagerStatus}}",
|
||||
})
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -135,6 +136,6 @@ func TestNodeListFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodePromoteErrors(t *testing.T) {
|
||||
|
@ -64,7 +64,7 @@ func TestNodePromoteNoChange(t *testing.T) {
|
|||
},
|
||||
}))
|
||||
cmd.SetArgs([]string{"nodeID"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
||||
func TestNodePromoteMultipleNode(t *testing.T) {
|
||||
|
@ -81,5 +81,5 @@ func TestNodePromoteMultipleNode(t *testing.T) {
|
|||
},
|
||||
}))
|
||||
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
|
|
@ -12,8 +12,9 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
// Import builders to get the builder function as package function
|
||||
. "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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodePsErrors(t *testing.T) {
|
||||
|
@ -60,7 +61,7 @@ func TestNodePsErrors(t *testing.T) {
|
|||
cmd.Flags().Set(key, value)
|
||||
}
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeRemoveErrors(t *testing.T) {
|
||||
|
@ -41,5 +41,5 @@ func TestNodeRemoveErrors(t *testing.T) {
|
|||
func TestNodeRemoveMultiple(t *testing.T) {
|
||||
cmd := newRemoveCommand(test.NewFakeCli(&fakeClient{}))
|
||||
cmd.SetArgs([]string{"nodeID1", "nodeID2"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNodeUpdateErrors(t *testing.T) {
|
||||
|
@ -165,6 +165,6 @@ func TestNodeUpdate(t *testing.T) {
|
|||
for key, value := range tc.flags {
|
||||
cmd.Flags().Set(key, value)
|
||||
}
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,9 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCreateErrors(t *testing.T) {
|
||||
|
@ -109,6 +110,6 @@ func TestCreatePlugin(t *testing.T) {
|
|||
|
||||
cmd := newCreateCommand(cli)
|
||||
cmd.SetArgs([]string{"plugin-foo", tmpDir.Path()})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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) {
|
||||
|
@ -53,6 +54,6 @@ func TestPluginDisable(t *testing.T) {
|
|||
})
|
||||
cmd := newDisableCommand(cli)
|
||||
cmd.SetArgs([]string{"plugin-foo"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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) {
|
||||
|
@ -65,6 +66,6 @@ func TestPluginEnable(t *testing.T) {
|
|||
|
||||
cmd := newEnableCommand(cli)
|
||||
cmd.SetArgs([]string{"plugin-foo"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"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) {
|
||||
|
@ -50,8 +51,8 @@ func TestRemove(t *testing.T) {
|
|||
})
|
||||
cmd := newRemoveCommand(cli)
|
||||
cmd.SetArgs([]string{"plugin-foo"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
||||
}
|
||||
|
||||
func TestRemoveWithForceOption(t *testing.T) {
|
||||
|
@ -65,7 +66,7 @@ func TestRemoveWithForceOption(t *testing.T) {
|
|||
cmd := newRemoveCommand(cli)
|
||||
cmd.SetArgs([]string{"plugin-foo"})
|
||||
cmd.Flags().Set("force", "true")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.True(t, force)
|
||||
assert.Equal(t, "plugin-foo\n", cli.OutBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, force)
|
||||
assert.Check(t, is.Equal("plugin-foo\n", cli.OutBuffer().String()))
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
registrytypes "github.com/docker/docker/api/types/registry"
|
||||
"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"
|
||||
|
@ -63,9 +64,9 @@ func TestLoginWithCredStoreCreds(t *testing.T) {
|
|||
cli.SetErr(errBuf)
|
||||
loginWithCredStoreCreds(ctx, cli, &tc.inputAuthConfig)
|
||||
outputString := cli.OutBuffer().String()
|
||||
assert.Equal(t, tc.expectedMsg, outputString)
|
||||
assert.Check(t, is.Equal(tc.expectedMsg, outputString))
|
||||
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)
|
||||
if tc.expectedErr != "" {
|
||||
assert.Equal(t, tc.expectedErr, loginErr.Error())
|
||||
assert.Check(t, is.Equal(tc.expectedErr, loginErr.Error()))
|
||||
} else {
|
||||
assert.Nil(t, loginErr)
|
||||
assert.Check(t, loginErr)
|
||||
savedCred, credStoreErr := cli.ConfigFile().GetCredentialsStore(tc.inputStoredCred.ServerAddress).Get(tc.inputStoredCred.ServerAddress)
|
||||
assert.Nil(t, credStoreErr)
|
||||
assert.Equal(t, tc.expectedSavedCred, savedCred)
|
||||
assert.Check(t, credStoreErr)
|
||||
assert.Check(t, is.DeepEqual(tc.expectedSavedCred, savedCred))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
|
||||
// Prevents a circular import with "github.com/docker/cli/internal/test"
|
||||
|
@ -80,12 +81,12 @@ func TestElectAuthServer(t *testing.T) {
|
|||
for _, tc := range testCases {
|
||||
cli := test.NewFakeCli(&fakeClient{infoFunc: tc.infoFunc})
|
||||
server := ElectAuthServer(context.Background(), cli)
|
||||
assert.Equal(t, tc.expectedAuthServer, server)
|
||||
assert.Check(t, is.Equal(tc.expectedAuthServer, server))
|
||||
actual := cli.ErrBuffer().String()
|
||||
if tc.expectedWarning == "" {
|
||||
assert.Empty(t, actual)
|
||||
assert.Check(t, is.Len(actual, 0))
|
||||
} 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
|
||||
authconfig, err := GetDefaultAuthConfig(cli, tc.checkCredStore, serverAddress, serverAddress == "https://index.docker.io/v1/")
|
||||
if tc.expectedErr != "" {
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, tc.expectedErr, err.Error())
|
||||
assert.Check(t, err != nil)
|
||||
assert.Check(t, is.Equal(tc.expectedErr, err.Error()))
|
||||
} else {
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, tc.expectedAuthConfig, *authconfig)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.DeepEqual(tc.expectedAuthConfig, *authconfig))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,8 +11,9 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
const secretDataFile = "secret-create-with-name.golden"
|
||||
|
@ -52,7 +53,7 @@ func TestSecretCreateErrors(t *testing.T) {
|
|||
func TestSecretCreateWithName(t *testing.T) {
|
||||
name := "foo"
|
||||
data, err := ioutil.ReadFile(filepath.Join("testdata", secretDataFile))
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
|
||||
expected := swarm.SecretSpec{
|
||||
Annotations: swarm.Annotations{
|
||||
|
@ -75,8 +76,8 @@ func TestSecretCreateWithName(t *testing.T) {
|
|||
|
||||
cmd := newSecretCreateCommand(cli)
|
||||
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
||||
func TestSecretCreateWithDriver(t *testing.T) {
|
||||
|
@ -104,8 +105,8 @@ func TestSecretCreateWithDriver(t *testing.T) {
|
|||
cmd := newSecretCreateCommand(cli)
|
||||
cmd.SetArgs([]string{name})
|
||||
cmd.Flags().Set("driver", expectedDriver.Name)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
||||
func TestSecretCreateWithTemplatingDriver(t *testing.T) {
|
||||
|
@ -133,8 +134,8 @@ func TestSecretCreateWithTemplatingDriver(t *testing.T) {
|
|||
cmd := newSecretCreateCommand(cli)
|
||||
cmd.SetArgs([]string{name})
|
||||
cmd.Flags().Set("template-driver", expectedDriver.Name)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
||||
func TestSecretCreateWithLabels(t *testing.T) {
|
||||
|
@ -164,6 +165,6 @@ func TestSecretCreateWithLabels(t *testing.T) {
|
|||
cmd.SetArgs([]string{name, filepath.Join("testdata", secretDataFile)})
|
||||
cmd.Flags().Set("label", "lbl1=Label-foo")
|
||||
cmd.Flags().Set("label", "lbl2=Label-bar")
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "ID-"+name, strings.TrimSpace(cli.OutBuffer().String()))
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("ID-"+name, strings.TrimSpace(cli.OutBuffer().String())))
|
||||
}
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSecretInspectErrors(t *testing.T) {
|
||||
|
@ -98,7 +98,7 @@ func TestSecretInspectWithoutFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newSecretInspectCommand(cli)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -135,7 +135,7 @@ func TestSecretInspectWithFormat(t *testing.T) {
|
|||
cmd := newSecretInspectCommand(cli)
|
||||
cmd.SetArgs(tc.args)
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ func TestSecretInspectPretty(t *testing.T) {
|
|||
cmd := newSecretInspectCommand(cli)
|
||||
cmd.SetArgs([]string{"secretID"})
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,8 +13,9 @@ import (
|
|||
// Import builders to get the builder function as package function
|
||||
. "github.com/docker/cli/internal/test/builders"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSecretListErrors(t *testing.T) {
|
||||
|
@ -74,7 +75,7 @@ func TestSecretList(t *testing.T) {
|
|||
},
|
||||
})
|
||||
cmd := newSecretListCommand(cli)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "secret-list-sort.golden")
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,7 @@ func TestSecretListWithQuietOption(t *testing.T) {
|
|||
})
|
||||
cmd := newSecretListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -110,7 +111,7 @@ func TestSecretListWithConfigFormat(t *testing.T) {
|
|||
SecretFormat: "{{ .Name }} {{ .Labels }}",
|
||||
})
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -127,15 +128,15 @@ func TestSecretListWithFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newSecretListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
func TestSecretListWithFilter(t *testing.T) {
|
||||
cli := test.NewFakeCli(&fakeClient{
|
||||
secretListFunc: func(options types.SecretListOptions) ([]swarm.Secret, error) {
|
||||
assert.Equal(t, "foo", options.Filters.Get("name")[0], "foo")
|
||||
assert.Equal(t, "lbl1=Label-bar", options.Filters.Get("label")[0])
|
||||
assert.Check(t, is.Equal("foo", options.Filters.Get("name")[0]), "foo")
|
||||
assert.Check(t, is.Equal("lbl1=Label-bar", options.Filters.Get("label")[0]))
|
||||
return []swarm.Secret{
|
||||
*Secret(SecretID("ID-foo"),
|
||||
SecretName("foo"),
|
||||
|
@ -155,6 +156,6 @@ func TestSecretListWithFilter(t *testing.T) {
|
|||
cmd := newSecretListCommand(cli)
|
||||
cmd.Flags().Set("filter", "name=foo")
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -7,8 +7,9 @@ import (
|
|||
|
||||
"github.com/docker/cli/internal/test"
|
||||
"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/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSecretRemoveErrors(t *testing.T) {
|
||||
|
@ -52,9 +53,9 @@ func TestSecretRemoveWithName(t *testing.T) {
|
|||
})
|
||||
cmd := newSecretRemoveCommand(cli)
|
||||
cmd.SetArgs(names)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n"))
|
||||
assert.Equal(t, names, removedSecrets)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.DeepEqual(names, strings.Split(strings.TrimSpace(cli.OutBuffer().String()), "\n")))
|
||||
assert.Check(t, is.DeepEqual(names, removedSecrets))
|
||||
}
|
||||
|
||||
func TestSecretRemoveContinueAfterError(t *testing.T) {
|
||||
|
@ -74,6 +75,6 @@ func TestSecretRemoveContinueAfterError(t *testing.T) {
|
|||
cmd := newSecretRemoveCommand(cli)
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs(names)
|
||||
assert.EqualError(t, cmd.Execute(), "error removing secret: foo")
|
||||
assert.Equal(t, names, removedSecrets)
|
||||
assert.Check(t, is.Error(cmd.Execute(), "error removing secret: foo"))
|
||||
assert.Check(t, is.DeepEqual(names, removedSecrets))
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ package service
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestValidateSingleGenericResource(t *testing.T) {
|
||||
|
@ -12,11 +13,11 @@ func TestValidateSingleGenericResource(t *testing.T) {
|
|||
|
||||
for _, v := range incorrect {
|
||||
_, err := ValidateSingleGenericResource(v)
|
||||
assert.Error(t, err)
|
||||
assert.Check(t, is.ErrorContains(err, ""))
|
||||
}
|
||||
|
||||
for _, v := range correct {
|
||||
_, err := ValidateSingleGenericResource(v)
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
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 {
|
||||
t.Fatal(err)
|
||||
}
|
||||
assert.Equal(t, m1, m2)
|
||||
assert.Check(t, is.DeepEqual(m1, m2))
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -23,6 +23,6 @@ func TestServiceListOrder(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -10,45 +10,45 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestMemBytesString(t *testing.T) {
|
||||
var mem opts.MemBytes = 1048576
|
||||
assert.Equal(t, "1MiB", mem.String())
|
||||
assert.Check(t, is.Equal("1MiB", mem.String()))
|
||||
}
|
||||
|
||||
func TestMemBytesSetAndValue(t *testing.T) {
|
||||
var mem opts.MemBytes
|
||||
assert.NoError(t, mem.Set("5kb"))
|
||||
assert.Equal(t, int64(5120), mem.Value())
|
||||
assert.Check(t, mem.Set("5kb"))
|
||||
assert.Check(t, is.Equal(int64(5120), mem.Value()))
|
||||
}
|
||||
|
||||
func TestNanoCPUsString(t *testing.T) {
|
||||
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) {
|
||||
var cpus opts.NanoCPUs
|
||||
assert.NoError(t, cpus.Set("0.35"))
|
||||
assert.Equal(t, int64(350000000), cpus.Value())
|
||||
assert.Check(t, cpus.Set("0.35"))
|
||||
assert.Check(t, is.Equal(int64(350000000), cpus.Value()))
|
||||
}
|
||||
|
||||
func TestUint64OptString(t *testing.T) {
|
||||
value := uint64(2345678)
|
||||
opt := Uint64Opt{value: &value}
|
||||
assert.Equal(t, "2345678", opt.String())
|
||||
assert.Check(t, is.Equal("2345678", opt.String()))
|
||||
|
||||
opt = Uint64Opt{}
|
||||
assert.Equal(t, "", opt.String())
|
||||
assert.Check(t, is.Equal("", opt.String()))
|
||||
}
|
||||
|
||||
func TestUint64OptSetAndValue(t *testing.T) {
|
||||
var opt Uint64Opt
|
||||
assert.NoError(t, opt.Set("14445"))
|
||||
assert.Equal(t, uint64(14445), *opt.Value())
|
||||
assert.Check(t, opt.Set("14445"))
|
||||
assert.Check(t, is.Equal(uint64(14445), *opt.Value()))
|
||||
}
|
||||
|
||||
func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
|
||||
|
@ -61,14 +61,14 @@ func TestHealthCheckOptionsToHealthConfig(t *testing.T) {
|
|||
retries: 10,
|
||||
}
|
||||
config, err := opt.toHealthConfig()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, &container.HealthConfig{
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.DeepEqual(&container.HealthConfig{
|
||||
Test: []string{"CMD-SHELL", "curl"},
|
||||
Interval: time.Second,
|
||||
Timeout: time.Second,
|
||||
StartPeriod: time.Second,
|
||||
Retries: 10,
|
||||
}, config)
|
||||
}, config))
|
||||
}
|
||||
|
||||
func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
|
||||
|
@ -76,10 +76,10 @@ func TestHealthCheckOptionsToHealthConfigNoHealthcheck(t *testing.T) {
|
|||
noHealthcheck: true,
|
||||
}
|
||||
config, err := opt.toHealthConfig()
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, &container.HealthConfig{
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.DeepEqual(&container.HealthConfig{
|
||||
Test: []string{"NONE"},
|
||||
}, config)
|
||||
}, config))
|
||||
}
|
||||
|
||||
func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
|
||||
|
@ -88,7 +88,7 @@ func TestHealthCheckOptionsToHealthConfigConflict(t *testing.T) {
|
|||
noHealthcheck: true,
|
||||
}
|
||||
_, 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) {
|
||||
|
@ -109,7 +109,7 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
|
|||
|
||||
for _, opt := range incorrectOptions {
|
||||
_, err := opt.ToResourceRequirements()
|
||||
assert.Error(t, err)
|
||||
assert.Check(t, is.ErrorContains(err, ""))
|
||||
}
|
||||
|
||||
correctOptions := []resourceOptions{
|
||||
|
@ -123,8 +123,8 @@ func TestResourceOptionsToResourceRequirements(t *testing.T) {
|
|||
|
||||
for _, opt := range correctOptions {
|
||||
r, err := opt.ToResourceRequirements()
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, r.Reservations.GenericResources, len(opt.resGenericResources))
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Len(r.Reservations.GenericResources, len(opt.resGenericResources)))
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -159,6 +159,6 @@ func TestToServiceNetwork(t *testing.T) {
|
|||
ctx := context.Background()
|
||||
flags := newCreateCommand(nil).Flags()
|
||||
service, err := o.ToService(ctx, client, flags)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id111"}, {Target: "id555"}, {Target: "id999"}}, service.TaskTemplate.Networks)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id111"}, {Target: "id555"}, {Target: "id999"}}, service.TaskTemplate.Networks))
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import (
|
|||
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"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 {
|
||||
|
@ -36,9 +37,9 @@ func (u updaterTester) testUpdater(tasks []swarm.Task, expectedConvergence bool,
|
|||
u.p.clear()
|
||||
|
||||
converged, err := u.updater.update(u.service, tasks, u.activeNodes, u.rollback)
|
||||
assert.NoError(u.t, err)
|
||||
assert.Equal(u.t, expectedConvergence, converged)
|
||||
assert.Equal(u.t, expectedProgress, u.p.p)
|
||||
assert.Check(u.t, err)
|
||||
assert.Check(u.t, is.Equal(expectedConvergence, converged))
|
||||
assert.Check(u.t, is.DeepEqual(expectedProgress, u.p.p))
|
||||
}
|
||||
|
||||
func TestReplicatedProgressUpdaterOneReplica(t *testing.T) {
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -26,22 +27,23 @@ func TestCreateFilter(t *testing.T) {
|
|||
}
|
||||
|
||||
filter := opts.NewFilterOpt()
|
||||
require.NoError(t, filter.Set("node=somenode"))
|
||||
assert.NilError(t, filter.Set("node=somenode"))
|
||||
options := psOptions{
|
||||
services: []string{"idmatch", "idprefix", "namematch", "notfound"},
|
||||
filter: filter,
|
||||
}
|
||||
|
||||
actual, notfound, err := createFilter(context.Background(), client, options)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, notfound, []string{"no such service: notfound"})
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual(notfound, []string{"no such service: notfound"}))
|
||||
|
||||
expected := filters.NewArgs()
|
||||
expected.Add("service", "idmatch")
|
||||
expected.Add("service", "idprefixmatch")
|
||||
expected.Add("service", "cccccccc")
|
||||
expected.Add("node", "somenode")
|
||||
assert.Equal(t, expected, actual)
|
||||
expected := filters.NewArgs(
|
||||
filters.Arg("service", "idmatch"),
|
||||
filters.Arg("service", "idprefixmatch"),
|
||||
filters.Arg("service", "cccccccc"),
|
||||
filters.Arg("node", "somenode"),
|
||||
)
|
||||
assert.DeepEqual(t, expected, actual, cmpFilters)
|
||||
}
|
||||
|
||||
func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) {
|
||||
|
@ -58,7 +60,7 @@ func TestCreateFilterWithAmbiguousIDPrefixError(t *testing.T) {
|
|||
filter: opts.NewFilterOpt(),
|
||||
}
|
||||
_, _, 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) {
|
||||
|
@ -68,7 +70,7 @@ func TestCreateFilterNoneFound(t *testing.T) {
|
|||
filter: opts.NewFilterOpt(),
|
||||
}
|
||||
_, _, 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) {
|
||||
|
@ -87,7 +89,7 @@ func TestRunPSWarnsOnNotFound(t *testing.T) {
|
|||
format: "{{.ID}}",
|
||||
}
|
||||
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) {
|
||||
|
@ -102,16 +104,17 @@ func TestRunPSQuiet(t *testing.T) {
|
|||
|
||||
cli := test.NewFakeCli(client)
|
||||
err := runPS(cli, psOptions{services: []string{"foo"}, quiet: true, filter: opts.NewFilterOpt()})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "sxabyp0obqokwekpun4rjo0b3\n", cli.OutBuffer().String())
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal("sxabyp0obqokwekpun4rjo0b3\n", cli.OutBuffer().String()))
|
||||
}
|
||||
|
||||
func TestUpdateNodeFilter(t *testing.T) {
|
||||
selfNodeID := "foofoo"
|
||||
filter := filters.NewArgs()
|
||||
filter.Add("node", "one")
|
||||
filter.Add("node", "two")
|
||||
filter.Add("node", "self")
|
||||
filter := filters.NewArgs(
|
||||
filters.Arg("node", "one"),
|
||||
filters.Arg("node", "two"),
|
||||
filters.Arg("node", "self"),
|
||||
)
|
||||
|
||||
client := &fakeClient{
|
||||
infoFunc: func(_ context.Context) (types.Info, error) {
|
||||
|
@ -121,9 +124,12 @@ func TestUpdateNodeFilter(t *testing.T) {
|
|||
|
||||
updateNodeFilter(context.Background(), client, filter)
|
||||
|
||||
expected := filters.NewArgs()
|
||||
expected.Add("node", "one")
|
||||
expected.Add("node", "two")
|
||||
expected.Add("node", selfNodeID)
|
||||
assert.Equal(t, expected, filter)
|
||||
expected := filters.NewArgs(
|
||||
filters.Arg("node", "one"),
|
||||
filters.Arg("node", "two"),
|
||||
filters.Arg("node", selfNodeID),
|
||||
)
|
||||
assert.DeepEqual(t, expected, filter, cmpFilters)
|
||||
}
|
||||
|
||||
var cmpFilters = cmp.AllowUnexported(filters.Args{})
|
||||
|
|
|
@ -10,7 +10,8 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -50,8 +51,8 @@ func TestRollback(t *testing.T) {
|
|||
cmd.SetArgs(tc.args)
|
||||
cmd.Flags().Set("quiet", "true")
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, strings.TrimSpace(cli.ErrBuffer().String()), tc.expectedDockerCliErr)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal(strings.TrimSpace(cli.ErrBuffer().String()), tc.expectedDockerCliErr))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/docker/docker/api/types/container"
|
||||
mounttypes "github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -30,7 +30,7 @@ func TestUpdateServiceArgs(t *testing.T) {
|
|||
cspec.Args = []string{"old", "args"}
|
||||
|
||||
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) {
|
||||
|
@ -44,9 +44,9 @@ func TestUpdateLabels(t *testing.T) {
|
|||
}
|
||||
|
||||
updateLabels(flags, &labels)
|
||||
assert.Len(t, labels, 2)
|
||||
assert.Equal(t, "value", labels["tokeep"])
|
||||
assert.Equal(t, "newlabel", labels["toadd"])
|
||||
assert.Check(t, is.Len(labels, 2))
|
||||
assert.Check(t, is.Equal("value", labels["tokeep"]))
|
||||
assert.Check(t, is.Equal("newlabel", labels["toadd"]))
|
||||
}
|
||||
|
||||
func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
|
||||
|
@ -55,7 +55,7 @@ func TestUpdateLabelsRemoveALabelThatDoesNotExist(t *testing.T) {
|
|||
|
||||
labels := map[string]string{"foo": "theoldlabel"}
|
||||
updateLabels(flags, &labels)
|
||||
assert.Len(t, labels, 1)
|
||||
assert.Check(t, is.Len(labels, 1))
|
||||
}
|
||||
|
||||
func TestUpdatePlacementConstraints(t *testing.T) {
|
||||
|
@ -68,9 +68,9 @@ func TestUpdatePlacementConstraints(t *testing.T) {
|
|||
}
|
||||
|
||||
updatePlacementConstraints(flags, placement)
|
||||
require.Len(t, placement.Constraints, 2)
|
||||
assert.Equal(t, "container=tokeep", placement.Constraints[0])
|
||||
assert.Equal(t, "node=toadd", placement.Constraints[1])
|
||||
assert.Assert(t, is.Len(placement.Constraints, 2))
|
||||
assert.Check(t, is.Equal("container=tokeep", placement.Constraints[0]))
|
||||
assert.Check(t, is.Equal("node=toadd", placement.Constraints[1]))
|
||||
}
|
||||
|
||||
func TestUpdatePlacementPrefs(t *testing.T) {
|
||||
|
@ -94,9 +94,9 @@ func TestUpdatePlacementPrefs(t *testing.T) {
|
|||
}
|
||||
|
||||
updatePlacementPreferences(flags, placement)
|
||||
require.Len(t, placement.Preferences, 2)
|
||||
assert.Equal(t, "node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor)
|
||||
assert.Equal(t, "node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor)
|
||||
assert.Assert(t, is.Len(placement.Preferences, 2))
|
||||
assert.Check(t, is.Equal("node.labels.row", placement.Preferences[0].Spread.SpreadDescriptor))
|
||||
assert.Check(t, is.Equal("node.labels.dc", placement.Preferences[1].Spread.SpreadDescriptor))
|
||||
}
|
||||
|
||||
func TestUpdateEnvironment(t *testing.T) {
|
||||
|
@ -107,11 +107,11 @@ func TestUpdateEnvironment(t *testing.T) {
|
|||
envs := []string{"toremove=theenvtoremove", "tokeep=value"}
|
||||
|
||||
updateEnvironment(flags, &envs)
|
||||
require.Len(t, envs, 2)
|
||||
assert.Assert(t, is.Len(envs, 2))
|
||||
// Order has been removed in updateEnvironment (map)
|
||||
sort.Strings(envs)
|
||||
assert.Equal(t, "toadd=newenv", envs[0])
|
||||
assert.Equal(t, "tokeep=value", envs[1])
|
||||
assert.Check(t, is.Equal("toadd=newenv", envs[0]))
|
||||
assert.Check(t, is.Equal("tokeep=value", envs[1]))
|
||||
}
|
||||
|
||||
func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
|
||||
|
@ -123,7 +123,7 @@ func TestUpdateEnvironmentWithDuplicateValues(t *testing.T) {
|
|||
envs := []string{"foo=value"}
|
||||
|
||||
updateEnvironment(flags, &envs)
|
||||
assert.Len(t, envs, 0)
|
||||
assert.Check(t, is.Len(envs, 0))
|
||||
}
|
||||
|
||||
func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
|
||||
|
@ -134,8 +134,8 @@ func TestUpdateEnvironmentWithDuplicateKeys(t *testing.T) {
|
|||
envs := []string{"A=c"}
|
||||
|
||||
updateEnvironment(flags, &envs)
|
||||
require.Len(t, envs, 1)
|
||||
assert.Equal(t, "A=b", envs[0])
|
||||
assert.Assert(t, is.Len(envs, 1))
|
||||
assert.Check(t, is.Equal("A=b", envs[0]))
|
||||
}
|
||||
|
||||
func TestUpdateGroups(t *testing.T) {
|
||||
|
@ -149,10 +149,10 @@ func TestUpdateGroups(t *testing.T) {
|
|||
groups := []string{"bar", "root"}
|
||||
|
||||
updateGroups(flags, &groups)
|
||||
require.Len(t, groups, 3)
|
||||
assert.Equal(t, "bar", groups[0])
|
||||
assert.Equal(t, "foo", groups[1])
|
||||
assert.Equal(t, "wheel", groups[2])
|
||||
assert.Assert(t, is.Len(groups, 3))
|
||||
assert.Check(t, is.Equal("bar", groups[0]))
|
||||
assert.Check(t, is.Equal("foo", groups[1]))
|
||||
assert.Check(t, is.Equal("wheel", groups[2]))
|
||||
}
|
||||
|
||||
func TestUpdateDNSConfig(t *testing.T) {
|
||||
|
@ -188,17 +188,17 @@ func TestUpdateDNSConfig(t *testing.T) {
|
|||
|
||||
updateDNSConfig(flags, &config)
|
||||
|
||||
require.Len(t, config.Nameservers, 3)
|
||||
assert.Equal(t, "1.1.1.1", config.Nameservers[0])
|
||||
assert.Equal(t, "2001:db8:abc8::1", config.Nameservers[1])
|
||||
assert.Equal(t, "5.5.5.5", config.Nameservers[2])
|
||||
assert.Assert(t, is.Len(config.Nameservers, 3))
|
||||
assert.Check(t, is.Equal("1.1.1.1", config.Nameservers[0]))
|
||||
assert.Check(t, is.Equal("2001:db8:abc8::1", config.Nameservers[1]))
|
||||
assert.Check(t, is.Equal("5.5.5.5", config.Nameservers[2]))
|
||||
|
||||
require.Len(t, config.Search, 2)
|
||||
assert.Equal(t, "example.com", config.Search[0])
|
||||
assert.Equal(t, "localdomain", config.Search[1])
|
||||
assert.Assert(t, is.Len(config.Search, 2))
|
||||
assert.Check(t, is.Equal("example.com", config.Search[0]))
|
||||
assert.Check(t, is.Equal("localdomain", config.Search[1]))
|
||||
|
||||
require.Len(t, config.Options, 1)
|
||||
assert.Equal(t, config.Options[0], "ndots:9")
|
||||
assert.Assert(t, is.Len(config.Options, 1))
|
||||
assert.Check(t, is.Equal(config.Options[0], "ndots:9"))
|
||||
}
|
||||
|
||||
func TestUpdateMounts(t *testing.T) {
|
||||
|
@ -212,9 +212,9 @@ func TestUpdateMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
updateMounts(flags, &mounts)
|
||||
require.Len(t, mounts, 2)
|
||||
assert.Equal(t, "/toadd", mounts[0].Target)
|
||||
assert.Equal(t, "/tokeep", mounts[1].Target)
|
||||
assert.Assert(t, is.Len(mounts, 2))
|
||||
assert.Check(t, is.Equal("/toadd", mounts[0].Target))
|
||||
assert.Check(t, is.Equal("/tokeep", mounts[1].Target))
|
||||
}
|
||||
|
||||
func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
|
||||
|
@ -228,10 +228,10 @@ func TestUpdateMountsWithDuplicateMounts(t *testing.T) {
|
|||
}
|
||||
|
||||
updateMounts(flags, &mounts)
|
||||
require.Len(t, mounts, 3)
|
||||
assert.Equal(t, "/tokeep1", mounts[0].Target)
|
||||
assert.Equal(t, "/tokeep2", mounts[1].Target)
|
||||
assert.Equal(t, "/toadd", mounts[2].Target)
|
||||
assert.Assert(t, is.Len(mounts, 3))
|
||||
assert.Check(t, is.Equal("/tokeep1", mounts[0].Target))
|
||||
assert.Check(t, is.Equal("/tokeep2", mounts[1].Target))
|
||||
assert.Check(t, is.Equal("/toadd", mounts[2].Target))
|
||||
}
|
||||
|
||||
func TestUpdatePorts(t *testing.T) {
|
||||
|
@ -245,13 +245,13 @@ func TestUpdatePorts(t *testing.T) {
|
|||
}
|
||||
|
||||
err := updatePorts(flags, &portConfigs)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, portConfigs, 2)
|
||||
assert.Check(t, err)
|
||||
assert.Assert(t, is.Len(portConfigs, 2))
|
||||
// Do a sort to have the order (might have changed by map)
|
||||
targetPorts := []int{int(portConfigs[0].TargetPort), int(portConfigs[1].TargetPort)}
|
||||
sort.Ints(targetPorts)
|
||||
assert.Equal(t, 555, targetPorts[0])
|
||||
assert.Equal(t, 1000, targetPorts[1])
|
||||
assert.Check(t, is.Equal(555, targetPorts[0]))
|
||||
assert.Check(t, is.Equal(1000, targetPorts[1]))
|
||||
}
|
||||
|
||||
func TestUpdatePortsDuplicate(t *testing.T) {
|
||||
|
@ -269,9 +269,9 @@ func TestUpdatePortsDuplicate(t *testing.T) {
|
|||
}
|
||||
|
||||
err := updatePorts(flags, &portConfigs)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, portConfigs, 1)
|
||||
assert.Equal(t, uint32(80), portConfigs[0].TargetPort)
|
||||
assert.Check(t, err)
|
||||
assert.Assert(t, is.Len(portConfigs, 1))
|
||||
assert.Check(t, is.Equal(uint32(80), portConfigs[0].TargetPort))
|
||||
}
|
||||
|
||||
func TestUpdateHealthcheckTable(t *testing.T) {
|
||||
|
@ -345,9 +345,9 @@ func TestUpdateHealthcheckTable(t *testing.T) {
|
|||
}
|
||||
err := updateHealthcheck(flags, cspec)
|
||||
if c.err != "" {
|
||||
assert.EqualError(t, err, c.err)
|
||||
assert.Check(t, is.Error(err, c.err))
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
if !reflect.DeepEqual(cspec.Healthcheck, c.expected) {
|
||||
t.Errorf("incorrect result for test %d, expected health config:\n\t%#v\ngot:\n\t%#v", i, c.expected, cspec.Healthcheck)
|
||||
}
|
||||
|
@ -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"}
|
||||
|
||||
err := updateHosts(flags, &hosts)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, hosts)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.DeepEqual(expected, hosts))
|
||||
}
|
||||
|
||||
func TestUpdateHostsPreservesOrder(t *testing.T) {
|
||||
|
@ -382,8 +382,8 @@ func TestUpdateHostsPreservesOrder(t *testing.T) {
|
|||
|
||||
hosts := []string{}
|
||||
err := updateHosts(flags, &hosts)
|
||||
assert.NoError(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, err)
|
||||
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) {
|
||||
|
@ -404,10 +404,10 @@ func TestUpdatePortsRmWithProtocol(t *testing.T) {
|
|||
}
|
||||
|
||||
err := updatePorts(flags, &portConfigs)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, portConfigs, 2)
|
||||
assert.Equal(t, uint32(81), portConfigs[0].TargetPort)
|
||||
assert.Equal(t, uint32(82), portConfigs[1].TargetPort)
|
||||
assert.Check(t, err)
|
||||
assert.Assert(t, is.Len(portConfigs, 2))
|
||||
assert.Check(t, is.Equal(uint32(81), portConfigs[0].TargetPort))
|
||||
assert.Check(t, is.Equal(uint32(82), portConfigs[1].TargetPort))
|
||||
}
|
||||
|
||||
type secretAPIClientMock struct {
|
||||
|
@ -461,11 +461,11 @@ func TestUpdateSecretUpdateInPlace(t *testing.T) {
|
|||
|
||||
updatedSecrets, err := getUpdatedSecrets(apiClient, flags, secrets)
|
||||
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, updatedSecrets, 1)
|
||||
assert.Equal(t, "tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID)
|
||||
assert.Equal(t, "foo", updatedSecrets[0].SecretName)
|
||||
assert.Equal(t, "foo2", updatedSecrets[0].File.Name)
|
||||
assert.Check(t, err)
|
||||
assert.Assert(t, is.Len(updatedSecrets, 1))
|
||||
assert.Check(t, is.Equal("tn9qiblgnuuut11eufquw5dev", updatedSecrets[0].SecretID))
|
||||
assert.Check(t, is.Equal("foo", updatedSecrets[0].SecretName))
|
||||
assert.Check(t, is.Equal("foo2", updatedSecrets[0].File.Name))
|
||||
}
|
||||
|
||||
func TestUpdateReadOnly(t *testing.T) {
|
||||
|
@ -480,18 +480,18 @@ func TestUpdateReadOnly(t *testing.T) {
|
|||
flags := newUpdateCommand(nil).Flags()
|
||||
flags.Set("read-only", "true")
|
||||
updateService(nil, nil, flags, spec)
|
||||
assert.True(t, cspec.ReadOnly)
|
||||
assert.Check(t, cspec.ReadOnly)
|
||||
|
||||
// Update without --read-only, no change
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
updateService(nil, nil, flags, spec)
|
||||
assert.True(t, cspec.ReadOnly)
|
||||
assert.Check(t, cspec.ReadOnly)
|
||||
|
||||
// Update with --read-only=false, changed to false
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
flags.Set("read-only", "false")
|
||||
updateService(nil, nil, flags, spec)
|
||||
assert.False(t, cspec.ReadOnly)
|
||||
assert.Check(t, !cspec.ReadOnly)
|
||||
}
|
||||
|
||||
func TestUpdateStopSignal(t *testing.T) {
|
||||
|
@ -506,74 +506,74 @@ func TestUpdateStopSignal(t *testing.T) {
|
|||
flags := newUpdateCommand(nil).Flags()
|
||||
flags.Set("stop-signal", "SIGUSR1")
|
||||
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
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
updateService(nil, nil, flags, spec)
|
||||
assert.Equal(t, "SIGUSR1", cspec.StopSignal)
|
||||
assert.Check(t, is.Equal("SIGUSR1", cspec.StopSignal))
|
||||
|
||||
// Update with --stop-signal=SIGWINCH
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
flags.Set("stop-signal", "SIGWINCH")
|
||||
updateService(nil, nil, flags, spec)
|
||||
assert.Equal(t, "SIGWINCH", cspec.StopSignal)
|
||||
assert.Check(t, is.Equal("SIGWINCH", cspec.StopSignal))
|
||||
}
|
||||
|
||||
func TestUpdateIsolationValid(t *testing.T) {
|
||||
flags := newUpdateCommand(nil).Flags()
|
||||
err := flags.Set("isolation", "process")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
spec := swarm.ServiceSpec{
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{},
|
||||
},
|
||||
}
|
||||
err = updateService(context.Background(), nil, flags, &spec)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, container.IsolationProcess, spec.TaskTemplate.ContainerSpec.Isolation)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(container.IsolationProcess, spec.TaskTemplate.ContainerSpec.Isolation))
|
||||
}
|
||||
|
||||
func TestUpdateIsolationInvalid(t *testing.T) {
|
||||
// validation depends on daemon os / version so validation should be done on the daemon side
|
||||
flags := newUpdateCommand(nil).Flags()
|
||||
err := flags.Set("isolation", "test")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
spec := swarm.ServiceSpec{
|
||||
TaskTemplate: swarm.TaskSpec{
|
||||
ContainerSpec: &swarm.ContainerSpec{},
|
||||
},
|
||||
}
|
||||
err = updateService(context.Background(), nil, flags, &spec)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, container.Isolation("test"), spec.TaskTemplate.ContainerSpec.Isolation)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(container.Isolation("test"), spec.TaskTemplate.ContainerSpec.Isolation))
|
||||
}
|
||||
|
||||
func TestAddGenericResources(t *testing.T) {
|
||||
task := &swarm.TaskSpec{}
|
||||
flags := newUpdateCommand(nil).Flags()
|
||||
|
||||
assert.Nil(t, addGenericResources(flags, task))
|
||||
assert.Check(t, addGenericResources(flags, task))
|
||||
|
||||
flags.Set(flagGenericResourcesAdd, "foo=1")
|
||||
assert.NoError(t, addGenericResources(flags, task))
|
||||
assert.Len(t, task.Resources.Reservations.GenericResources, 1)
|
||||
assert.Check(t, addGenericResources(flags, task))
|
||||
assert.Check(t, is.Len(task.Resources.Reservations.GenericResources, 1))
|
||||
|
||||
// Checks that foo isn't added a 2nd time
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
flags.Set(flagGenericResourcesAdd, "bar=1")
|
||||
assert.NoError(t, addGenericResources(flags, task))
|
||||
assert.Len(t, task.Resources.Reservations.GenericResources, 2)
|
||||
assert.Check(t, addGenericResources(flags, task))
|
||||
assert.Check(t, is.Len(task.Resources.Reservations.GenericResources, 2))
|
||||
}
|
||||
|
||||
func TestRemoveGenericResources(t *testing.T) {
|
||||
task := &swarm.TaskSpec{}
|
||||
flags := newUpdateCommand(nil).Flags()
|
||||
|
||||
assert.Nil(t, removeGenericResources(flags, task))
|
||||
assert.Check(t, removeGenericResources(flags, task))
|
||||
|
||||
flags.Set(flagGenericResourcesRemove, "foo")
|
||||
assert.Error(t, removeGenericResources(flags, task))
|
||||
assert.Check(t, is.ErrorContains(removeGenericResources(flags, task), ""))
|
||||
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
flags.Set(flagGenericResourcesAdd, "foo=1")
|
||||
|
@ -584,8 +584,8 @@ func TestRemoveGenericResources(t *testing.T) {
|
|||
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
flags.Set(flagGenericResourcesRemove, "foo")
|
||||
assert.NoError(t, removeGenericResources(flags, task))
|
||||
assert.Len(t, task.Resources.Reservations.GenericResources, 1)
|
||||
assert.Check(t, removeGenericResources(flags, task))
|
||||
assert.Check(t, is.Len(task.Resources.Reservations.GenericResources, 1))
|
||||
}
|
||||
|
||||
func TestUpdateNetworks(t *testing.T) {
|
||||
|
@ -618,38 +618,38 @@ func TestUpdateNetworks(t *testing.T) {
|
|||
|
||||
flags := newUpdateCommand(nil).Flags()
|
||||
err := flags.Set(flagNetworkAdd, "aaa-network")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = updateService(ctx, client, flags, &svc)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks)
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
|
||||
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
err = flags.Set(flagNetworkAdd, "aaa-network")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = updateService(ctx, client, flags, &svc)
|
||||
assert.EqualError(t, 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.Error(err, "service is already attached to network aaa-network"))
|
||||
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
|
||||
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
err = flags.Set(flagNetworkAdd, "id555")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = updateService(ctx, client, flags, &svc)
|
||||
assert.EqualError(t, err, "service is already attached to network id555")
|
||||
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks)
|
||||
assert.Check(t, is.Error(err, "service is already attached to network id555"))
|
||||
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}, {Target: "id999"}}, svc.TaskTemplate.Networks))
|
||||
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
err = flags.Set(flagNetworkRemove, "id999")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = updateService(ctx, client, flags, &svc)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id555"}}, svc.TaskTemplate.Networks)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id555"}}, svc.TaskTemplate.Networks))
|
||||
|
||||
flags = newUpdateCommand(nil).Flags()
|
||||
err = flags.Set(flagNetworkAdd, "mmm-network")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = flags.Set(flagNetworkRemove, "aaa-network")
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
err = updateService(ctx, client, flags, &svc)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, []swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.DeepEqual([]swarm.NetworkAttachmentConfig{{Target: "id999"}}, svc.TaskTemplate.Networks))
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import (
|
|||
|
||||
composetypes "github.com/docker/cli/cli/compose/types"
|
||||
apiv1beta1 "github.com/docker/cli/kubernetes/compose/v1beta1"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
||||
|
@ -24,13 +25,13 @@ func TestLoadStack(t *testing.T) {
|
|||
},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, &apiv1beta1.Stack{
|
||||
assert.NilError(t, err)
|
||||
assert.DeepEqual(t, &apiv1beta1.Stack{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "foo",
|
||||
},
|
||||
Spec: apiv1beta1.StackSpec{
|
||||
ComposeFile: string(`version: "3.1"
|
||||
ComposeFile: `version: "3.1"
|
||||
services:
|
||||
bar:
|
||||
image: bar
|
||||
|
@ -40,7 +41,15 @@ networks: {}
|
|||
volumes: {}
|
||||
secrets: {}
|
||||
configs: {}
|
||||
`),
|
||||
`,
|
||||
},
|
||||
}, s)
|
||||
}, s, cmpKubeAPITime)
|
||||
}
|
||||
|
||||
// TODO: this can be removed when k8s.io/apimachinery is updated to > 1.9.0
|
||||
var cmpKubeAPITime = cmp.Comparer(func(x, y *metav1.Time) bool {
|
||||
if x == nil || y == nil {
|
||||
return x == y
|
||||
}
|
||||
return x.Time.Equal(y.Time)
|
||||
})
|
||||
|
|
|
@ -10,9 +10,9 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/gotestyourself/gotestyourself/golden"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestListErrors(t *testing.T) {
|
||||
|
@ -72,7 +72,7 @@ func TestListWithFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newListCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ func TestListWithoutFormat(t *testing.T) {
|
|||
},
|
||||
})
|
||||
cmd := newListCommand(cli)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), "stack-list-without-format.golden")
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ func TestListOrder(t *testing.T) {
|
|||
},
|
||||
})
|
||||
cmd := newListCommand(cli)
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
golden.Assert(t, cli.OutBuffer().String(), uc.golden)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"github.com/gotestyourself/gotestyourself/fs"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGetConfigDetails(t *testing.T) {
|
||||
|
@ -22,11 +22,11 @@ services:
|
|||
defer file.Remove()
|
||||
|
||||
details, err := getConfigDetails([]string{file.Path()}, nil)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, filepath.Dir(file.Path()), details.WorkingDir)
|
||||
require.Len(t, details.ConfigFiles, 1)
|
||||
assert.Equal(t, "3.0", details.ConfigFiles[0].Config["version"])
|
||||
assert.Len(t, details.Environment, len(os.Environ()))
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(filepath.Dir(file.Path()), details.WorkingDir))
|
||||
assert.Assert(t, is.Len(details.ConfigFiles, 1))
|
||||
assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
|
||||
assert.Check(t, is.Len(details.Environment, len(os.Environ())))
|
||||
}
|
||||
|
||||
func TestGetConfigDetailsStdin(t *testing.T) {
|
||||
|
@ -37,11 +37,11 @@ services:
|
|||
image: alpine:3.5
|
||||
`
|
||||
details, err := getConfigDetails([]string{"-"}, strings.NewReader(content))
|
||||
require.NoError(t, err)
|
||||
assert.NilError(t, err)
|
||||
cwd, err := os.Getwd()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, cwd, details.WorkingDir)
|
||||
require.Len(t, details.ConfigFiles, 1)
|
||||
assert.Equal(t, "3.0", details.ConfigFiles[0].Config["version"])
|
||||
assert.Len(t, details.Environment, len(os.Environ()))
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(cwd, details.WorkingDir))
|
||||
assert.Assert(t, is.Len(details.ConfigFiles, 1))
|
||||
assert.Check(t, is.Equal("3.0", details.ConfigFiles[0].Config["version"]))
|
||||
assert.Check(t, is.Len(details.Environment, len(os.Environ())))
|
||||
}
|
||||
|
|
|
@ -12,9 +12,10 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStackPsErrors(t *testing.T) {
|
||||
|
@ -61,9 +62,8 @@ func TestStackPsEmptyStack(t *testing.T) {
|
|||
cmd.SetArgs([]string{"foo"})
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
|
||||
assert.Error(t, cmd.Execute())
|
||||
assert.EqualError(t, cmd.Execute(), "nothing found in stack: foo")
|
||||
assert.Equal(t, "", fakeCli.OutBuffer().String())
|
||||
assert.Check(t, is.Error(cmd.Execute(), "nothing found in stack: foo"))
|
||||
assert.Check(t, is.Equal("", fakeCli.OutBuffer().String()))
|
||||
}
|
||||
|
||||
func TestStackPsWithQuietOption(t *testing.T) {
|
||||
|
@ -75,7 +75,7 @@ func TestStackPsWithQuietOption(t *testing.T) {
|
|||
cmd := newPsCommand(cli)
|
||||
cmd.SetArgs([]string{"foo"})
|
||||
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")
|
||||
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ func TestStackPsWithNoTruncOption(t *testing.T) {
|
|||
cmd.SetArgs([]string{"foo"})
|
||||
cmd.Flags().Set("no-trunc", "true")
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ func TestStackPsWithNoResolveOption(t *testing.T) {
|
|||
cmd.SetArgs([]string{"foo"})
|
||||
cmd.Flags().Set("no-resolve", "true")
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ func TestStackPsWithFormat(t *testing.T) {
|
|||
cmd := newPsCommand(cli)
|
||||
cmd.SetArgs([]string{"foo"})
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ func TestStackPsWithConfigFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newPsCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -159,6 +159,6 @@ func TestStackPsWithoutFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newPsCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import (
|
|||
"testing"
|
||||
|
||||
"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 {
|
||||
|
@ -45,11 +46,11 @@ func TestRemoveStackVersion124DoesNotRemoveConfigsOrSecrets(t *testing.T) {
|
|||
cmd := newRemoveCommand(test.NewFakeCli(client))
|
||||
cmd.SetArgs([]string{"foo", "bar"})
|
||||
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||
assert.Nil(t, client.removedSecrets)
|
||||
assert.Nil(t, client.removedConfigs)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
|
||||
assert.Check(t, is.Len(client.removedSecrets, 0))
|
||||
assert.Check(t, is.Len(client.removedConfigs, 0))
|
||||
}
|
||||
|
||||
func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
|
||||
|
@ -57,11 +58,11 @@ func TestRemoveStackVersion125DoesNotRemoveConfigs(t *testing.T) {
|
|||
cmd := newRemoveCommand(test.NewFakeCli(client))
|
||||
cmd.SetArgs([]string{"foo", "bar"})
|
||||
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets)
|
||||
assert.Nil(t, client.removedConfigs)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.secrets), client.removedSecrets))
|
||||
assert.Check(t, is.Len(client.removedConfigs, 0))
|
||||
}
|
||||
|
||||
func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
|
||||
|
@ -69,11 +70,11 @@ func TestRemoveStackVersion130RemovesEverything(t *testing.T) {
|
|||
cmd := newRemoveCommand(test.NewFakeCli(client))
|
||||
cmd.SetArgs([]string{"foo", "bar"})
|
||||
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, buildObjectIDs(client.services), client.removedServices)
|
||||
assert.Equal(t, buildObjectIDs(client.networks), client.removedNetworks)
|
||||
assert.Equal(t, buildObjectIDs(client.secrets), client.removedSecrets)
|
||||
assert.Equal(t, buildObjectIDs(client.configs), client.removedConfigs)
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.services), client.removedServices))
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.networks), client.removedNetworks))
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.secrets), client.removedSecrets))
|
||||
assert.Check(t, is.DeepEqual(buildObjectIDs(client.configs), client.removedConfigs))
|
||||
}
|
||||
|
||||
func TestRemoveStackSkipEmpty(t *testing.T) {
|
||||
|
@ -100,19 +101,19 @@ func TestRemoveStackSkipEmpty(t *testing.T) {
|
|||
cmd := newRemoveCommand(fakeCli)
|
||||
cmd.SetArgs([]string{"foo", "bar"})
|
||||
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Check(t, cmd.Execute())
|
||||
expectedList := []string{"Removing service bar_service1",
|
||||
"Removing service bar_service2",
|
||||
"Removing secret bar_secret1",
|
||||
"Removing config bar_config1",
|
||||
"Removing network bar_network1\n",
|
||||
}
|
||||
assert.Equal(t, strings.Join(expectedList, "\n"), fakeCli.OutBuffer().String())
|
||||
assert.Contains(t, fakeCli.ErrBuffer().String(), "Nothing found in stack: foo\n")
|
||||
assert.Equal(t, allServiceIDs, fakeClient.removedServices)
|
||||
assert.Equal(t, allNetworkIDs, fakeClient.removedNetworks)
|
||||
assert.Equal(t, allSecretIDs, fakeClient.removedSecrets)
|
||||
assert.Equal(t, allConfigIDs, fakeClient.removedConfigs)
|
||||
assert.Check(t, is.Equal(strings.Join(expectedList, "\n"), fakeCli.OutBuffer().String()))
|
||||
assert.Check(t, is.Contains(fakeCli.ErrBuffer().String(), "Nothing found in stack: foo\n"))
|
||||
assert.Check(t, is.DeepEqual(allServiceIDs, fakeClient.removedServices))
|
||||
assert.Check(t, is.DeepEqual(allNetworkIDs, fakeClient.removedNetworks))
|
||||
assert.Check(t, is.DeepEqual(allSecretIDs, fakeClient.removedSecrets))
|
||||
assert.Check(t, is.DeepEqual(allConfigIDs, fakeClient.removedConfigs))
|
||||
}
|
||||
|
||||
func TestRemoveContinueAfterError(t *testing.T) {
|
||||
|
@ -149,9 +150,9 @@ func TestRemoveContinueAfterError(t *testing.T) {
|
|||
cmd.SetOutput(ioutil.Discard)
|
||||
cmd.SetArgs([]string{"foo", "bar"})
|
||||
|
||||
assert.EqualError(t, cmd.Execute(), "Failed to remove some resources from stack: foo")
|
||||
assert.Equal(t, allServiceIDs, removedServices)
|
||||
assert.Equal(t, allNetworkIDs, cli.removedNetworks)
|
||||
assert.Equal(t, allSecretIDs, cli.removedSecrets)
|
||||
assert.Equal(t, allConfigIDs, cli.removedConfigs)
|
||||
assert.Check(t, is.Error(cmd.Execute(), "Failed to remove some resources from stack: foo"))
|
||||
assert.Check(t, is.DeepEqual(allServiceIDs, removedServices))
|
||||
assert.Check(t, is.DeepEqual(allNetworkIDs, cli.removedNetworks))
|
||||
assert.Check(t, is.DeepEqual(allSecretIDs, cli.removedSecrets))
|
||||
assert.Check(t, is.DeepEqual(allConfigIDs, cli.removedConfigs))
|
||||
}
|
||||
|
|
|
@ -11,9 +11,10 @@ import (
|
|||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestStackServicesErrors(t *testing.T) {
|
||||
|
@ -88,9 +89,9 @@ func TestStackServicesEmptyServiceList(t *testing.T) {
|
|||
})
|
||||
cmd := newServicesCommand(fakeCli)
|
||||
cmd.SetArgs([]string{"foo"})
|
||||
assert.NoError(t, cmd.Execute())
|
||||
assert.Equal(t, "", fakeCli.OutBuffer().String())
|
||||
assert.Equal(t, "Nothing found in stack: foo\n", fakeCli.ErrBuffer().String())
|
||||
assert.Check(t, cmd.Execute())
|
||||
assert.Check(t, is.Equal("", fakeCli.OutBuffer().String()))
|
||||
assert.Check(t, is.Equal("Nothing found in stack: foo\n", fakeCli.ErrBuffer().String()))
|
||||
}
|
||||
|
||||
func TestStackServicesWithQuietOption(t *testing.T) {
|
||||
|
@ -102,7 +103,7 @@ func TestStackServicesWithQuietOption(t *testing.T) {
|
|||
cmd := newServicesCommand(cli)
|
||||
cmd.Flags().Set("quiet", "true")
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -117,7 +118,7 @@ func TestStackServicesWithFormat(t *testing.T) {
|
|||
cmd := newServicesCommand(cli)
|
||||
cmd.SetArgs([]string{"foo"})
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -134,7 +135,7 @@ func TestStackServicesWithConfigFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newServicesCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
||||
|
@ -157,6 +158,6 @@ func TestStackServicesWithoutFormat(t *testing.T) {
|
|||
})
|
||||
cmd := newServicesCommand(cli)
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -2,38 +2,39 @@ package swarm
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func TestLoadBundlefileErrors(t *testing.T) {
|
||||
testCases := []struct {
|
||||
namespace string
|
||||
path string
|
||||
expectedError error
|
||||
expectedError string
|
||||
}{
|
||||
{
|
||||
namespace: "namespace_foo",
|
||||
expectedError: fmt.Errorf("Bundle %s.dab not found", "namespace_foo"),
|
||||
expectedError: "Bundle namespace_foo.dab not found",
|
||||
},
|
||||
{
|
||||
namespace: "namespace_foo",
|
||||
path: "invalid_path",
|
||||
expectedError: fmt.Errorf("Bundle %s not found", "invalid_path"),
|
||||
},
|
||||
{
|
||||
namespace: "namespace_foo",
|
||||
path: filepath.Join("testdata", "bundlefile_with_invalid_syntax"),
|
||||
expectedError: fmt.Errorf("Error reading"),
|
||||
expectedError: "Bundle invalid_path not found",
|
||||
},
|
||||
// FIXME: this test never working, testdata file is missing from repo
|
||||
//{
|
||||
// namespace: "namespace_foo",
|
||||
// path: string(golden.Get(t, "bundlefile_with_invalid_syntax")),
|
||||
// expectedError: "Error reading",
|
||||
//},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
_, err := loadBundlefile(&bytes.Buffer{}, tc.namespace, tc.path)
|
||||
assert.Error(t, err, tc.expectedError)
|
||||
assert.ErrorContains(t, err, tc.expectedError)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,6 +45,6 @@ func TestLoadBundlefile(t *testing.T) {
|
|||
path := filepath.Join("testdata", "bundlefile_with_two_services.dab")
|
||||
bundleFile, err := loadBundlefile(buf, namespace, path)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(bundleFile.Services), 2)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(len(bundleFile.Services), 2))
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/docker/cli/internal/test/network"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -57,7 +57,7 @@ func TestValidateExternalNetworks(t *testing.T) {
|
|||
networks := []string{testcase.network}
|
||||
err := validateExternalNetworks(context.Background(), fakeClient, networks)
|
||||
if testcase.expectedMsg == "" {
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
} else {
|
||||
testutil.ErrorContains(t, err, testcase.expectedMsg)
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -22,7 +23,7 @@ func TestPruneServices(t *testing.T) {
|
|||
dockerCli := test.NewFakeCli(client)
|
||||
|
||||
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
|
||||
|
@ -93,9 +94,9 @@ func TestServiceUpdateResolveImageChanged(t *testing.T) {
|
|||
},
|
||||
}
|
||||
err := deployServices(ctx, client, spec, namespace, false, ResolveImageChanged)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, testcase.expectedQueryRegistry, receivedOptions.QueryRegistry)
|
||||
assert.Equal(t, testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image)
|
||||
assert.Check(t, err)
|
||||
assert.Check(t, is.Equal(testcase.expectedQueryRegistry, receivedOptions.QueryRegistry))
|
||||
assert.Check(t, is.Equal(testcase.expectedImage, receivedService.TaskTemplate.ContainerSpec.Image))
|
||||
|
||||
receivedService = swarm.ServiceSpec{}
|
||||
receivedOptions = types.ServiceUpdateOptions{}
|
||||
|
|
|
@ -10,8 +10,8 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/cli/internal/test/testutil"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/gotestyourself/gotestyourself/assert"
|
||||
is "github.com/gotestyourself/gotestyourself/assert/cmp"
|
||||
)
|
||||
|
||||
func swarmSpecWithFullCAConfig() *swarm.Spec {
|
||||
|
@ -35,13 +35,13 @@ func swarmSpecWithFullCAConfig() *swarm.Spec {
|
|||
func TestDisplayTrustRootNoRoot(t *testing.T) {
|
||||
buffer := new(bytes.Buffer)
|
||||
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) {
|
||||
// we need an actual PEMfile to test
|
||||
tmpfile, err := ioutil.TempFile("", "pemfile")
|
||||
assert.NoError(t, err)
|
||||
assert.Check(t, err)
|
||||
defer os.Remove(tmpfile.Name())
|
||||
tmpfile.Write([]byte(`
|
||||
-----BEGIN CERTIFICATE-----
|
||||
|
@ -95,7 +95,7 @@ PQQDAgNIADBFAiEAqD3Kb2rgsy6NoTk+zEgcUi/aGBCsvQDG3vML1PXN8j0CIBjj
|
|||
}, nil
|
||||
},
|
||||
}))
|
||||
assert.NoError(t, cmd.Flags().Parse(args))
|
||||
assert.Check(t, cmd.Flags().Parse(args))
|
||||
cmd.SetOutput(ioutil.Discard)
|
||||
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},
|
||||
},
|
||||
})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, trustRoot+"\n", buffer.String())
|
||||
assert.NilError(t, err)
|
||||
assert.Check(t, is.Equal(trustRoot+"\n", buffer.String()))
|
||||
}
|
||||
|
||||
func TestUpdateSwarmSpecDefaultRotate(t *testing.T) {
|
||||
|
@ -122,7 +122,7 @@ func TestUpdateSwarmSpecDefaultRotate(t *testing.T) {
|
|||
expected.CAConfig.ForceRotate = 2
|
||||
expected.CAConfig.SigningCACert = ""
|
||||
expected.CAConfig.SigningCAKey = ""
|
||||
assert.Equal(t, expected, spec)
|
||||
assert.Check(t, is.DeepEqual(expected, spec))
|
||||
}
|
||||
|
||||
func TestUpdateSwarmSpecPartial(t *testing.T) {
|
||||
|
@ -134,7 +134,7 @@ func TestUpdateSwarmSpecPartial(t *testing.T) {
|
|||
|
||||
expected := swarmSpecWithFullCAConfig()
|
||||
expected.CAConfig.SigningCACert = "cacert"
|
||||
assert.Equal(t, expected, spec)
|
||||
assert.Check(t, is.DeepEqual(expected, spec))
|
||||
}
|
||||
|
||||
func TestUpdateSwarmSpecFullFlags(t *testing.T) {
|
||||
|
@ -151,5 +151,5 @@ func TestUpdateSwarmSpecFullFlags(t *testing.T) {
|
|||
expected.CAConfig.SigningCACert = "cacert"
|
||||
expected.CAConfig.SigningCAKey = "cakey"
|
||||
expected.CAConfig.NodeCertExpiry = 3 * time.Minute
|
||||
assert.Equal(t, expected, spec)
|
||||
assert.Check(t, is.DeepEqual(expected, spec))
|
||||
}
|
||||
|
|
|
@ -8,9 +8,10 @@ import (
|
|||
"github.com/docker/cli/internal/test"
|
||||
"github.com/docker/docker/api/types"
|
||||
"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/pkg/errors"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
||||
|
@ -74,7 +75,7 @@ func TestSwarmInitErrorOnAPIFailure(t *testing.T) {
|
|||
cmd.Flags().Set(key, value)
|
||||
}
|
||||
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 {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue