From da6334f415e2e6bf8e7e3aec32acb3be6c620fc5 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 21 Aug 2020 17:34:02 +0200 Subject: [PATCH 1/5] Renaming, expect commands to succeed by default (removed a bunch of res.Assert(success) ) Signed-off-by: Guillaume Tardif --- local/e2e/backend_test.go | 25 +++--- tests/aci-e2e/e2e-aci_test.go | 110 +++++++++-------------- tests/e2e/e2e_test.go | 164 +++++++++++++--------------------- tests/ecs-e2e/e2e-ecs_test.go | 36 +++----- tests/framework/e2e.go | 14 ++- 5 files changed, 139 insertions(+), 210 deletions(-) diff --git a/local/e2e/backend_test.go b/local/e2e/backend_test.go index a1cdc4de7..b07aab019 100644 --- a/local/e2e/backend_test.go +++ b/local/e2e/backend_test.go @@ -43,38 +43,33 @@ func TestMain(m *testing.M) { func TestLocalBackend(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success) - c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success) + c.RunDocker( "context", "create", "local", "test-context").Assert(t, icmd.Success) + c.RunDocker("context", "use", "test-context").Assert(t, icmd.Success) t.Run("run", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("run", "-d", "nginx") - res.Assert(t, icmd.Success) + res := c.RunDocker( "run", "-d", "nginx") containerName := strings.TrimSpace(res.Combined()) t.Cleanup(func() { - _ = c.RunDockerCmd("rm", "-f", containerName) + _ = c.RunDockerOrFail("rm", "-f", containerName) }) - res = c.RunDockerCmd("inspect", containerName) + res = c.RunDocker("inspect", containerName) res.Assert(t, icmd.Expected{Out: `"Status": "running"`}) }) t.Run("run with ports", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("run", "-d", "-p", "8080:80", "nginx") - res.Assert(t, icmd.Success) + res := c.RunDocker( "run", "-d", "-p", "8080:80", "nginx") containerName := strings.TrimSpace(res.Combined()) t.Cleanup(func() { - _ = c.RunDockerCmd("rm", "-f", containerName) + _ = c.RunDockerOrFail("rm", "-f", containerName) }) - res = c.RunDockerCmd("inspect", containerName) + res = c.RunDocker( "inspect", containerName) res.Assert(t, icmd.Expected{Out: `"Status": "running"`}) - res = c.RunDockerCmd("ps") + res = c.RunDocker( "ps") res.Assert(t, icmd.Expected{Out: "0.0.0.0:8080->80/tcp"}) }) t.Run("inspect not found", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("inspect", "nonexistentcontainer") + res := c.RunDockerOrFail("inspect", "nonexistentcontainer") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "Error: No such container: nonexistentcontainer", diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 395063b9c..b824d1531 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -87,26 +87,25 @@ func TestLoginLogout(t *testing.T) { _ = deleteResourceGroup(rg) }) - res := c.RunDockerCmd("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) - res.Assert(t, icmd.Success) - res = c.RunDockerCmd("context", "use", contextName) + res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) + res = c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) - res = c.RunDockerCmd("context", "ls") + res = c.RunDocker("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) }) t.Run("delete context", func(t *testing.T) { - res := c.RunDockerCmd("context", "use", "default") + res := c.RunDocker("context", "use", "default") res.Assert(t, icmd.Expected{Out: "default"}) - res = c.RunDockerCmd("context", "rm", contextName) + res = c.RunDocker("context", "rm", contextName) res.Assert(t, icmd.Expected{Out: contextName}) }) t.Run("logout", func(t *testing.T) { _, err := os.Stat(login.GetTokenStorePath()) assert.NilError(t, err) - res := c.RunDockerCmd("logout", "azure") + res := c.RunDocker("logout", "azure") res.Assert(t, icmd.Expected{Out: "Removing login credentials for Azure"}) _, err = os.Stat(login.GetTokenStorePath()) errMsg := "no such file or directory" @@ -117,7 +116,7 @@ func TestLoginLogout(t *testing.T) { }) t.Run("create context fail", func(t *testing.T) { - res := c.RunDockerCmd("context", "create", "aci", "fail-context") + res := c.RunDockerOrFail("context", "create", "aci", "fail-context") res.Assert(t, icmd.Expected{ ExitCode: errdefs.ExitCodeLoginRequired, Err: `not logged in to azure, you need to run "docker login azure" first`, @@ -163,20 +162,18 @@ func TestContainerRun(t *testing.T) { t.Run("run", func(t *testing.T) { mountTarget := "/usr/share/nginx/html" - res := c.RunDockerCmd( + res := c.RunDocker( "run", "-d", "-v", fmt.Sprintf("%s@%s:%s", saName, testShareName, mountTarget), "-p", "80:80", "nginx", ) - res.Assert(t, icmd.Success) container = getContainerName(res.Stdout()) t.Logf("Container name: %q", container) }) t.Run("inspect", func(t *testing.T) { - res := c.RunDockerCmd("inspect", container) - res.Assert(t, icmd.Success) + res := c.RunDocker("inspect", container) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) @@ -191,8 +188,7 @@ func TestContainerRun(t *testing.T) { }) t.Run("ps", func(t *testing.T) { - res := c.RunDockerCmd("ps") - res.Assert(t, icmd.Success) + res := c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") l := out[len(out)-1] assert.Assert(t, strings.Contains(l, container), "Looking for %q in line: %s", container, l) @@ -211,15 +207,15 @@ func TestContainerRun(t *testing.T) { }) t.Run("logs", func(t *testing.T) { - res := c.RunDockerCmd("logs", container) + res := c.RunDocker("logs", container) res.Assert(t, icmd.Expected{Out: "GET"}) }) t.Run("exec", func(t *testing.T) { - res := c.RunDockerCmd("exec", container, "pwd") + res := c.RunDocker("exec", container, "pwd") res.Assert(t, icmd.Expected{Out: "/"}) - res = c.RunDockerCmd("exec", container, "echo", "fail_with_argument") + res = c.RunDockerOrFail("exec", container, "echo", "fail_with_argument") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "ACI exec command does not accept arguments to the command. Only the binary should be specified", @@ -266,7 +262,7 @@ func TestContainerRun(t *testing.T) { }) t.Run("rm a running container", func(t *testing.T) { - res := c.RunDockerCmd("rm", container) + res := c.RunDockerOrFail("rm", container) res.Assert(t, icmd.Expected{ Err: fmt.Sprintf("Error: you cannot remove a running container %s. Stop the container before attempting removal or force remove", container), ExitCode: 1, @@ -274,14 +270,11 @@ func TestContainerRun(t *testing.T) { }) t.Run("force rm", func(t *testing.T) { - res := c.RunDockerCmd("rm", "-f", container) - res.Assert(t, icmd.Expected{ - Out: container, - ExitCode: 0, - }) + res := c.RunDocker("rm", "-f", container) + res.Assert(t, icmd.Expected{Out: container}) checkStopped := func(t poll.LogT) poll.Result { - res := c.RunDockerCmd("inspect", container) + res := c.RunDockerOrFail("inspect", container) if res.ExitCode == 1 { return poll.Success() } @@ -315,7 +308,7 @@ func TestContainerRunAttached(t *testing.T) { runRes := icmd.StartCmd(cmd) checkRunning := func(t poll.LogT) poll.Result { - res := c.RunDockerCmd("inspect", container) + res := c.RunDockerOrFail("inspect", container) if res.ExitCode == 0 { return poll.Success() } @@ -323,8 +316,7 @@ func TestContainerRunAttached(t *testing.T) { } poll.WaitOn(t, checkRunning, poll.WithDelay(5*time.Second), poll.WithTimeout(60*time.Second)) - inspectRes := c.RunDockerCmd("inspect", container) - inspectRes.Assert(t, icmd.Success) + inspectRes := c.RunDocker("inspect", container) containerInspect, err := ParseContainerInspect(inspectRes.Stdout()) assert.NilError(t, err) @@ -361,7 +353,7 @@ func TestContainerRunAttached(t *testing.T) { }) t.Run("stop wrong container", func(t *testing.T) { - res := c.RunDockerCmd("stop", "unknown-container") + res := c.RunDockerOrFail("stop", "unknown-container") res.Assert(t, icmd.Expected{ Err: "Error: container unknown-container not found", ExitCode: 1, @@ -369,34 +361,32 @@ func TestContainerRunAttached(t *testing.T) { }) t.Run("stop container", func(t *testing.T) { - res := c.RunDockerCmd("stop", container) + res := c.RunDocker("stop", container) res.Assert(t, icmd.Expected{Out: container}) }) t.Run("ps stopped container with --all", func(t *testing.T) { - res := c.RunDockerCmd("ps", container) - res.Assert(t, icmd.Success) + res := c.RunDocker("ps", container) out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Assert(t, is.Len(out, 1)) - res = c.RunDockerCmd("ps", "--all", container) - res.Assert(t, icmd.Success) + res = c.RunDocker("ps", "--all", container) out = strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Assert(t, is.Len(out, 2)) }) t.Run("start container", func(t *testing.T) { - res := c.RunDockerCmd("start", container) + res := c.RunDocker("start", container) res.Assert(t, icmd.Expected{Out: container}) waitForStatus(t, c, container, "Running") }) t.Run("rm stopped container", func(t *testing.T) { - res := c.RunDockerCmd("stop", container) + res := c.RunDocker("stop", container) res.Assert(t, icmd.Expected{Out: container}) waitForStatus(t, c, container, "Terminated", "Node Stopped") - res = c.RunDockerCmd("rm", container) + res = c.RunDocker("rm", container) res.Assert(t, icmd.Expected{Out: container}) }) } @@ -415,11 +405,9 @@ func TestCompose(t *testing.T) { t.Run("compose up", func(t *testing.T) { // Name of Compose project is taken from current folder "acie2e" - res := c.RunDockerCmd("compose", "up", "-f", composeFile) - res.Assert(t, icmd.Success) + res := c.RunDocker("compose", "up", "-f", composeFile) - res = c.RunDockerCmd("ps") - res.Assert(t, icmd.Success) + res = c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") // Check three containers are running assert.Assert(t, is.Len(out, 4)) @@ -432,8 +420,7 @@ func TestCompose(t *testing.T) { } assert.Assert(t, webRunning, "web container not running") - res = c.RunDockerCmd("inspect", serverContainer) - res.Assert(t, icmd.Success) + res = c.RunDocker("inspect", serverContainer) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) @@ -450,23 +437,20 @@ func TestCompose(t *testing.T) { }) t.Run("logs web", func(t *testing.T) { - res := c.RunDockerCmd("logs", serverContainer) + res := c.RunDocker("logs", serverContainer) res.Assert(t, icmd.Expected{Out: "Listening on port 80"}) }) t.Run("update", func(t *testing.T) { - res := c.RunDockerCmd("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) - res.Assert(t, icmd.Success) + res := c.RunDocker("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) - res = c.RunDockerCmd("ps") - res.Assert(t, icmd.Success) + res = c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") // Check three containers are running assert.Assert(t, is.Len(out, 4)) for _, cName := range []string{serverContainer, wordsContainer} { - res = c.RunDockerCmd("inspect", cName) - res.Assert(t, icmd.Success) + res = c.RunDocker("inspect", cName) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) @@ -493,7 +477,7 @@ func TestCompose(t *testing.T) { } poll.WaitOn(t, checkUp, poll.WithDelay(1*time.Second), poll.WithTimeout(60*time.Second)) - res = c.RunDockerCmd("ps") + res = c.RunDocker("ps") p := containerInspect.Ports[0] res.Assert(t, icmd.Expected{ Out: fmt.Sprintf("%s:%d->%d/tcp", p.HostIP, p.HostPort, p.ContainerPort), @@ -502,11 +486,9 @@ func TestCompose(t *testing.T) { }) t.Run("down", func(t *testing.T) { - res := c.RunDockerCmd("compose", "down", "--project-name", composeProjectName) - res.Assert(t, icmd.Success) + res := c.RunDocker("compose", "down", "--project-name", composeProjectName) - res = c.RunDockerCmd("ps") - res.Assert(t, icmd.Success) + res = c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Equal(t, len(out), 1) }) @@ -532,15 +514,14 @@ func TestRunEnvVars(t *testing.T) { container := strings.TrimSpace(out[len(out)-1]) t.Logf("Container name: %q", container) - res = c.RunDockerCmd("inspect", container) - res.Assert(t, icmd.Success) + res = c.RunDocker("inspect", container) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) assert.Equal(t, containerInspect.Image, "mysql:5.7") check := func(t poll.LogT) poll.Result { - res := c.RunDockerCmd("logs", container) + res := c.RunDockerOrFail("logs", container) if strings.Contains(res.Stdout(), "Giving user user1 access to schema mytestdb") { return poll.Success() } @@ -565,8 +546,7 @@ func setupTestResourceGroup(t *testing.T, c *E2eCLI, tName string) (string, stri }) createAciContextAndUseIt(t, c, sID, rg) // Check nothing is running - res := c.RunDockerCmd("ps") - res.Assert(t, icmd.Success) + res := c.RunDocker("ps") assert.Assert(t, is.Len(strings.Split(strings.TrimSpace(res.Stdout()), "\n"), 1)) return sID, rg } @@ -593,8 +573,7 @@ func azureLogin(t *testing.T, c *E2eCLI) { assert.Check(t, clientID != "", "AZURE_CLIENT_ID must not be empty") assert.Check(t, clientSecret != "", "AZURE_CLIENT_SECRET must not be empty") assert.Check(t, tenantID != "", "AZURE_TENANT_ID must not be empty") - res := c.RunDockerCmd("login", "azure", "--client-id", clientID, "--client-secret", clientSecret, "--tenant-id", tenantID) - res.Assert(t, icmd.Success) + c.RunDocker("login", "azure", "--client-id", clientID, "--client-secret", clientSecret, "--tenant-id", tenantID) } func getSubscriptionID(t *testing.T) string { @@ -614,11 +593,10 @@ func createResourceGroup(sID, rgName string) error { func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) { t.Log("Create ACI context") - res := c.RunDockerCmd("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) - res.Assert(t, icmd.Success) - res = c.RunDockerCmd("context", "use", contextName) + res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) + res = c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) - res = c.RunDockerCmd("context", "ls") + res = c.RunDocker("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) } @@ -669,7 +647,7 @@ func getContainerName(stdout string) string { func waitForStatus(t *testing.T, c *E2eCLI, containerID string, statuses ...string) { checkStopped := func(logt poll.LogT) poll.Result { - res := c.RunDockerCmd("inspect", containerID) + res := c.RunDocker("inspect", containerID) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) for _, status := range statuses { diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 0eccc3456..96d58f2c5 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -49,9 +49,9 @@ func TestMain(m *testing.M) { func TestComposeNotImplemented(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - res := c.RunDockerCmd("context", "show") + res := c.RunDocker("context", "show") res.Assert(t, icmd.Expected{Out: "default"}) - res = c.RunDockerCmd("compose", "up") + res = c.RunDockerOrFail("compose", "up") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: `Command "compose up" not available in current context (default)`, @@ -62,67 +62,58 @@ func TestContextDefault(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("show", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "show") + res := c.RunDocker("context", "show") res.Assert(t, icmd.Expected{Out: "default"}) }) t.Run("ls", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "ls") - res.Assert(t, icmd.Success) + res := c.RunDocker("context", "ls") golden.Assert(t, res.Stdout(), GoldenFile("ls-out-default")) }) t.Run("inspect", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "inspect", "default") + res := c.RunDocker("context", "inspect", "default") res.Assert(t, icmd.Expected{Out: `"Name": "default"`}) }) t.Run("inspect current", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "inspect") + res := c.RunDocker("context", "inspect") res.Assert(t, icmd.Expected{Out: `"Name": "default"`}) }) } func TestContextCreateDocker(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - res := c.RunDockerCmd("context", "create", "test-docker", "--from", "default") + res := c.RunDocker("context", "create", "test-docker", "--from", "default") res.Assert(t, icmd.Expected{Out: "test-docker"}) t.Run("ls", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "ls") - res.Assert(t, icmd.Success) + res := c.RunDocker("context", "ls") golden.Assert(t, res.Stdout(), GoldenFile("ls-out-test-docker")) }) t.Run("ls quiet", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "ls", "-q") + res := c.RunDocker("context", "ls", "-q") golden.Assert(t, res.Stdout(), "ls-out-test-docker-quiet.golden") }) t.Run("ls format", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "ls", "--format", "{{ json . }}") + res := c.RunDocker("context", "ls", "--format", "{{ json . }}") res.Assert(t, icmd.Expected{Out: `"Name":"default"`}) }) } func TestContextInspect(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - res := c.RunDockerCmd("context", "create", "test-docker", "--from", "default") + res := c.RunDocker("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.RunDockerCmd("context", "use", "test-docker") + res := c.RunDocker("context", "use", "test-docker") res.Assert(t, icmd.Expected{Out: "test-docker"}) - res = c.RunDockerCmd("context", "inspect") + res = c.RunDocker("context", "inspect") res.Assert(t, icmd.Expected{Out: `"Name": "test-docker"`}) }) } @@ -131,8 +122,7 @@ func TestContextHelpACI(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("help", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "create", "aci", "--help") + res := c.RunDocker("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"}) @@ -141,8 +131,7 @@ func TestContextHelpACI(t *testing.T) { }) t.Run("check exec", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "create", "aci", "--subscription-id", "invalid-id") + res := c.RunDockerOrFail("context", "create", "aci", "--subscription-id", "invalid-id") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "accepts 1 arg(s), received 0", @@ -154,8 +143,8 @@ func TestContextHelpACI(t *testing.T) { func TestContextDuplicateACI(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "mycontext", "--from", "default").Assert(t, icmd.Success) - res := c.RunDockerCmd("context", "create", "aci", "mycontext") + c.RunDocker("context", "create", "mycontext", "--from", "default") + res := c.RunDockerOrFail("context", "create", "aci", "mycontext") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "context mycontext: already exists", @@ -167,10 +156,10 @@ func TestContextRemove(t *testing.T) { t.Run("remove current", func(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "test-context-rm", "--from", "default").Assert(t, icmd.Success) - res := c.RunDockerCmd("context", "use", "test-context-rm") + c.RunDocker("context", "create", "test-context-rm", "--from", "default") + res := c.RunDocker("context", "use", "test-context-rm") res.Assert(t, icmd.Expected{Out: "test-context-rm"}) - res = c.RunDockerCmd("context", "rm", "test-context-rm") + res = c.RunDockerOrFail("context", "rm", "test-context-rm") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "cannot delete current context", @@ -180,11 +169,11 @@ func TestContextRemove(t *testing.T) { t.Run("force remove current", func(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "test-context-rmf").Assert(t, icmd.Success) - c.RunDockerCmd("context", "use", "test-context-rmf").Assert(t, icmd.Success) - res := c.RunDockerCmd("context", "rm", "-f", "test-context-rmf") + c.RunDocker("context", "create", "test-context-rmf") + c.RunDocker("context", "use", "test-context-rmf") + res := c.RunDocker("context", "rm", "-f", "test-context-rmf") res.Assert(t, icmd.Expected{Out: "test-context-rmf"}) - res = c.RunDockerCmd("context", "ls") + res = c.RunDocker("context", "ls") res.Assert(t, icmd.Expected{Out: "default *"}) }) } @@ -195,8 +184,7 @@ func TestLoginCommandDelegation(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("default context", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("login", "-u", "nouser", "-p", "wrongpasword") + res := c.RunDockerOrFail("login", "-u", "nouser", "-p", "wrongpasword") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "unauthorized: incorrect username or password", @@ -204,8 +192,7 @@ func TestLoginCommandDelegation(t *testing.T) { }) t.Run("interactive", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("login", "someregistry.docker.io") + res := c.RunDockerOrFail("login", "someregistry.docker.io") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "Cannot perform an interactive login from a non TTY device", @@ -213,16 +200,14 @@ func TestLoginCommandDelegation(t *testing.T) { }) t.Run("logout", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("logout", "someregistry.docker.io") + res := c.RunDocker("logout", "someregistry.docker.io") res.Assert(t, icmd.Expected{Out: "someregistry.docker.io"}) }) t.Run("existing context", func(t *testing.T) { - c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "local", "local").Assert(t, icmd.Success) - c.RunDockerCmd("context", "use", "local").Assert(t, icmd.Success) - res := c.RunDockerCmd("login", "-u", "nouser", "-p", "wrongpasword") + c.RunDocker("context", "create", "local", "local") + c.RunDocker("context", "use", "local") + res := c.RunDockerOrFail("login", "-u", "nouser", "-p", "wrongpasword") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "unauthorized: incorrect username or password", @@ -234,8 +219,7 @@ func TestCloudLogin(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("unknown backend", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("login", "mycloudbackend") + res := c.RunDockerOrFail("login", "mycloudbackend") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "unknown backend type for cloud login: mycloudbackend", @@ -282,14 +266,12 @@ func TestLegacy(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("help", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("--help") + res := c.RunDocker("--help") res.Assert(t, icmd.Expected{Out: "swarm"}) }) t.Run("swarm", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("swarm", "join") + res := c.RunDockerOrFail("swarm", "join") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: `"docker swarm join" requires exactly 1 argument.`, @@ -297,7 +279,6 @@ func TestLegacy(t *testing.T) { }) t.Run("local run", func(t *testing.T) { - t.Parallel() cmd := c.NewDockerCmd("run", "--rm", "hello-world") cmd.Timeout = 40 * time.Second res := icmd.RunCmd(cmd) @@ -305,8 +286,7 @@ func TestLegacy(t *testing.T) { }) t.Run("error messages", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("foo") + res := c.RunDockerOrFail("foo") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "docker: 'foo' is not a docker command.", @@ -314,12 +294,11 @@ func TestLegacy(t *testing.T) { }) t.Run("host flag", func(t *testing.T) { - t.Parallel() stderr := "Cannot connect to the Docker daemon at tcp://localhost:123" if runtime.GOOS == "windows" { stderr = "error during connect: Get http://localhost:123" } - res := c.RunDockerCmd("-H", "tcp://localhost:123", "version") + res := c.RunDockerOrFail("-H", "tcp://localhost:123", "version") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: stderr, @@ -327,10 +306,9 @@ func TestLegacy(t *testing.T) { }) t.Run("existing contexts delegate", func(t *testing.T) { - c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "moby-ctx", "--from=default").Assert(t, icmd.Success) - c.RunDockerCmd("context", "use", "moby-ctx").Assert(t, icmd.Success) - res := c.RunDockerCmd("swarm", "join") + c.RunDocker("context", "create", "moby-ctx", "--from=default") + c.RunDocker("context", "use", "moby-ctx") + res := c.RunDockerOrFail("swarm", "join") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: `"docker swarm join" requires exactly 1 argument.`, @@ -338,15 +316,13 @@ func TestLegacy(t *testing.T) { }) t.Run("host flag overrides context", func(t *testing.T) { - c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "example", "test-example").Assert(t, icmd.Success) - c.RunDockerCmd("context", "use", "test-example").Assert(t, icmd.Success) + c.RunDocker("context", "create", "example", "test-example") + c.RunDocker("context", "use", "test-example") endpoint := "unix:///var/run/docker.sock" if runtime.GOOS == "windows" { endpoint = "npipe:////./pipe/docker_engine" } - res := c.RunDockerCmd("-H", endpoint, "ps") - res.Assert(t, icmd.Success) + res := c.RunDocker("-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")) @@ -357,8 +333,7 @@ func TestLegacyLogin(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("host flag login", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("-H", "tcp://localhost:123", "login", "-u", "nouser", "-p", "wrongpasword") + res := c.RunDockerOrFail("-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.", @@ -366,8 +341,7 @@ func TestLegacyLogin(t *testing.T) { }) t.Run("log level flag login", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("--log-level", "debug", "login", "-u", "nouser", "-p", "wrongpasword") + res := c.RunDockerOrFail("--log-level", "debug", "login", "-u", "nouser", "-p", "wrongpasword") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "WARNING! Using --password via the CLI is insecure", @@ -375,9 +349,7 @@ func TestLegacyLogin(t *testing.T) { }) t.Run("login help global flags", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("login", "--help") - res.Assert(t, icmd.Success) + res := c.RunDocker("login", "--help") assert.Assert(t, !strings.Contains(res.Combined(), "--log-level")) }) } @@ -385,9 +357,8 @@ func TestLegacyLogin(t *testing.T) { func TestUnsupportedCommand(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - res := c.RunDockerCmd("context", "create", "example", "test-example") - res.Assert(t, icmd.Success) - res = c.RunDockerCmd("--context", "test-example", "images") + res := c.RunDocker("context", "create", "example", "test-example") + res = c.RunDockerOrFail("--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`, @@ -398,73 +369,60 @@ func TestVersion(t *testing.T) { c := NewParallelE2eCLI(t, binDir) t.Run("azure version", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("version") + res := c.RunDocker("version") res.Assert(t, icmd.Expected{Out: "Azure integration"}) }) t.Run("format", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("version", "-f", "{{ json . }}") + res := c.RunDocker("version", "-f", "{{ json . }}") res.Assert(t, icmd.Expected{Out: `"Client":`}) - res = c.RunDockerCmd("version", "--format", "{{ json . }}") + res = c.RunDocker("version", "--format", "{{ json . }}") res.Assert(t, icmd.Expected{Out: `"Client":`}) }) t.Run("delegate version flag", func(t *testing.T) { - c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "example", "test-example").Assert(t, icmd.Success) - c.RunDockerCmd("context", "use", "test-example").Assert(t, icmd.Success) - res := c.RunDockerCmd("-v") + c.RunDocker("context", "create", "example", "test-example") + c.RunDocker("context", "use", "test-example") + res := c.RunDocker("-v") res.Assert(t, icmd.Expected{Out: "Docker version"}) }) } func TestMockBackend(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDockerCmd("context", "create", "example", "test-example").Assert(t, icmd.Success) - res := c.RunDockerCmd("context", "use", "test-example") + c.RunDocker("context", "create", "example", "test-example") + res := c.RunDocker("context", "use", "test-example") res.Assert(t, icmd.Expected{Out: "test-example"}) t.Run("use", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("context", "show") + res := c.RunDocker("context", "show") res.Assert(t, icmd.Expected{Out: "test-example"}) - res = c.RunDockerCmd("context", "ls") + res = c.RunDocker("context", "ls") golden.Assert(t, res.Stdout(), GoldenFile("ls-out-test-example")) }) t.Run("ps", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("ps") - res.Assert(t, icmd.Success) + res := c.RunDocker("ps") golden.Assert(t, res.Stdout(), "ps-out-example.golden") }) t.Run("ps quiet", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("ps", "-q") - res.Assert(t, icmd.Success) + res := c.RunDocker("ps", "-q") golden.Assert(t, res.Stdout(), "ps-quiet-out-example.golden") }) t.Run("ps quiet all", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("ps", "-q", "--all") - res.Assert(t, icmd.Success) + res := c.RunDocker("ps", "-q", "--all") golden.Assert(t, res.Stdout(), "ps-quiet-all-out-example.golden") }) t.Run("inspect", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("inspect", "id") - res.Assert(t, icmd.Success) + res := c.RunDocker("inspect", "id") golden.Assert(t, res.Stdout(), "inspect-id.golden") }) t.Run("run", func(t *testing.T) { - t.Parallel() - res := c.RunDockerCmd("run", "-d", "nginx", "-p", "80:80") + res := c.RunDocker("run", "-d", "nginx", "-p", "80:80") res.Assert(t, icmd.Expected{ Out: `Running container "nginx" with name`, }) diff --git a/tests/ecs-e2e/e2e-ecs_test.go b/tests/ecs-e2e/e2e-ecs_test.go index 4d3e6ab85..99716a647 100644 --- a/tests/ecs-e2e/e2e-ecs_test.go +++ b/tests/ecs-e2e/e2e-ecs_test.go @@ -49,35 +49,30 @@ func TestMain(m *testing.M) { } func TestSecrets(t *testing.T) { - c, testID := setupTest(t) + cmd, testID := setupTest(t) secretName := "secret" + testID description := "description " + testID t.Run("create secret", func(t *testing.T) { - res := c.RunDockerCmd("secret", "create", secretName, "-u", "user1", "-p", "pass1", "-d", description) - res.Assert(t, icmd.Success) + res := cmd.RunDocker("secret", "create", secretName, "-u", "user1", "-p", "pass1", "-d", description) assert.Check(t, strings.Contains(res.Stdout(), "secret:"+secretName)) }) t.Run("list secrets", func(t *testing.T) { - res := c.RunDockerCmd("secret", "list") - res.Assert(t, icmd.Success) + res := cmd.RunDocker("secret", "list") assert.Check(t, strings.Contains(res.Stdout(), secretName)) assert.Check(t, strings.Contains(res.Stdout(), description)) }) t.Run("inspect secret", func(t *testing.T) { - res := c.RunDockerCmd("secret", "inspect", secretName) - res.Assert(t, icmd.Success) + res := cmd.RunDocker("secret", "inspect", secretName) assert.Check(t, strings.Contains(res.Stdout(), `"Name": "`+secretName+`"`)) assert.Check(t, strings.Contains(res.Stdout(), `"Description": "`+description+`"`)) }) t.Run("rm secret", func(t *testing.T) { - res := c.RunDockerCmd("secret", "rm", secretName) - res.Assert(t, icmd.Success) - res = c.RunDockerCmd("secret", "list") - res.Assert(t, icmd.Success) + res := cmd.RunDocker("secret", "rm", secretName) + res = cmd.RunDocker("secret", "list") assert.Check(t, !strings.Contains(res.Stdout(), secretName)) }) } @@ -86,14 +81,12 @@ func TestCompose(t *testing.T) { c, stack := setupTest(t) t.Run("compose up", func(t *testing.T) { - res := c.RunDockerCmd("compose", "up", "--project-name", stack, "-f", "../composefiles/nginx.yaml") - res.Assert(t, icmd.Success) + c.RunDocker("compose", "up", "--project-name", stack, "-f", "../composefiles/nginx.yaml") }) var url string t.Run("compose ps", func(t *testing.T) { - res := c.RunDockerCmd("compose", "ps", "--project-name", stack) - res.Assert(t, icmd.Success) + res := c.RunDocker("compose", "ps", "--project-name", stack) lines := strings.Split(res.Stdout(), "\n") assert.Equal(t, 3, len(lines)) @@ -124,8 +117,7 @@ func TestCompose(t *testing.T) { }) t.Run("compose down", func(t *testing.T) { - res := c.RunDockerCmd("compose", "down", "--project-name", stack, "-f", "../composefiles/nginx.yaml") - res.Assert(t, icmd.Success) + c.RunDocker("compose", "down", "--project-name", stack, "-f", "../composefiles/nginx.yaml") }) } @@ -140,8 +132,7 @@ func setupTest(t *testing.T) (*E2eCLI, string) { if localTestProfile != "" { region := os.Getenv("TEST_AWS_REGION") assert.Check(t, region != "") - res = c.RunDockerCmd("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) - res.Assert(t, icmd.Success) + res = c.RunDocker("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) } else { profile := contextName region := os.Getenv("AWS_DEFAULT_REGION") @@ -150,12 +141,11 @@ func setupTest(t *testing.T) (*E2eCLI, string) { assert.Check(t, keyID != "") assert.Check(t, secretKey != "") assert.Check(t, region != "") - res = c.RunDockerCmd("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) - res.Assert(t, icmd.Success) + res = c.RunDocker("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) } - res = c.RunDockerCmd("context", "use", contextName) + res = c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) - res = c.RunDockerCmd("context", "ls") + res = c.RunDocker("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) }) return c, stack diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index a5d4a50f3..eb082a220 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -51,6 +51,7 @@ func init() { type E2eCLI struct { BinDir string ConfigDir string + test *testing.T } // NewParallelE2eCLI returns a configured TestE2eCLI with t.Parallel() set @@ -80,7 +81,7 @@ func newE2eCLI(t *testing.T, binDir string) *E2eCLI { _ = os.RemoveAll(d) }) - return &E2eCLI{binDir, d} + return &E2eCLI{binDir, d, t} } func dirContents(dir string) []string { @@ -158,11 +159,18 @@ func (c *E2eCLI) NewDockerCmd(args ...string) icmd.Cmd { return c.NewCmd(filepath.Join(c.BinDir, DockerExecutableName), args...) } -// RunDockerCmd runs a docker command and returns a result -func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result { +// RunDockerOrFail runs a docker command and returns a result +func (c *E2eCLI) RunDockerOrFail(args ...string) *icmd.Result { return icmd.RunCmd(c.NewDockerCmd(args...)) } +// RunDocker runs a docker command, expects no error and returns a result +func (c *E2eCLI) RunDocker(args ...string) *icmd.Result { + res := c.RunDockerOrFail(args...) + res.Assert(c.test, icmd.Success) + return res +} + // GoldenFile golden file specific to platform func GoldenFile(name string) string { if runtime.GOOS == "windows" { From 30884ad91a9e57e40e3336bf2a80da405b614900 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 21 Aug 2020 18:39:25 +0200 Subject: [PATCH 2/5] Display executed commands (prefixed with test name for readable logs in // runs) Signed-off-by: Guillaume Tardif --- tests/aci-e2e/e2e-aci_test.go | 10 ---------- tests/framework/e2e.go | 3 +++ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index b824d1531..9c3e6ac2a 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -169,7 +169,6 @@ func TestContainerRun(t *testing.T) { "nginx", ) container = getContainerName(res.Stdout()) - t.Logf("Container name: %q", container) }) t.Run("inspect", func(t *testing.T) { @@ -184,7 +183,6 @@ func TestContainerRun(t *testing.T) { assert.Assert(t, is.Len(containerInspect.Ports, 1)) hostIP = containerInspect.Ports[0].HostIP endpoint = fmt.Sprintf("http://%s:%d", containerInspect.Ports[0].HostIP, containerInspect.Ports[0].HostPort) - t.Logf("Endpoint: %s", endpoint) }) t.Run("ps", func(t *testing.T) { @@ -331,7 +329,6 @@ func TestContainerRunAttached(t *testing.T) { assert.Equal(t, port.ContainerPort, uint32(80)) assert.Equal(t, port.HostPort, uint32(80)) endpoint = fmt.Sprintf("http://%s:%d", port.HostIP, port.HostPort) - t.Logf("Endpoint: %s", endpoint) assert.Assert(t, !strings.Contains(runRes.Stdout(), "/test")) checkRequest := func(t poll.LogT) poll.Result { @@ -426,7 +423,6 @@ func TestCompose(t *testing.T) { assert.NilError(t, err) assert.Assert(t, is.Len(containerInspect.Ports, 1)) endpoint := fmt.Sprintf("http://%s:%d", containerInspect.Ports[0].HostIP, containerInspect.Ports[0].HostPort) - t.Logf("Endpoint: %s", endpoint) r, err := http.Get(endpoint + "/words/noun") assert.NilError(t, err) @@ -456,7 +452,6 @@ func TestCompose(t *testing.T) { assert.NilError(t, err) assert.Assert(t, is.Len(containerInspect.Ports, 1)) endpoint := fmt.Sprintf("http://%s:%d", containerInspect.Ports[0].HostIP, containerInspect.Ports[0].HostPort) - t.Logf("Endpoint: %s", endpoint) var route string switch cName { case serverContainer: @@ -512,7 +507,6 @@ func TestRunEnvVars(t *testing.T) { res.Assert(t, icmd.Success) out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") container := strings.TrimSpace(out[len(out)-1]) - t.Logf("Container name: %q", container) res = c.RunDocker("inspect", container) @@ -536,7 +530,6 @@ func setupTestResourceGroup(t *testing.T, c *E2eCLI, tName string) (string, stri rg := "E2E-" + tName + "-" + startTime azureLogin(t, c) sID := getSubscriptionID(t) - t.Logf("Create resource group %q", rg) err := createResourceGroup(sID, rg) assert.Check(t, is.Nil(err)) t.Cleanup(func() { @@ -565,7 +558,6 @@ func deleteResourceGroup(rgName string) error { } func azureLogin(t *testing.T, c *E2eCLI) { - t.Log("Log in to Azure") // in order to create new service principal and get these 3 values : `az ad sp create-for-rbac --name 'TestServicePrincipal' --sdk-auth` clientID := os.Getenv("AZURE_CLIENT_ID") clientSecret := os.Getenv("AZURE_CLIENT_SECRET") @@ -592,7 +584,6 @@ func createResourceGroup(sID, rgName string) error { } func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) { - t.Log("Create ACI context") res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) res = c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) @@ -601,7 +592,6 @@ func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) { } func createStorageAccount(t *testing.T, aciContext store.AciContext, name string) (azure_storage.Account, func() error) { - t.Logf("Create storage account %q", name) account, err := storage.CreateStorageAccount(context.TODO(), aciContext, name) assert.Check(t, is.Nil(err)) assert.Check(t, is.Equal(*(account.Name), name)) diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index eb082a220..2d56892c9 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -20,11 +20,13 @@ import ( "bytes" "encoding/json" "errors" + "fmt" "io/ioutil" "os" "os/exec" "path/filepath" "runtime" + "strings" "testing" "gotest.tools/v3/assert" @@ -161,6 +163,7 @@ func (c *E2eCLI) NewDockerCmd(args ...string) icmd.Cmd { // RunDockerOrFail runs a docker command and returns a result func (c *E2eCLI) RunDockerOrFail(args ...string) *icmd.Result { + fmt.Printf(" [%s] docker %s\n", c.test.Name() , strings.Join(args, " ") ) return icmd.RunCmd(c.NewDockerCmd(args...)) } From 7204692e3acc91f60b151b6f0d2ac81584ba446b Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 21 Aug 2020 18:43:55 +0200 Subject: [PATCH 3/5] Use test name instead of arbitrary string that needs to be different for each test Signed-off-by: Guillaume Tardif --- tests/aci-e2e/e2e-aci_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 9c3e6ac2a..7de7a4606 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -126,7 +126,7 @@ func TestLoginLogout(t *testing.T) { func TestContainerRun(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - sID, rg := setupTestResourceGroup(t, c, "run") + sID, rg := setupTestResourceGroup(t, c) const ( testShareName = "dockertestshare" @@ -284,7 +284,7 @@ func TestContainerRun(t *testing.T) { func TestContainerRunAttached(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - _, _ = setupTestResourceGroup(t, c, "runA") + _, _ = setupTestResourceGroup(t, c) // Used in subtests var ( @@ -390,7 +390,7 @@ func TestContainerRunAttached(t *testing.T) { func TestCompose(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - _, _ = setupTestResourceGroup(t, c, "compose") + _, _ = setupTestResourceGroup(t, c) const ( composeFile = "../composefiles/aci-demo/aci_demo_port.yaml" @@ -491,7 +491,7 @@ func TestCompose(t *testing.T) { func TestRunEnvVars(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - _, _ = setupTestResourceGroup(t, c, "runEnv") + _, _ = setupTestResourceGroup(t, c) t.Run("run", func(t *testing.T) { cmd := c.NewDockerCmd( @@ -525,9 +525,9 @@ func TestRunEnvVars(t *testing.T) { }) } -func setupTestResourceGroup(t *testing.T, c *E2eCLI, tName string) (string, string) { +func setupTestResourceGroup(t *testing.T, c *E2eCLI) (string, string) { startTime := strconv.Itoa(int(time.Now().Unix())) - rg := "E2E-" + tName + "-" + startTime + rg := "E2E-" + t.Name() + "-" + startTime azureLogin(t, c) sID := getSubscriptionID(t) err := createResourceGroup(sID, rg) From 2bac8cf94e3359915948bfd464f499dbe00974e1 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 21 Aug 2020 18:52:07 +0200 Subject: [PATCH 4/5] Fix linter Signed-off-by: Guillaume Tardif --- local/e2e/backend_test.go | 10 +++++----- tests/aci-e2e/e2e-aci_test.go | 23 ++++++++++------------- tests/e2e/e2e_test.go | 4 ++-- tests/ecs-e2e/e2e-ecs_test.go | 8 ++++---- tests/framework/e2e.go | 4 ++-- 5 files changed, 23 insertions(+), 26 deletions(-) diff --git a/local/e2e/backend_test.go b/local/e2e/backend_test.go index b07aab019..2d77d357d 100644 --- a/local/e2e/backend_test.go +++ b/local/e2e/backend_test.go @@ -43,11 +43,11 @@ func TestMain(m *testing.M) { func TestLocalBackend(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDocker( "context", "create", "local", "test-context").Assert(t, icmd.Success) + c.RunDocker("context", "create", "local", "test-context").Assert(t, icmd.Success) c.RunDocker("context", "use", "test-context").Assert(t, icmd.Success) t.Run("run", func(t *testing.T) { - res := c.RunDocker( "run", "-d", "nginx") + res := c.RunDocker("run", "-d", "nginx") containerName := strings.TrimSpace(res.Combined()) t.Cleanup(func() { _ = c.RunDockerOrFail("rm", "-f", containerName) @@ -57,14 +57,14 @@ func TestLocalBackend(t *testing.T) { }) t.Run("run with ports", func(t *testing.T) { - res := c.RunDocker( "run", "-d", "-p", "8080:80", "nginx") + res := c.RunDocker("run", "-d", "-p", "8080:80", "nginx") containerName := strings.TrimSpace(res.Combined()) t.Cleanup(func() { _ = c.RunDockerOrFail("rm", "-f", containerName) }) - res = c.RunDocker( "inspect", containerName) + res = c.RunDocker("inspect", containerName) res.Assert(t, icmd.Expected{Out: `"Status": "running"`}) - res = c.RunDocker( "ps") + res = c.RunDocker("ps") res.Assert(t, icmd.Expected{Out: "0.0.0.0:8080->80/tcp"}) }) diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 7de7a4606..126f2ec20 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -87,8 +87,8 @@ func TestLoginLogout(t *testing.T) { _ = deleteResourceGroup(rg) }) - res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) - res = c.RunDocker("context", "use", contextName) + c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) + res := c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) res = c.RunDocker("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) @@ -402,9 +402,8 @@ func TestCompose(t *testing.T) { t.Run("compose up", func(t *testing.T) { // Name of Compose project is taken from current folder "acie2e" - res := c.RunDocker("compose", "up", "-f", composeFile) - - res = c.RunDocker("ps") + c.RunDocker("compose", "up", "-f", composeFile) + res := c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") // Check three containers are running assert.Assert(t, is.Len(out, 4)) @@ -438,9 +437,8 @@ func TestCompose(t *testing.T) { }) t.Run("update", func(t *testing.T) { - res := c.RunDocker("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) - - res = c.RunDocker("ps") + c.RunDocker("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) + res := c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") // Check three containers are running assert.Assert(t, is.Len(out, 4)) @@ -481,9 +479,8 @@ func TestCompose(t *testing.T) { }) t.Run("down", func(t *testing.T) { - res := c.RunDocker("compose", "down", "--project-name", composeProjectName) - - res = c.RunDocker("ps") + c.RunDocker("compose", "down", "--project-name", composeProjectName) + res := c.RunDocker("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Equal(t, len(out), 1) }) @@ -584,8 +581,8 @@ func createResourceGroup(sID, rgName string) error { } func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) { - res := c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) - res = c.RunDocker("context", "use", contextName) + c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) + res := c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) res = c.RunDocker("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 96d58f2c5..256365545 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -357,8 +357,8 @@ func TestLegacyLogin(t *testing.T) { func TestUnsupportedCommand(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - res := c.RunDocker("context", "create", "example", "test-example") - res = c.RunDockerOrFail("--context", "test-example", "images") + c.RunDocker("context", "create", "example", "test-example") + res := c.RunDockerOrFail("--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`, diff --git a/tests/ecs-e2e/e2e-ecs_test.go b/tests/ecs-e2e/e2e-ecs_test.go index 99716a647..9c2b6ec05 100644 --- a/tests/ecs-e2e/e2e-ecs_test.go +++ b/tests/ecs-e2e/e2e-ecs_test.go @@ -71,8 +71,8 @@ func TestSecrets(t *testing.T) { }) t.Run("rm secret", func(t *testing.T) { - res := cmd.RunDocker("secret", "rm", secretName) - res = cmd.RunDocker("secret", "list") + cmd.RunDocker("secret", "rm", secretName) + res := cmd.RunDocker("secret", "list") assert.Check(t, !strings.Contains(res.Stdout(), secretName)) }) } @@ -132,7 +132,7 @@ func setupTest(t *testing.T) (*E2eCLI, string) { if localTestProfile != "" { region := os.Getenv("TEST_AWS_REGION") assert.Check(t, region != "") - res = c.RunDocker("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) + c.RunDocker("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) } else { profile := contextName region := os.Getenv("AWS_DEFAULT_REGION") @@ -141,7 +141,7 @@ func setupTest(t *testing.T) (*E2eCLI, string) { assert.Check(t, keyID != "") assert.Check(t, secretKey != "") assert.Check(t, region != "") - res = c.RunDocker("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) + c.RunDocker("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) } res = c.RunDocker("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index 2d56892c9..17dcf459b 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -53,7 +53,7 @@ func init() { type E2eCLI struct { BinDir string ConfigDir string - test *testing.T + test *testing.T } // NewParallelE2eCLI returns a configured TestE2eCLI with t.Parallel() set @@ -163,7 +163,7 @@ func (c *E2eCLI) NewDockerCmd(args ...string) icmd.Cmd { // RunDockerOrFail runs a docker command and returns a result func (c *E2eCLI) RunDockerOrFail(args ...string) *icmd.Result { - fmt.Printf(" [%s] docker %s\n", c.test.Name() , strings.Join(args, " ") ) + fmt.Printf(" [%s] docker %s\n", c.test.Name(), strings.Join(args, " ")) return icmd.RunCmd(c.NewDockerCmd(args...)) } From 981665b02c2a90ae7fc6c03b099d2af1fd27b8a5 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Mon, 24 Aug 2020 10:23:14 +0200 Subject: [PATCH 5/5] Better renaming Signed-off-by: Guillaume Tardif --- local/e2e/backend_test.go | 20 +++--- tests/aci-e2e/e2e-aci_test.go | 86 +++++++++++------------ tests/e2e/e2e_test.go | 126 +++++++++++++++++----------------- tests/ecs-e2e/e2e-ecs_test.go | 24 +++---- tests/framework/e2e.go | 10 +-- 5 files changed, 133 insertions(+), 133 deletions(-) diff --git a/local/e2e/backend_test.go b/local/e2e/backend_test.go index 2d77d357d..e028057e4 100644 --- a/local/e2e/backend_test.go +++ b/local/e2e/backend_test.go @@ -43,33 +43,33 @@ func TestMain(m *testing.M) { func TestLocalBackend(t *testing.T) { c := NewParallelE2eCLI(t, binDir) - c.RunDocker("context", "create", "local", "test-context").Assert(t, icmd.Success) - c.RunDocker("context", "use", "test-context").Assert(t, icmd.Success) + c.RunDockerCmd("context", "create", "local", "test-context").Assert(t, icmd.Success) + c.RunDockerCmd("context", "use", "test-context").Assert(t, icmd.Success) t.Run("run", func(t *testing.T) { - res := c.RunDocker("run", "-d", "nginx") + res := c.RunDockerCmd("run", "-d", "nginx") containerName := strings.TrimSpace(res.Combined()) t.Cleanup(func() { - _ = c.RunDockerOrFail("rm", "-f", containerName) + _ = c.RunDockerOrExitError("rm", "-f", containerName) }) - res = c.RunDocker("inspect", containerName) + res = c.RunDockerCmd("inspect", containerName) res.Assert(t, icmd.Expected{Out: `"Status": "running"`}) }) t.Run("run with ports", func(t *testing.T) { - res := c.RunDocker("run", "-d", "-p", "8080:80", "nginx") + res := c.RunDockerCmd("run", "-d", "-p", "8080:80", "nginx") containerName := strings.TrimSpace(res.Combined()) t.Cleanup(func() { - _ = c.RunDockerOrFail("rm", "-f", containerName) + _ = c.RunDockerOrExitError("rm", "-f", containerName) }) - res = c.RunDocker("inspect", containerName) + res = c.RunDockerCmd("inspect", containerName) res.Assert(t, icmd.Expected{Out: `"Status": "running"`}) - res = c.RunDocker("ps") + res = c.RunDockerCmd("ps") res.Assert(t, icmd.Expected{Out: "0.0.0.0:8080->80/tcp"}) }) t.Run("inspect not found", func(t *testing.T) { - res := c.RunDockerOrFail("inspect", "nonexistentcontainer") + res := c.RunDockerOrExitError("inspect", "nonexistentcontainer") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "Error: No such container: nonexistentcontainer", diff --git a/tests/aci-e2e/e2e-aci_test.go b/tests/aci-e2e/e2e-aci_test.go index 126f2ec20..86fd762ce 100644 --- a/tests/aci-e2e/e2e-aci_test.go +++ b/tests/aci-e2e/e2e-aci_test.go @@ -87,25 +87,25 @@ func TestLoginLogout(t *testing.T) { _ = deleteResourceGroup(rg) }) - c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) - res := c.RunDocker("context", "use", contextName) + c.RunDockerCmd("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rg, "--location", location) + res := c.RunDockerCmd("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) - res = c.RunDocker("context", "ls") + res = c.RunDockerCmd("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) }) t.Run("delete context", func(t *testing.T) { - res := c.RunDocker("context", "use", "default") + res := c.RunDockerCmd("context", "use", "default") res.Assert(t, icmd.Expected{Out: "default"}) - res = c.RunDocker("context", "rm", contextName) + res = c.RunDockerCmd("context", "rm", contextName) res.Assert(t, icmd.Expected{Out: contextName}) }) t.Run("logout", func(t *testing.T) { _, err := os.Stat(login.GetTokenStorePath()) assert.NilError(t, err) - res := c.RunDocker("logout", "azure") + res := c.RunDockerCmd("logout", "azure") res.Assert(t, icmd.Expected{Out: "Removing login credentials for Azure"}) _, err = os.Stat(login.GetTokenStorePath()) errMsg := "no such file or directory" @@ -116,7 +116,7 @@ func TestLoginLogout(t *testing.T) { }) t.Run("create context fail", func(t *testing.T) { - res := c.RunDockerOrFail("context", "create", "aci", "fail-context") + res := c.RunDockerOrExitError("context", "create", "aci", "fail-context") res.Assert(t, icmd.Expected{ ExitCode: errdefs.ExitCodeLoginRequired, Err: `not logged in to azure, you need to run "docker login azure" first`, @@ -162,7 +162,7 @@ func TestContainerRun(t *testing.T) { t.Run("run", func(t *testing.T) { mountTarget := "/usr/share/nginx/html" - res := c.RunDocker( + res := c.RunDockerCmd( "run", "-d", "-v", fmt.Sprintf("%s@%s:%s", saName, testShareName, mountTarget), "-p", "80:80", @@ -172,7 +172,7 @@ func TestContainerRun(t *testing.T) { }) t.Run("inspect", func(t *testing.T) { - res := c.RunDocker("inspect", container) + res := c.RunDockerCmd("inspect", container) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) @@ -186,7 +186,7 @@ func TestContainerRun(t *testing.T) { }) t.Run("ps", func(t *testing.T) { - res := c.RunDocker("ps") + res := c.RunDockerCmd("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") l := out[len(out)-1] assert.Assert(t, strings.Contains(l, container), "Looking for %q in line: %s", container, l) @@ -205,15 +205,15 @@ func TestContainerRun(t *testing.T) { }) t.Run("logs", func(t *testing.T) { - res := c.RunDocker("logs", container) + res := c.RunDockerCmd("logs", container) res.Assert(t, icmd.Expected{Out: "GET"}) }) t.Run("exec", func(t *testing.T) { - res := c.RunDocker("exec", container, "pwd") + res := c.RunDockerCmd("exec", container, "pwd") res.Assert(t, icmd.Expected{Out: "/"}) - res = c.RunDockerOrFail("exec", container, "echo", "fail_with_argument") + res = c.RunDockerOrExitError("exec", container, "echo", "fail_with_argument") res.Assert(t, icmd.Expected{ ExitCode: 1, Err: "ACI exec command does not accept arguments to the command. Only the binary should be specified", @@ -260,7 +260,7 @@ func TestContainerRun(t *testing.T) { }) t.Run("rm a running container", func(t *testing.T) { - res := c.RunDockerOrFail("rm", container) + res := c.RunDockerOrExitError("rm", container) res.Assert(t, icmd.Expected{ Err: fmt.Sprintf("Error: you cannot remove a running container %s. Stop the container before attempting removal or force remove", container), ExitCode: 1, @@ -268,11 +268,11 @@ func TestContainerRun(t *testing.T) { }) t.Run("force rm", func(t *testing.T) { - res := c.RunDocker("rm", "-f", container) + res := c.RunDockerCmd("rm", "-f", container) res.Assert(t, icmd.Expected{Out: container}) checkStopped := func(t poll.LogT) poll.Result { - res := c.RunDockerOrFail("inspect", container) + res := c.RunDockerOrExitError("inspect", container) if res.ExitCode == 1 { return poll.Success() } @@ -306,7 +306,7 @@ func TestContainerRunAttached(t *testing.T) { runRes := icmd.StartCmd(cmd) checkRunning := func(t poll.LogT) poll.Result { - res := c.RunDockerOrFail("inspect", container) + res := c.RunDockerOrExitError("inspect", container) if res.ExitCode == 0 { return poll.Success() } @@ -314,7 +314,7 @@ func TestContainerRunAttached(t *testing.T) { } poll.WaitOn(t, checkRunning, poll.WithDelay(5*time.Second), poll.WithTimeout(60*time.Second)) - inspectRes := c.RunDocker("inspect", container) + inspectRes := c.RunDockerCmd("inspect", container) containerInspect, err := ParseContainerInspect(inspectRes.Stdout()) assert.NilError(t, err) @@ -350,7 +350,7 @@ func TestContainerRunAttached(t *testing.T) { }) t.Run("stop wrong container", func(t *testing.T) { - res := c.RunDockerOrFail("stop", "unknown-container") + res := c.RunDockerOrExitError("stop", "unknown-container") res.Assert(t, icmd.Expected{ Err: "Error: container unknown-container not found", ExitCode: 1, @@ -358,32 +358,32 @@ func TestContainerRunAttached(t *testing.T) { }) t.Run("stop container", func(t *testing.T) { - res := c.RunDocker("stop", container) + res := c.RunDockerCmd("stop", container) res.Assert(t, icmd.Expected{Out: container}) }) t.Run("ps stopped container with --all", func(t *testing.T) { - res := c.RunDocker("ps", container) + res := c.RunDockerCmd("ps", container) out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Assert(t, is.Len(out, 1)) - res = c.RunDocker("ps", "--all", container) + res = c.RunDockerCmd("ps", "--all", container) out = strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Assert(t, is.Len(out, 2)) }) t.Run("start container", func(t *testing.T) { - res := c.RunDocker("start", container) + res := c.RunDockerCmd("start", container) res.Assert(t, icmd.Expected{Out: container}) waitForStatus(t, c, container, "Running") }) t.Run("rm stopped container", func(t *testing.T) { - res := c.RunDocker("stop", container) + res := c.RunDockerCmd("stop", container) res.Assert(t, icmd.Expected{Out: container}) waitForStatus(t, c, container, "Terminated", "Node Stopped") - res = c.RunDocker("rm", container) + res = c.RunDockerCmd("rm", container) res.Assert(t, icmd.Expected{Out: container}) }) } @@ -402,8 +402,8 @@ func TestCompose(t *testing.T) { t.Run("compose up", func(t *testing.T) { // Name of Compose project is taken from current folder "acie2e" - c.RunDocker("compose", "up", "-f", composeFile) - res := c.RunDocker("ps") + c.RunDockerCmd("compose", "up", "-f", composeFile) + res := c.RunDockerCmd("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") // Check three containers are running assert.Assert(t, is.Len(out, 4)) @@ -416,7 +416,7 @@ func TestCompose(t *testing.T) { } assert.Assert(t, webRunning, "web container not running") - res = c.RunDocker("inspect", serverContainer) + res = c.RunDockerCmd("inspect", serverContainer) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) @@ -432,19 +432,19 @@ func TestCompose(t *testing.T) { }) t.Run("logs web", func(t *testing.T) { - res := c.RunDocker("logs", serverContainer) + res := c.RunDockerCmd("logs", serverContainer) res.Assert(t, icmd.Expected{Out: "Listening on port 80"}) }) t.Run("update", func(t *testing.T) { - c.RunDocker("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) - res := c.RunDocker("ps") + c.RunDockerCmd("compose", "up", "-f", composeFileMultiplePorts, "--project-name", composeProjectName) + res := c.RunDockerCmd("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") // Check three containers are running assert.Assert(t, is.Len(out, 4)) for _, cName := range []string{serverContainer, wordsContainer} { - res = c.RunDocker("inspect", cName) + res = c.RunDockerCmd("inspect", cName) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) @@ -470,7 +470,7 @@ func TestCompose(t *testing.T) { } poll.WaitOn(t, checkUp, poll.WithDelay(1*time.Second), poll.WithTimeout(60*time.Second)) - res = c.RunDocker("ps") + res = c.RunDockerCmd("ps") p := containerInspect.Ports[0] res.Assert(t, icmd.Expected{ Out: fmt.Sprintf("%s:%d->%d/tcp", p.HostIP, p.HostPort, p.ContainerPort), @@ -479,8 +479,8 @@ func TestCompose(t *testing.T) { }) t.Run("down", func(t *testing.T) { - c.RunDocker("compose", "down", "--project-name", composeProjectName) - res := c.RunDocker("ps") + c.RunDockerCmd("compose", "down", "--project-name", composeProjectName) + res := c.RunDockerCmd("ps") out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") assert.Equal(t, len(out), 1) }) @@ -505,14 +505,14 @@ func TestRunEnvVars(t *testing.T) { out := strings.Split(strings.TrimSpace(res.Stdout()), "\n") container := strings.TrimSpace(out[len(out)-1]) - res = c.RunDocker("inspect", container) + res = c.RunDockerCmd("inspect", container) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) assert.Equal(t, containerInspect.Image, "mysql:5.7") check := func(t poll.LogT) poll.Result { - res := c.RunDockerOrFail("logs", container) + res := c.RunDockerOrExitError("logs", container) if strings.Contains(res.Stdout(), "Giving user user1 access to schema mytestdb") { return poll.Success() } @@ -536,7 +536,7 @@ func setupTestResourceGroup(t *testing.T, c *E2eCLI) (string, string) { }) createAciContextAndUseIt(t, c, sID, rg) // Check nothing is running - res := c.RunDocker("ps") + res := c.RunDockerCmd("ps") assert.Assert(t, is.Len(strings.Split(strings.TrimSpace(res.Stdout()), "\n"), 1)) return sID, rg } @@ -562,7 +562,7 @@ func azureLogin(t *testing.T, c *E2eCLI) { assert.Check(t, clientID != "", "AZURE_CLIENT_ID must not be empty") assert.Check(t, clientSecret != "", "AZURE_CLIENT_SECRET must not be empty") assert.Check(t, tenantID != "", "AZURE_TENANT_ID must not be empty") - c.RunDocker("login", "azure", "--client-id", clientID, "--client-secret", clientSecret, "--tenant-id", tenantID) + c.RunDockerCmd("login", "azure", "--client-id", clientID, "--client-secret", clientSecret, "--tenant-id", tenantID) } func getSubscriptionID(t *testing.T) string { @@ -581,10 +581,10 @@ func createResourceGroup(sID, rgName string) error { } func createAciContextAndUseIt(t *testing.T, c *E2eCLI, sID, rgName string) { - c.RunDocker("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) - res := c.RunDocker("context", "use", contextName) + c.RunDockerCmd("context", "create", "aci", contextName, "--subscription-id", sID, "--resource-group", rgName, "--location", location) + res := c.RunDockerCmd("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) - res = c.RunDocker("context", "ls") + res = c.RunDockerCmd("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) } @@ -634,7 +634,7 @@ func getContainerName(stdout string) string { func waitForStatus(t *testing.T, c *E2eCLI, containerID string, statuses ...string) { checkStopped := func(logt poll.LogT) poll.Result { - res := c.RunDocker("inspect", containerID) + res := c.RunDockerCmd("inspect", containerID) containerInspect, err := ParseContainerInspect(res.Stdout()) assert.NilError(t, err) for _, status := range statuses { diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 256365545..cefd5e611 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -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`, }) diff --git a/tests/ecs-e2e/e2e-ecs_test.go b/tests/ecs-e2e/e2e-ecs_test.go index 9c2b6ec05..e206257ed 100644 --- a/tests/ecs-e2e/e2e-ecs_test.go +++ b/tests/ecs-e2e/e2e-ecs_test.go @@ -54,25 +54,25 @@ func TestSecrets(t *testing.T) { description := "description " + testID t.Run("create secret", func(t *testing.T) { - res := cmd.RunDocker("secret", "create", secretName, "-u", "user1", "-p", "pass1", "-d", description) + res := cmd.RunDockerCmd("secret", "create", secretName, "-u", "user1", "-p", "pass1", "-d", description) assert.Check(t, strings.Contains(res.Stdout(), "secret:"+secretName)) }) t.Run("list secrets", func(t *testing.T) { - res := cmd.RunDocker("secret", "list") + res := cmd.RunDockerCmd("secret", "list") assert.Check(t, strings.Contains(res.Stdout(), secretName)) assert.Check(t, strings.Contains(res.Stdout(), description)) }) t.Run("inspect secret", func(t *testing.T) { - res := cmd.RunDocker("secret", "inspect", secretName) + res := cmd.RunDockerCmd("secret", "inspect", secretName) assert.Check(t, strings.Contains(res.Stdout(), `"Name": "`+secretName+`"`)) assert.Check(t, strings.Contains(res.Stdout(), `"Description": "`+description+`"`)) }) t.Run("rm secret", func(t *testing.T) { - cmd.RunDocker("secret", "rm", secretName) - res := cmd.RunDocker("secret", "list") + cmd.RunDockerCmd("secret", "rm", secretName) + res := cmd.RunDockerCmd("secret", "list") assert.Check(t, !strings.Contains(res.Stdout(), secretName)) }) } @@ -81,12 +81,12 @@ func TestCompose(t *testing.T) { c, stack := setupTest(t) t.Run("compose up", func(t *testing.T) { - c.RunDocker("compose", "up", "--project-name", stack, "-f", "../composefiles/nginx.yaml") + c.RunDockerCmd("compose", "up", "--project-name", stack, "-f", "../composefiles/nginx.yaml") }) var url string t.Run("compose ps", func(t *testing.T) { - res := c.RunDocker("compose", "ps", "--project-name", stack) + res := c.RunDockerCmd("compose", "ps", "--project-name", stack) lines := strings.Split(res.Stdout(), "\n") assert.Equal(t, 3, len(lines)) @@ -117,7 +117,7 @@ func TestCompose(t *testing.T) { }) t.Run("compose down", func(t *testing.T) { - c.RunDocker("compose", "down", "--project-name", stack, "-f", "../composefiles/nginx.yaml") + c.RunDockerCmd("compose", "down", "--project-name", stack, "-f", "../composefiles/nginx.yaml") }) } @@ -132,7 +132,7 @@ func setupTest(t *testing.T) (*E2eCLI, string) { if localTestProfile != "" { region := os.Getenv("TEST_AWS_REGION") assert.Check(t, region != "") - c.RunDocker("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) + c.RunDockerCmd("context", "create", "ecs", contextName, "--profile", localTestProfile, "--region", region) } else { profile := contextName region := os.Getenv("AWS_DEFAULT_REGION") @@ -141,11 +141,11 @@ func setupTest(t *testing.T) (*E2eCLI, string) { assert.Check(t, keyID != "") assert.Check(t, secretKey != "") assert.Check(t, region != "") - c.RunDocker("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) + c.RunDockerCmd("context", "create", "ecs", contextName, "--profile", profile, "--region", region, "--secret-key", secretKey, "--key-id", keyID) } - res = c.RunDocker("context", "use", contextName) + res = c.RunDockerCmd("context", "use", contextName) res.Assert(t, icmd.Expected{Out: contextName}) - res = c.RunDocker("context", "ls") + res = c.RunDockerCmd("context", "ls") res.Assert(t, icmd.Expected{Out: contextName + " *"}) }) return c, stack diff --git a/tests/framework/e2e.go b/tests/framework/e2e.go index 17dcf459b..f92795a2f 100644 --- a/tests/framework/e2e.go +++ b/tests/framework/e2e.go @@ -161,15 +161,15 @@ func (c *E2eCLI) NewDockerCmd(args ...string) icmd.Cmd { return c.NewCmd(filepath.Join(c.BinDir, DockerExecutableName), args...) } -// RunDockerOrFail runs a docker command and returns a result -func (c *E2eCLI) RunDockerOrFail(args ...string) *icmd.Result { +// RunDockerOrExitError runs a docker command and returns a result +func (c *E2eCLI) RunDockerOrExitError(args ...string) *icmd.Result { fmt.Printf(" [%s] docker %s\n", c.test.Name(), strings.Join(args, " ")) return icmd.RunCmd(c.NewDockerCmd(args...)) } -// RunDocker runs a docker command, expects no error and returns a result -func (c *E2eCLI) RunDocker(args ...string) *icmd.Result { - res := c.RunDockerOrFail(args...) +// RunDockerCmd runs a docker command, expects no error and returns a result +func (c *E2eCLI) RunDockerCmd(args ...string) *icmd.Result { + res := c.RunDockerOrExitError(args...) res.Assert(c.test, icmd.Success) return res }