mirror of https://github.com/docker/cli.git
Move output of stack rm to stdout
Signed-off-by: French Ben <frenchben@docker.com> Update for the test to capture the proper removal Signed-off-by: French Ben <frenchben@docker.com> Satisfy lint length limit Signed-off-by: French Ben <frenchben@docker.com> Updated e2e test Signed-off-by: French Ben <frenchben@docker.com>
This commit is contained in:
parent
d861a1c3dd
commit
bb8f49773c
|
@ -103,7 +103,7 @@ func removeServices(
|
||||||
var hasError bool
|
var hasError bool
|
||||||
sort.Slice(services, sortServiceByName(services))
|
sort.Slice(services, sortServiceByName(services))
|
||||||
for _, service := range 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 {
|
if err := dockerCli.Client().ServiceRemove(ctx, service.ID); err != nil {
|
||||||
hasError = true
|
hasError = true
|
||||||
fmt.Fprintf(dockerCli.Err(), "Failed to remove service %s: %s", service.ID, err)
|
fmt.Fprintf(dockerCli.Err(), "Failed to remove service %s: %s", service.ID, err)
|
||||||
|
@ -119,7 +119,7 @@ func removeNetworks(
|
||||||
) bool {
|
) bool {
|
||||||
var hasError bool
|
var hasError bool
|
||||||
for _, network := range networks {
|
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 {
|
if err := dockerCli.Client().NetworkRemove(ctx, network.ID); err != nil {
|
||||||
hasError = true
|
hasError = true
|
||||||
fmt.Fprintf(dockerCli.Err(), "Failed to remove network %s: %s", network.ID, err)
|
fmt.Fprintf(dockerCli.Err(), "Failed to remove network %s: %s", network.ID, err)
|
||||||
|
@ -135,7 +135,7 @@ func removeSecrets(
|
||||||
) bool {
|
) bool {
|
||||||
var hasError bool
|
var hasError bool
|
||||||
for _, secret := range secrets {
|
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 {
|
if err := dockerCli.Client().SecretRemove(ctx, secret.ID); err != nil {
|
||||||
hasError = true
|
hasError = true
|
||||||
fmt.Fprintf(dockerCli.Err(), "Failed to remove secret %s: %s", secret.ID, err)
|
fmt.Fprintf(dockerCli.Err(), "Failed to remove secret %s: %s", secret.ID, err)
|
||||||
|
@ -151,7 +151,7 @@ func removeConfigs(
|
||||||
) bool {
|
) bool {
|
||||||
var hasError bool
|
var hasError bool
|
||||||
for _, config := range configs {
|
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 {
|
if err := dockerCli.Client().ConfigRemove(ctx, config.ID); err != nil {
|
||||||
hasError = true
|
hasError = true
|
||||||
fmt.Fprintf(dockerCli.Err(), "Failed to remove config %s: %s", config.ID, err)
|
fmt.Fprintf(dockerCli.Err(), "Failed to remove config %s: %s", config.ID, err)
|
||||||
|
|
|
@ -101,7 +101,13 @@ func TestRemoveStackSkipEmpty(t *testing.T) {
|
||||||
cmd.SetArgs([]string{"foo", "bar"})
|
cmd.SetArgs([]string{"foo", "bar"})
|
||||||
|
|
||||||
assert.NoError(t, cmd.Execute())
|
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.Contains(t, fakeCli.ErrBuffer().String(), "Nothing found in stack: foo\n")
|
||||||
assert.Equal(t, allServiceIDs, fakeClient.removedServices)
|
assert.Equal(t, allServiceIDs, fakeClient.removedServices)
|
||||||
assert.Equal(t, allNetworkIDs, fakeClient.removedNetworks)
|
assert.Equal(t, allNetworkIDs, fakeClient.removedNetworks)
|
||||||
|
|
|
@ -19,8 +19,8 @@ func TestRemove(t *testing.T) {
|
||||||
|
|
||||||
result := icmd.RunCmd(shell(t, "docker stack rm %s", stackname))
|
result := icmd.RunCmd(shell(t, "docker stack rm %s", stackname))
|
||||||
|
|
||||||
result.Assert(t, icmd.Expected{Out: icmd.None})
|
result.Assert(t, icmd.Expected{Err: icmd.None})
|
||||||
golden.Assert(t, result.Stderr(), "stack-remove-success.golden")
|
golden.Assert(t, result.Stdout(), "stack-remove-success.golden")
|
||||||
}
|
}
|
||||||
|
|
||||||
func deployFullStack(t *testing.T, stackname string) {
|
func deployFullStack(t *testing.T, stackname string) {
|
||||||
|
|
Loading…
Reference in New Issue