Skip to content

Commit

Permalink
fix(issue knative#762): correct error message when updating service (k…
Browse files Browse the repository at this point in the history
…native#778)

* fix(issue knative#762): correct error message when updating service

* correct message when updating service and passing many names
* fix issue with TestServiceUpdateWithMultipleImages running create vs update

* * added TestServiceDescribeWithMultipleNames
* added TestServiceCreateWithMultipleNames
* fix error message for service delete since many names can be passed
  • Loading branch information
maximilien authored and rhuss committed Apr 15, 2020
1 parent 4aa4de2 commit fb2d0d9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
| Fix plugin lookup with file ext on Windows
| https://github.com/knative/client/pull/774[#774]

| 🐛
| Correct error message when updating service
| https://github.com/knative/client/pull/778[#778]

|===

## v0.13.1 (2020-03-25)
Expand Down
7 changes: 7 additions & 0 deletions pkg/kn/commands/service/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ func TestServiceCreateWithMultipleImages(t *testing.T) {
assert.Assert(t, util.ContainsAll(err.Error(), "\"--image\"", "\"gcr.io/bar/foo:baz\"", "flag", "once"))
}

func TestServiceCreateWithMultipleNames(t *testing.T) {
_, _, _, err := fakeServiceCreate([]string{
"service", "create", "foo", "foo1", "--image", "gcr.io/foo/bar:baz", "--no-wait"}, false)

assert.Assert(t, util.ContainsAll(err.Error(), "'service create' requires the service name given as single argument"))
}

func TestServiceCreateImageSync(t *testing.T) {
action, created, output, err := fakeServiceCreate([]string{
"service", "create", "foo", "--image", "gcr.io/foo/bar:baz"}, false)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/service/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func NewServiceDeleteCommand(p *commands.KnParams) *cobra.Command {

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

namespace, err := p.GetNamespace(cmd)
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/service/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func NewServiceDescribeCommand(p *commands.KnParams) *cobra.Command {
Short: "Show details of a service",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("'kn service describe' requires name of the service as single argument")
return errors.New("'service describe' requires the service name given as single argument")
}
serviceName := args[0]

Expand Down
10 changes: 10 additions & 0 deletions pkg/kn/commands/service/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ func TestServiceDescribeBasic(t *testing.T) {
r.Validate()
}

func TestServiceDescribeWithMultipleNames(t *testing.T) {
client := knclient.NewMockKnServiceClient(t)
r := client.Recorder()
createTestService("foo", []string{"rev1"}, goodConditions())
_, err := executeServiceCommand(client, "describe", "foo", "foo1")

assert.Assert(t, util.ContainsAll(err.Error(), "'service describe' requires the service name given as single argument"))
r.Validate()
}

func TestServiceDescribeSad(t *testing.T) {
client := knclient.NewMockKnServiceClient(t)
r := client.Recorder()
Expand Down
2 changes: 1 addition & 1 deletion pkg/kn/commands/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewServiceUpdateCommand(p *commands.KnParams) *cobra.Command {
Example: updateExample,
RunE: func(cmd *cobra.Command, args []string) (err error) {
if len(args) != 1 {
return errors.New("requires the service name")
return errors.New("'service update' requires the service name given as single argument")
}

namespace, err := p.GetNamespace(cmd)
Expand Down
10 changes: 9 additions & 1 deletion pkg/kn/commands/service/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,19 @@ func TestServiceUpdateImage(t *testing.T) {
func TestServiceUpdateWithMultipleImages(t *testing.T) {
orig := newEmptyService()
_, _, _, err := fakeServiceUpdate(orig, []string{
"service", "create", "foo", "--image", "gcr.io/foo/bar:baz", "--image", "gcr.io/bar/foo:baz", "--no-wait"})
"service", "update", "foo", "--image", "gcr.io/foo/bar:baz", "--image", "gcr.io/bar/foo:baz", "--no-wait"})

assert.Assert(t, util.ContainsAll(err.Error(), "\"--image\"", "\"gcr.io/bar/foo:baz\"", "flag", "once"))
}

func TestServiceUpdateWithMultipleNames(t *testing.T) {
orig := newEmptyService()
_, _, _, err := fakeServiceUpdate(orig, []string{
"service", "update", "foo", "foo1", "--image", "gcr.io/foo/bar:baz", "--no-wait"})

assert.Assert(t, util.ContainsAll(err.Error(), "'service update' requires the service name given as single argument"))
}

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

Expand Down

0 comments on commit fb2d0d9

Please sign in to comment.