Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 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 Down Expand Up @@ -91,10 +91,21 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
return nil
}
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return preCheck(cmd, args)
},
}

commands.AddNamespaceFlags(serviceUpdateCommand.Flags(), false)
editFlags.AddUpdateFlags(serviceUpdateCommand)
waitFlags.AddConditionWaitFlags(serviceUpdateCommand, 60, "Update", "service")
return serviceUpdateCommand
}

func preCheck(cmd *cobra.Command, args []string) error {
if cmd.Flags().NFlag() == 0 {
return errors.New(fmt.Sprintf("flag(s) not set\nUsage: %s", cmd.Use))
}

return nil
}
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 {
t.Fatal(err)
}

expectedErrMsg := "flag(s) not set"
if !strings.Contains(err.Error(), expectedErrMsg) {
t.Fatalf("Missing %s in %s", expectedErrMsg, err.Error())
}
}

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

Expand Down