From bb8f49773c57c65f75bfa848379d330ae7e5b450 Mon Sep 17 00:00:00 2001 From: French Ben Date: Thu, 31 Aug 2017 19:42:34 -0700 Subject: [PATCH] Move output of stack rm to stdout Signed-off-by: French Ben Update for the test to capture the proper removal Signed-off-by: French Ben Satisfy lint length limit Signed-off-by: French Ben Updated e2e test Signed-off-by: French Ben --- cli/command/stack/remove.go | 8 ++++---- cli/command/stack/remove_test.go | 8 +++++++- e2e/stack/remove_test.go | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cli/command/stack/remove.go b/cli/command/stack/remove.go index 157f71ea12..d595b6c3ec 100644 --- a/cli/command/stack/remove.go +++ b/cli/command/stack/remove.go @@ -103,7 +103,7 @@ func removeServices( var hasError bool sort.Slice(services, sortServiceByName(services)) for _, service := range services { - fmt.Fprintf(dockerCli.Err(), "Removing service %s\n", service.Spec.Name) + fmt.Fprintf(dockerCli.Out(), "Removing service %s\n", service.Spec.Name) if err := dockerCli.Client().ServiceRemove(ctx, service.ID); err != nil { hasError = true fmt.Fprintf(dockerCli.Err(), "Failed to remove service %s: %s", service.ID, err) @@ -119,7 +119,7 @@ func removeNetworks( ) bool { var hasError bool for _, network := range networks { - fmt.Fprintf(dockerCli.Err(), "Removing network %s\n", network.Name) + fmt.Fprintf(dockerCli.Out(), "Removing network %s\n", network.Name) if err := dockerCli.Client().NetworkRemove(ctx, network.ID); err != nil { hasError = true fmt.Fprintf(dockerCli.Err(), "Failed to remove network %s: %s", network.ID, err) @@ -135,7 +135,7 @@ func removeSecrets( ) bool { var hasError bool for _, secret := range secrets { - fmt.Fprintf(dockerCli.Err(), "Removing secret %s\n", secret.Spec.Name) + fmt.Fprintf(dockerCli.Out(), "Removing secret %s\n", secret.Spec.Name) if err := dockerCli.Client().SecretRemove(ctx, secret.ID); err != nil { hasError = true fmt.Fprintf(dockerCli.Err(), "Failed to remove secret %s: %s", secret.ID, err) @@ -151,7 +151,7 @@ func removeConfigs( ) bool { var hasError bool for _, config := range configs { - fmt.Fprintf(dockerCli.Err(), "Removing config %s\n", config.Spec.Name) + fmt.Fprintf(dockerCli.Out(), "Removing config %s\n", config.Spec.Name) if err := dockerCli.Client().ConfigRemove(ctx, config.ID); err != nil { hasError = true fmt.Fprintf(dockerCli.Err(), "Failed to remove config %s: %s", config.ID, err) diff --git a/cli/command/stack/remove_test.go b/cli/command/stack/remove_test.go index c44977c0c6..0ce5cdacfc 100644 --- a/cli/command/stack/remove_test.go +++ b/cli/command/stack/remove_test.go @@ -101,7 +101,13 @@ func TestRemoveStackSkipEmpty(t *testing.T) { cmd.SetArgs([]string{"foo", "bar"}) assert.NoError(t, cmd.Execute()) - assert.Equal(t, "", fakeCli.OutBuffer().String()) + expectedList := []string{"Removing service bar_service1", + "Removing service bar_service2", + "Removing secret bar_secret1", + "Removing config bar_config1", + "Removing network bar_network1\n", + } + assert.Equal(t, strings.Join(expectedList, "\n"), fakeCli.OutBuffer().String()) assert.Contains(t, fakeCli.ErrBuffer().String(), "Nothing found in stack: foo\n") assert.Equal(t, allServiceIDs, fakeClient.removedServices) assert.Equal(t, allNetworkIDs, fakeClient.removedNetworks) diff --git a/e2e/stack/remove_test.go b/e2e/stack/remove_test.go index 77d95c793d..2d39d02345 100644 --- a/e2e/stack/remove_test.go +++ b/e2e/stack/remove_test.go @@ -19,8 +19,8 @@ func TestRemove(t *testing.T) { result := icmd.RunCmd(shell(t, "docker stack rm %s", stackname)) - result.Assert(t, icmd.Expected{Out: icmd.None}) - golden.Assert(t, result.Stderr(), "stack-remove-success.golden") + result.Assert(t, icmd.Expected{Err: icmd.None}) + golden.Assert(t, result.Stdout(), "stack-remove-success.golden") } func deployFullStack(t *testing.T, stackname string) {