Skip to content

Commit

Permalink
Report an error if no flag(s) set in service update
Browse files Browse the repository at this point in the history
For now if no flag(s) set, service update will still try to
do an update, it should return an error instead.

[issue 286](#286)
  • Loading branch information
Gong Zhang committed Jul 30, 2019
1 parent f797fba commit 73c16c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/kn/commands/service/service_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
var waitFlags commands.WaitFlags

serviceUpdateCommand := &cobra.Command{
Use: "update NAME",
Use: "update NAME [flags]",
Short: "Update a service.",
Example: `
# Updates a service 'mysvc' with new environment variables
Expand All @@ -50,6 +50,10 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
return err
}

if cmd.Flags().NFlag() == 0 {
return fmt.Errorf("Flag(s) not set\nUsage: %s", cmd.Use)
}

client, err := p.NewClient(namespace)
if err != nil {
return err
Expand Down
20 changes: 20 additions & 0 deletions pkg/kn/commands/service/service_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,26 @@ func fakeServiceUpdate(original *v1alpha1.Service, args []string, sync bool) (
return
}

func TestServcieUpdateNoFlags(t *testing.T) {
orig := newEmptyService()

action, _, _, err := fakeServiceUpdate(orig, []string{
"service", "update", "foo"}, false)

if action != nil {
t.Errorf("Unexpected action if no flag(s) set")
}

if err != nil {
expectedErrMsg := "Flag(s) not set"
if !strings.Contains(err.Error(), expectedErrMsg) {
t.Errorf("Missing %s in %s", expectedErrMsg, err.Error())
}
} else {
t.Errorf("Error is expected if no flag(s) set")
}
}

func TestServiceUpdateImageSync(t *testing.T) {
orig := newEmptyService()

Expand Down

0 comments on commit 73c16c1

Please sign in to comment.