Skip to content

Commit

Permalink
Support multiple NAMEs on service delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisy Guo committed Nov 12, 2019
1 parent 1f27eca commit f397792
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/kn/commands/service/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ func NewServiceDeleteCommand(p *commands.KnParams) *cobra.Command {
kn service delete svc2 -n ns1`,

RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
if len(args) < 1 {
return errors.New("requires the service name.")
}

namespace, err := p.GetNamespace(cmd)
if err != nil {
return err
Expand All @@ -47,11 +48,13 @@ func NewServiceDeleteCommand(p *commands.KnParams) *cobra.Command {
return err
}

err = client.DeleteService(args[0])
if err != nil {
return err
for _, name := range args {
err = client.DeleteService(name)
if err != nil {
return err
}
fmt.Fprintf(cmd.OutOrStdout(), "Service '%s' successfully deleted in namespace '%s'.\n", name, namespace)
}
fmt.Fprintf(cmd.OutOrStdout(), "Service '%s' successfully deleted in namespace '%s'.\n", args[0], namespace)
return nil
},
}
Expand Down
19 changes: 19 additions & 0 deletions pkg/kn/commands/service/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,22 @@ func TestServiceDelete(t *testing.T) {
}
assert.Check(t, util.ContainsAll(output, "Service", sevName, "deleted", "namespace", commands.FakeNamespace))
}

func TestMultipleServiceDelete(t *testing.T) {
sevName1 := "sev-12345"
sevName2 := "sev-67890"
sevName3 := "sev-abcde"
action, _, output, err := fakeServiceDelete([]string{"service", "delete", sevName1, sevName2, sevName3})
if err != nil {
t.Error(err)
return
}
if action == nil {
t.Errorf("No action")
} else if !action.Matches("delete", "services") {
t.Errorf("Bad action %v", action)
}
assert.Check(t, util.ContainsAll(output, "Service", sevName1, "deleted", "namespace", commands.FakeNamespace))
assert.Check(t, util.ContainsAll(output, "Service", sevName2, "deleted", "namespace", commands.FakeNamespace))
assert.Check(t, util.ContainsAll(output, "Service", sevName3, "deleted", "namespace", commands.FakeNamespace))
}

0 comments on commit f397792

Please sign in to comment.