From 9625b5f4c5c20881bfb837dc0cde4fe5b6b8f6c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20Hu=C3=9F?= Date: Thu, 22 Aug 2019 09:23:32 +0200 Subject: [PATCH] chore(plugins, services, routes): Aligned "Not found" messages (#359) For the sake of consistency with out own service commands and for kubectl, `kn plugin list` should print: ``` No plugins found. ``` `kn service list` should print: ``` No services found. ``` and not `No resources found.` like it does now. Same for `kn routes list`. --- pkg/kn/commands/plugin/plugin_list.go | 4 +++- pkg/kn/commands/plugin/plugin_list_test.go | 4 ++-- pkg/kn/commands/route/list.go | 5 +++-- pkg/kn/commands/route/list_test.go | 2 +- pkg/kn/commands/service/service_list.go | 2 +- pkg/kn/commands/service/service_list_test.go | 2 +- test/e2e/basic_workflow_test.go | 2 +- 7 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pkg/kn/commands/plugin/plugin_list.go b/pkg/kn/commands/plugin/plugin_list.go index 05a730a8a..4e28976ef 100644 --- a/pkg/kn/commands/plugin/plugin_list.go +++ b/pkg/kn/commands/plugin/plugin_list.go @@ -80,7 +80,9 @@ func listPlugins(cmd *cobra.Command, flags pluginListFlags) error { if len(pluginsFound) == 0 { if flags.verbose { - fmt.Fprintf(out, "No plugins found in path %s\n", pluginPath) + fmt.Fprintf(out, "No plugins found in path %s.\n", pluginPath) + } else { + fmt.Fprintln(out, "No plugins found.") } return nil } diff --git a/pkg/kn/commands/plugin/plugin_list_test.go b/pkg/kn/commands/plugin/plugin_list_test.go index 24afdee6d..c5207e9dd 100644 --- a/pkg/kn/commands/plugin/plugin_list_test.go +++ b/pkg/kn/commands/plugin/plugin_list_test.go @@ -124,7 +124,7 @@ func TestPluginList(t *testing.T) { defer ctx.cleanup() err := ctx.execute("plugin", "list", "--lookup-plugins-in-path=true") assert.NilError(t, err) - assert.Equal(t, ctx.output(), "") + assert.Equal(t, ctx.output(), "No plugins found.\n") }) }) @@ -224,7 +224,7 @@ func TestPluginList(t *testing.T) { err := ctx.execute("plugin", "list") assert.NilError(t, err) - assert.Equal(t, ctx.output(), "") + assert.Equal(t, ctx.output(), "No plugins found.\n") }) }) } diff --git a/pkg/kn/commands/route/list.go b/pkg/kn/commands/route/list.go index f6505f361..e974e5721 100644 --- a/pkg/kn/commands/route/list.go +++ b/pkg/kn/commands/route/list.go @@ -15,6 +15,7 @@ package route import ( + "errors" "fmt" "knative.dev/client/pkg/kn/commands" @@ -57,13 +58,13 @@ func NewRouteListCommand(p *commands.KnParams) *cobra.Command { case 1: routeList, err = client.ListRoutes(v1alpha12.WithName(args[0])) default: - return fmt.Errorf("'kn route list' accepts maximum 1 argument.") + return errors.New("'kn route list' accepts only one additional argument") } if err != nil { return err } if len(routeList.Items) == 0 { - fmt.Fprintf(cmd.OutOrStdout(), "No resources found.\n") + fmt.Fprintf(cmd.OutOrStdout(), "No routes found.\n") return nil } printer, err := routeListFlags.ToPrinter() diff --git a/pkg/kn/commands/route/list_test.go b/pkg/kn/commands/route/list_test.go index 34a3465ac..fb74401b9 100644 --- a/pkg/kn/commands/route/list_test.go +++ b/pkg/kn/commands/route/list_test.go @@ -54,7 +54,7 @@ func TestListEmpty(t *testing.T) { t.Errorf("No action") } else if !action.Matches("list", "routes") { t.Errorf("Bad action %v", action) - } else if output[0] != "No resources found." { + } else if output[0] != "No routes found." { t.Errorf("Bad output %s", output[0]) } } diff --git a/pkg/kn/commands/service/service_list.go b/pkg/kn/commands/service/service_list.go index 7a867bc44..a24c7f83e 100644 --- a/pkg/kn/commands/service/service_list.go +++ b/pkg/kn/commands/service/service_list.go @@ -54,7 +54,7 @@ func NewServiceListCommand(p *commands.KnParams) *cobra.Command { return err } if len(serviceList.Items) == 0 { - fmt.Fprintf(cmd.OutOrStdout(), "No resources found.\n") + fmt.Fprintf(cmd.OutOrStdout(), "No services found.\n") return nil } diff --git a/pkg/kn/commands/service/service_list_test.go b/pkg/kn/commands/service/service_list_test.go index 023b206d0..15a443edf 100644 --- a/pkg/kn/commands/service/service_list_test.go +++ b/pkg/kn/commands/service/service_list_test.go @@ -57,7 +57,7 @@ func TestListEmpty(t *testing.T) { t.Errorf("No action") } else if !action.Matches("list", "services") { t.Errorf("Bad action %v", action) - } else if output[0] != "No resources found." { + } else if output[0] != "No services found." { t.Errorf("Bad output %s", output[0]) } } diff --git a/test/e2e/basic_workflow_test.go b/test/e2e/basic_workflow_test.go index 22e03a936..114549c95 100644 --- a/test/e2e/basic_workflow_test.go +++ b/test/e2e/basic_workflow_test.go @@ -75,7 +75,7 @@ func (test *e2eTest) serviceListEmpty(t *testing.T) { out, err := test.kn.RunWithOpts([]string{"service", "list"}, runOpts{NoNamespace: false}) assert.NilError(t, err) - assert.Check(t, util.ContainsAll(out, "No resources found.")) + assert.Check(t, util.ContainsAll(out, "No services found.")) } func (test *e2eTest) serviceCreate(t *testing.T, serviceName string) {