Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #111 by responding with an error for unknown subcommands #192

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
f27ed5c
Fixes issue #111 by responding with an error for unknown subcommands
maximilien Jun 18, 2019
837fb44
Revert #173 and #139, reinstating having a config file. (#193)
sixolet Jun 20, 2019
375ecbd
List revisions for a given service (#194)
navidshaikh Jun 20, 2019
8a12c72
Set current namespace from kubeconfig by default (#172)
nak3 Jun 24, 2019
5b23948
Restores the bash e2e tests as a smoke test (#183)
maximilien Jun 25, 2019
4d25d73
fix(build.sh): Cosmetic spacing fix (#199)
rhuss Jun 25, 2019
890a57b
Add rhuss and maximilien to OWNERS to increase approver speed. (#209)
sixolet Jun 26, 2019
0f7fd43
Fix the periodic CI flow error in client (#200)
chizhg Jun 27, 2019
dbb7294
feat(service create): Wait for a service to be ready when its created…
rhuss Jun 28, 2019
263d2c0
feat(build.sh): Enable goimports + cleanup imports in source files (#…
rhuss Jun 28, 2019
0ea4430
Add kn revision delete command (#207)
navidshaikh Jun 28, 2019
12de316
Added changes to support container port information while creating/up…
savitaashture Jun 28, 2019
e3ca309
Add the support to test against specified release of Knative serving …
Jun 28, 2019
316d65b
Fixes `limits-memory` and `requests-memory` descriptions (#198)
maximilien Jun 28, 2019
9bc4ed8
fix(serving): Fixed error message when timeout happens during wait fo…
rhuss Jul 1, 2019
7f8fdf7
Fixes issue #111 by responding with an error for unknown subcommands
maximilien Jun 18, 2019
f7b4eb1
Merge branch 'master' into issue111
maximilien Jul 1, 2019
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
4 changes: 4 additions & 0 deletions docs/cmd/kn_revision.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Revision command group

Revision command group

```
kn revision [flags]
```

### Options

```
Expand Down
4 changes: 4 additions & 0 deletions docs/cmd/kn_service.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ Service command group

Service command group

```
kn service [flags]
```

### Options

```
Expand Down
11 changes: 11 additions & 0 deletions pkg/kn/commands/revision/revision.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package revision

import (
"errors"
"fmt"

"github.com/knative/client/pkg/kn/commands"
"github.com/spf13/cobra"
)
Expand All @@ -23,6 +26,14 @@ func NewRevisionCommand(p *commands.KnParams) *cobra.Command {
revisionCmd := &cobra.Command{
Use: "revision",
Short: "Revision command group",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Help()
if len(args) == 0 {
return errors.New("please provide a valid sub-command for \"kn revision\"")
} else {
return errors.New(fmt.Sprintf("unknown command \"%s\" for \"kn revision\"", args[0]))
}
},
}
revisionCmd.AddCommand(NewRevisionListCommand(p))
revisionCmd.AddCommand(NewRevisionDescribeCommand(p))
Expand Down
6 changes: 3 additions & 3 deletions pkg/kn/commands/revision/revision_describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"sigs.k8s.io/yaml"
)

func fakeRevision(args []string, response *v1alpha1.Revision) (action client_testing.Action, output string, err error) {
func fakeRevisionDescribe(args []string, response *v1alpha1.Revision) (action client_testing.Action, output string, err error) {
knParams := &commands.KnParams{}
cmd, fakeServing, buf := commands.CreateTestKnCommand(NewRevisionCommand(knParams), knParams)
fakeServing.AddReactor("*", "*",
Expand All @@ -46,7 +46,7 @@ func fakeRevision(args []string, response *v1alpha1.Revision) (action client_tes
}

func TestDescribeRevisionWithNoName(t *testing.T) {
_, _, err := fakeRevision([]string{"revision", "describe"}, &v1alpha1.Revision{})
_, _, err := fakeRevisionDescribe([]string{"revision", "describe"}, &v1alpha1.Revision{})
expectedError := "requires the revision name."
if err == nil || err.Error() != expectedError {
t.Fatal("expect to fail with missing revision name")
Expand All @@ -70,7 +70,7 @@ func TestDescribeRevisionYaml(t *testing.T) {
},
}

action, data, err := fakeRevision([]string{"revision", "describe", "test-rev"}, &expectedRevision)
action, data, err := fakeRevisionDescribe([]string{"revision", "describe", "test-rev"}, &expectedRevision)
if err != nil {
t.Fatal(err)
}
Expand Down
66 changes: 66 additions & 0 deletions pkg/kn/commands/revision/revision_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright © 2018 The Knative Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package revision

import (
"strings"
"testing"

"github.com/knative/client/pkg/kn/commands"
v1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
client_testing "k8s.io/client-go/testing"
)

func fakeRevision(args []string, response *v1alpha1.ServiceList) (action client_testing.Action, output []string, err error) {
knParams := &commands.KnParams{}
cmd, fakeServing, buf := commands.CreateTestKnCommand(NewRevisionCommand(knParams), knParams)
fakeServing.AddReactor("*", "*",
func(a client_testing.Action) (bool, runtime.Object, error) {
action = a
return true, response, nil
})
cmd.SetArgs(args)
err = cmd.Execute()
if err != nil {
return
}
output = strings.Split(buf.String(), "\n")
return
}

func TestUnknownSubcommand(t *testing.T) {
_, _, err := fakeRevision([]string{"revision", "unknown"}, &v1alpha1.ServiceList{})
if err == nil {
t.Error(err)
return
}

if err.Error() != "unknown command \"unknown\" for \"kn revision\"" {
t.Errorf("Bad error message '%s'", err.Error())
}
}

func TestEmptySubcommand(t *testing.T) {
_, _, err := fakeRevision([]string{"revision"}, &v1alpha1.ServiceList{})
if err == nil {
t.Error(err)
return
}

if err.Error() != "please provide a valid sub-command for \"kn revision\"" {
t.Errorf("Bad error message '%s'", err.Error())
}
}
12 changes: 12 additions & 0 deletions pkg/kn/commands/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
package service

import (
"errors"
"fmt"

"github.com/knative/client/pkg/kn/commands"
"github.com/spf13/cobra"
)
Expand All @@ -23,6 +26,15 @@ func NewServiceCommand(p *commands.KnParams) *cobra.Command {
serviceCmd := &cobra.Command{
Use: "service",
Short: "Service command group",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Help()
if len(args) == 0 {
return errors.New("please provide a valid sub-command for \"kn service\"")
} else {
return errors.New(fmt.Sprintf("unknown command \"%s\" for \"kn service\"", args[0]))
}
return nil
},
}
serviceCmd.AddCommand(NewServiceListCommand(p))
serviceCmd.AddCommand(NewServiceDescribeCommand(p))
Expand Down
66 changes: 66 additions & 0 deletions pkg/kn/commands/service/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright © 2018 The Knative Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package service

import (
"strings"
"testing"

"github.com/knative/client/pkg/kn/commands"
v1alpha1 "github.com/knative/serving/pkg/apis/serving/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
client_testing "k8s.io/client-go/testing"
)

func fakeService(args []string, response *v1alpha1.ServiceList) (action client_testing.Action, output []string, err error) {
knParams := &commands.KnParams{}
cmd, fakeServing, buf := commands.CreateTestKnCommand(NewServiceCommand(knParams), knParams)
fakeServing.AddReactor("*", "*",
func(a client_testing.Action) (bool, runtime.Object, error) {
action = a
return true, response, nil
})
cmd.SetArgs(args)
err = cmd.Execute()
if err != nil {
return
}
output = strings.Split(buf.String(), "\n")
return
}

func TestUnknownSubcommand(t *testing.T) {
_, _, err := fakeService([]string{"service", "unknown"}, &v1alpha1.ServiceList{})
if err == nil {
t.Error(err)
return
}

if err.Error() != "unknown command \"unknown\" for \"kn service\"" {
t.Errorf("Bad error message '%s'", err.Error())
}
}

func TestEmptySubcommand(t *testing.T) {
_, _, err := fakeService([]string{"service"}, &v1alpha1.ServiceList{})
if err == nil {
t.Error(err)
return
}

if err.Error() != "please provide a valid sub-command for \"kn service\"" {
t.Errorf("Bad error message '%s'", err.Error())
}
}