|
|
@@ -49,9 +49,9 @@ func TestMain(m *testing.M) {
|
|
|
|
|
|
func TestComposeNotImplemented(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
- res := c.RunDocker("context", "show")
|
|
|
+ res := c.RunDockerCmd("context", "show")
|
|
|
res.Assert(t, icmd.Expected{Out: "default"})
|
|
|
- res = c.RunDockerOrFail("compose", "up")
|
|
|
+ res = c.RunDockerOrExitError("compose", "up")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: `Command "compose up" not available in current context (default)`,
|
|
|
@@ -62,58 +62,58 @@ func TestContextDefault(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("show", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "show")
|
|
|
+ res := c.RunDockerCmd("context", "show")
|
|
|
res.Assert(t, icmd.Expected{Out: "default"})
|
|
|
})
|
|
|
|
|
|
t.Run("ls", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "ls")
|
|
|
+ res := c.RunDockerCmd("context", "ls")
|
|
|
golden.Assert(t, res.Stdout(), GoldenFile("ls-out-default"))
|
|
|
})
|
|
|
|
|
|
t.Run("inspect", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "inspect", "default")
|
|
|
+ res := c.RunDockerCmd("context", "inspect", "default")
|
|
|
res.Assert(t, icmd.Expected{Out: `"Name": "default"`})
|
|
|
})
|
|
|
|
|
|
t.Run("inspect current", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "inspect")
|
|
|
+ res := c.RunDockerCmd("context", "inspect")
|
|
|
res.Assert(t, icmd.Expected{Out: `"Name": "default"`})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func TestContextCreateDocker(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
- res := c.RunDocker("context", "create", "test-docker", "--from", "default")
|
|
|
+ res := c.RunDockerCmd("context", "create", "test-docker", "--from", "default")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-docker"})
|
|
|
|
|
|
t.Run("ls", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "ls")
|
|
|
+ res := c.RunDockerCmd("context", "ls")
|
|
|
golden.Assert(t, res.Stdout(), GoldenFile("ls-out-test-docker"))
|
|
|
})
|
|
|
|
|
|
t.Run("ls quiet", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "ls", "-q")
|
|
|
+ res := c.RunDockerCmd("context", "ls", "-q")
|
|
|
golden.Assert(t, res.Stdout(), "ls-out-test-docker-quiet.golden")
|
|
|
})
|
|
|
|
|
|
t.Run("ls format", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "ls", "--format", "{{ json . }}")
|
|
|
+ res := c.RunDockerCmd("context", "ls", "--format", "{{ json . }}")
|
|
|
res.Assert(t, icmd.Expected{Out: `"Name":"default"`})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func TestContextInspect(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
- res := c.RunDocker("context", "create", "test-docker", "--from", "default")
|
|
|
+ res := c.RunDockerCmd("context", "create", "test-docker", "--from", "default")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-docker"})
|
|
|
|
|
|
t.Run("inspect current", func(t *testing.T) {
|
|
|
// Cannot be run in parallel because of "context use"
|
|
|
- res := c.RunDocker("context", "use", "test-docker")
|
|
|
+ res := c.RunDockerCmd("context", "use", "test-docker")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-docker"})
|
|
|
|
|
|
- res = c.RunDocker("context", "inspect")
|
|
|
+ res = c.RunDockerCmd("context", "inspect")
|
|
|
res.Assert(t, icmd.Expected{Out: `"Name": "test-docker"`})
|
|
|
})
|
|
|
}
|
|
|
@@ -122,7 +122,7 @@ func TestContextHelpACI(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("help", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "create", "aci", "--help")
|
|
|
+ res := c.RunDockerCmd("context", "create", "aci", "--help")
|
|
|
// Can't use golden here as the help prints the config directory which changes
|
|
|
res.Assert(t, icmd.Expected{Out: "docker context create aci CONTEXT [flags]"})
|
|
|
res.Assert(t, icmd.Expected{Out: "--location"})
|
|
|
@@ -131,7 +131,7 @@ func TestContextHelpACI(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("check exec", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("context", "create", "aci", "--subscription-id", "invalid-id")
|
|
|
+ res := c.RunDockerOrExitError("context", "create", "aci", "--subscription-id", "invalid-id")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "accepts 1 arg(s), received 0",
|
|
|
@@ -143,8 +143,8 @@ func TestContextHelpACI(t *testing.T) {
|
|
|
func TestContextDuplicateACI(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
- c.RunDocker("context", "create", "mycontext", "--from", "default")
|
|
|
- res := c.RunDockerOrFail("context", "create", "aci", "mycontext")
|
|
|
+ c.RunDockerCmd("context", "create", "mycontext", "--from", "default")
|
|
|
+ res := c.RunDockerOrExitError("context", "create", "aci", "mycontext")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "context mycontext: already exists",
|
|
|
@@ -156,10 +156,10 @@ func TestContextRemove(t *testing.T) {
|
|
|
t.Run("remove current", func(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
- c.RunDocker("context", "create", "test-context-rm", "--from", "default")
|
|
|
- res := c.RunDocker("context", "use", "test-context-rm")
|
|
|
+ c.RunDockerCmd("context", "create", "test-context-rm", "--from", "default")
|
|
|
+ res := c.RunDockerCmd("context", "use", "test-context-rm")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-context-rm"})
|
|
|
- res = c.RunDockerOrFail("context", "rm", "test-context-rm")
|
|
|
+ res = c.RunDockerOrExitError("context", "rm", "test-context-rm")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "cannot delete current context",
|
|
|
@@ -169,11 +169,11 @@ func TestContextRemove(t *testing.T) {
|
|
|
t.Run("force remove current", func(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
- c.RunDocker("context", "create", "test-context-rmf")
|
|
|
- c.RunDocker("context", "use", "test-context-rmf")
|
|
|
- res := c.RunDocker("context", "rm", "-f", "test-context-rmf")
|
|
|
+ c.RunDockerCmd("context", "create", "test-context-rmf")
|
|
|
+ c.RunDockerCmd("context", "use", "test-context-rmf")
|
|
|
+ res := c.RunDockerCmd("context", "rm", "-f", "test-context-rmf")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-context-rmf"})
|
|
|
- res = c.RunDocker("context", "ls")
|
|
|
+ res = c.RunDockerCmd("context", "ls")
|
|
|
res.Assert(t, icmd.Expected{Out: "default *"})
|
|
|
})
|
|
|
}
|
|
|
@@ -184,7 +184,7 @@ func TestLoginCommandDelegation(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("default context", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
+ res := c.RunDockerOrExitError("login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "unauthorized: incorrect username or password",
|
|
|
@@ -192,7 +192,7 @@ func TestLoginCommandDelegation(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("interactive", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("login", "someregistry.docker.io")
|
|
|
+ res := c.RunDockerOrExitError("login", "someregistry.docker.io")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "Cannot perform an interactive login from a non TTY device",
|
|
|
@@ -200,14 +200,14 @@ func TestLoginCommandDelegation(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("logout", func(t *testing.T) {
|
|
|
- res := c.RunDocker("logout", "someregistry.docker.io")
|
|
|
+ res := c.RunDockerCmd("logout", "someregistry.docker.io")
|
|
|
res.Assert(t, icmd.Expected{Out: "someregistry.docker.io"})
|
|
|
})
|
|
|
|
|
|
t.Run("existing context", func(t *testing.T) {
|
|
|
- c.RunDocker("context", "create", "local", "local")
|
|
|
- c.RunDocker("context", "use", "local")
|
|
|
- res := c.RunDockerOrFail("login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
+ c.RunDockerCmd("context", "create", "local", "local")
|
|
|
+ c.RunDockerCmd("context", "use", "local")
|
|
|
+ res := c.RunDockerOrExitError("login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "unauthorized: incorrect username or password",
|
|
|
@@ -219,7 +219,7 @@ func TestCloudLogin(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("unknown backend", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("login", "mycloudbackend")
|
|
|
+ res := c.RunDockerOrExitError("login", "mycloudbackend")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "unknown backend type for cloud login: mycloudbackend",
|
|
|
@@ -266,12 +266,12 @@ func TestLegacy(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("help", func(t *testing.T) {
|
|
|
- res := c.RunDocker("--help")
|
|
|
+ res := c.RunDockerCmd("--help")
|
|
|
res.Assert(t, icmd.Expected{Out: "swarm"})
|
|
|
})
|
|
|
|
|
|
t.Run("swarm", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("swarm", "join")
|
|
|
+ res := c.RunDockerOrExitError("swarm", "join")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: `"docker swarm join" requires exactly 1 argument.`,
|
|
|
@@ -286,7 +286,7 @@ func TestLegacy(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("error messages", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("foo")
|
|
|
+ res := c.RunDockerOrExitError("foo")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "docker: 'foo' is not a docker command.",
|
|
|
@@ -298,7 +298,7 @@ func TestLegacy(t *testing.T) {
|
|
|
if runtime.GOOS == "windows" {
|
|
|
stderr = "error during connect: Get http://localhost:123"
|
|
|
}
|
|
|
- res := c.RunDockerOrFail("-H", "tcp://localhost:123", "version")
|
|
|
+ res := c.RunDockerOrExitError("-H", "tcp://localhost:123", "version")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: stderr,
|
|
|
@@ -306,9 +306,9 @@ func TestLegacy(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("existing contexts delegate", func(t *testing.T) {
|
|
|
- c.RunDocker("context", "create", "moby-ctx", "--from=default")
|
|
|
- c.RunDocker("context", "use", "moby-ctx")
|
|
|
- res := c.RunDockerOrFail("swarm", "join")
|
|
|
+ c.RunDockerCmd("context", "create", "moby-ctx", "--from=default")
|
|
|
+ c.RunDockerCmd("context", "use", "moby-ctx")
|
|
|
+ res := c.RunDockerOrExitError("swarm", "join")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: `"docker swarm join" requires exactly 1 argument.`,
|
|
|
@@ -316,16 +316,16 @@ func TestLegacy(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("host flag overrides context", func(t *testing.T) {
|
|
|
- c.RunDocker("context", "create", "example", "test-example")
|
|
|
- c.RunDocker("context", "use", "test-example")
|
|
|
+ c.RunDockerCmd("context", "create", "example", "test-example")
|
|
|
+ c.RunDockerCmd("context", "use", "test-example")
|
|
|
endpoint := "unix:///var/run/docker.sock"
|
|
|
if runtime.GOOS == "windows" {
|
|
|
endpoint = "npipe:////./pipe/docker_engine"
|
|
|
}
|
|
|
- res := c.RunDocker("-H", endpoint, "ps")
|
|
|
+ res := c.RunDockerCmd("-H", endpoint, "ps")
|
|
|
// Example backend's ps output includes these strings
|
|
|
- assert.Assert(t, !strings.Contains(res.Stdout(), "id"))
|
|
|
- assert.Assert(t, !strings.Contains(res.Stdout(), "1234"))
|
|
|
+ assert.Assert(t, !strings.Contains(res.Stdout(), "id"), "%q does not contains %q", res.Stdout(), "id")
|
|
|
+ assert.Assert(t, !strings.Contains(res.Stdout(), "1234"), "%q does not contains %q", res.Stdout(), "1234")
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -333,7 +333,7 @@ func TestLegacyLogin(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("host flag login", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("-H", "tcp://localhost:123", "login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
+ res := c.RunDockerOrExitError("-H", "tcp://localhost:123", "login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "WARNING! Using --password via the CLI is insecure. Use --password-stdin.",
|
|
|
@@ -341,7 +341,7 @@ func TestLegacyLogin(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("log level flag login", func(t *testing.T) {
|
|
|
- res := c.RunDockerOrFail("--log-level", "debug", "login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
+ res := c.RunDockerOrExitError("--log-level", "debug", "login", "-u", "nouser", "-p", "wrongpasword")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: "WARNING! Using --password via the CLI is insecure",
|
|
|
@@ -349,7 +349,7 @@ func TestLegacyLogin(t *testing.T) {
|
|
|
})
|
|
|
|
|
|
t.Run("login help global flags", func(t *testing.T) {
|
|
|
- res := c.RunDocker("login", "--help")
|
|
|
+ res := c.RunDockerCmd("login", "--help")
|
|
|
assert.Assert(t, !strings.Contains(res.Combined(), "--log-level"))
|
|
|
})
|
|
|
}
|
|
|
@@ -357,8 +357,8 @@ func TestLegacyLogin(t *testing.T) {
|
|
|
func TestUnsupportedCommand(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
- c.RunDocker("context", "create", "example", "test-example")
|
|
|
- res := c.RunDockerOrFail("--context", "test-example", "images")
|
|
|
+ c.RunDockerCmd("context", "create", "example", "test-example")
|
|
|
+ res := c.RunDockerOrExitError("--context", "test-example", "images")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
ExitCode: 1,
|
|
|
Err: `Command "images" not available in current context (test-example), you can use the "default" context to run this command`,
|
|
|
@@ -369,60 +369,60 @@ func TestVersion(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
|
|
|
t.Run("azure version", func(t *testing.T) {
|
|
|
- res := c.RunDocker("version")
|
|
|
+ res := c.RunDockerCmd("version")
|
|
|
res.Assert(t, icmd.Expected{Out: "Azure integration"})
|
|
|
})
|
|
|
|
|
|
t.Run("format", func(t *testing.T) {
|
|
|
- res := c.RunDocker("version", "-f", "{{ json . }}")
|
|
|
+ res := c.RunDockerCmd("version", "-f", "{{ json . }}")
|
|
|
res.Assert(t, icmd.Expected{Out: `"Client":`})
|
|
|
- res = c.RunDocker("version", "--format", "{{ json . }}")
|
|
|
+ res = c.RunDockerCmd("version", "--format", "{{ json . }}")
|
|
|
res.Assert(t, icmd.Expected{Out: `"Client":`})
|
|
|
})
|
|
|
|
|
|
t.Run("delegate version flag", func(t *testing.T) {
|
|
|
- c.RunDocker("context", "create", "example", "test-example")
|
|
|
- c.RunDocker("context", "use", "test-example")
|
|
|
- res := c.RunDocker("-v")
|
|
|
+ c.RunDockerCmd("context", "create", "example", "test-example")
|
|
|
+ c.RunDockerCmd("context", "use", "test-example")
|
|
|
+ res := c.RunDockerCmd("-v")
|
|
|
res.Assert(t, icmd.Expected{Out: "Docker version"})
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func TestMockBackend(t *testing.T) {
|
|
|
c := NewParallelE2eCLI(t, binDir)
|
|
|
- c.RunDocker("context", "create", "example", "test-example")
|
|
|
- res := c.RunDocker("context", "use", "test-example")
|
|
|
+ c.RunDockerCmd("context", "create", "example", "test-example")
|
|
|
+ res := c.RunDockerCmd("context", "use", "test-example")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-example"})
|
|
|
|
|
|
t.Run("use", func(t *testing.T) {
|
|
|
- res := c.RunDocker("context", "show")
|
|
|
+ res := c.RunDockerCmd("context", "show")
|
|
|
res.Assert(t, icmd.Expected{Out: "test-example"})
|
|
|
- res = c.RunDocker("context", "ls")
|
|
|
+ res = c.RunDockerCmd("context", "ls")
|
|
|
golden.Assert(t, res.Stdout(), GoldenFile("ls-out-test-example"))
|
|
|
})
|
|
|
|
|
|
t.Run("ps", func(t *testing.T) {
|
|
|
- res := c.RunDocker("ps")
|
|
|
+ res := c.RunDockerCmd("ps")
|
|
|
golden.Assert(t, res.Stdout(), "ps-out-example.golden")
|
|
|
})
|
|
|
|
|
|
t.Run("ps quiet", func(t *testing.T) {
|
|
|
- res := c.RunDocker("ps", "-q")
|
|
|
+ res := c.RunDockerCmd("ps", "-q")
|
|
|
golden.Assert(t, res.Stdout(), "ps-quiet-out-example.golden")
|
|
|
})
|
|
|
|
|
|
t.Run("ps quiet all", func(t *testing.T) {
|
|
|
- res := c.RunDocker("ps", "-q", "--all")
|
|
|
+ res := c.RunDockerCmd("ps", "-q", "--all")
|
|
|
golden.Assert(t, res.Stdout(), "ps-quiet-all-out-example.golden")
|
|
|
})
|
|
|
|
|
|
t.Run("inspect", func(t *testing.T) {
|
|
|
- res := c.RunDocker("inspect", "id")
|
|
|
+ res := c.RunDockerCmd("inspect", "id")
|
|
|
golden.Assert(t, res.Stdout(), "inspect-id.golden")
|
|
|
})
|
|
|
|
|
|
t.Run("run", func(t *testing.T) {
|
|
|
- res := c.RunDocker("run", "-d", "nginx", "-p", "80:80")
|
|
|
+ res := c.RunDockerCmd("run", "-d", "nginx", "-p", "80:80")
|
|
|
res.Assert(t, icmd.Expected{
|
|
|
Out: `Running container "nginx" with name`,
|
|
|
})
|