Skip to content

Commit

Permalink
Fix resource listing with -oname flag (knative#799)
Browse files Browse the repository at this point in the history
* Fix resource listing with -oname flag

* add e2e tests

Signed-off-by: Roland Huß <[email protected]>
# Conflicts:
#	test/e2e/ping_test.go
#	test/e2e/revision_test.go
#	test/e2e/route_test.go
#	test/e2e/source_apiserver_test.go
#	test/e2e/source_binding_test.go
#	test/e2e/trigger_test.go
  • Loading branch information
Ying Chun Guo authored and rhuss committed Apr 15, 2020
1 parent 6843871 commit 3c65765
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 35 deletions.
7 changes: 1 addition & 6 deletions pkg/kn/commands/revision/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command {
sortRevisions(revisionList)

// Print out infos via printer framework
printer, err := revisionListFlags.ToPrinter()
if err != nil {
return err
}

return printer.PrintObj(revisionList, cmd.OutOrStdout())
return revisionListFlags.Print(revisionList, cmd.OutOrStdout())
},
}
commands.AddNamespaceFlags(revisionListCommand.Flags(), true)
Expand Down
6 changes: 1 addition & 5 deletions pkg/kn/commands/route/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,7 @@ func NewRouteListCommand(p *commands.KnParams) *cobra.Command {
fmt.Fprintf(cmd.OutOrStdout(), "No routes found.\n")
return nil
}
printer, err := routeListFlags.ToPrinter()
if err != nil {
return err
}
err = printer.PrintObj(routeList, cmd.OutOrStdout())
err = routeListFlags.Print(routeList, cmd.OutOrStdout())
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/kn/commands/source/apiserver/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ func NewAPIServerListCommand(p *commands.KnParams) *cobra.Command {
listFlags.EnsureWithNamespace()
}

printer, err := listFlags.ToPrinter()
if err != nil {
return nil
}

err = printer.PrintObj(sourceList, cmd.OutOrStdout())
err = listFlags.Print(sourceList, cmd.OutOrStdout())
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/kn/commands/source/binding/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,7 @@ func NewBindingListCommand(p *commands.KnParams) *cobra.Command {
listFlags.EnsureWithNamespace()
}

printer, err := listFlags.ToPrinter()
if err != nil {
return nil
}

err = printer.PrintObj(sourceList, cmd.OutOrStdout())
err = listFlags.Print(sourceList, cmd.OutOrStdout())
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/kn/commands/source/ping/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ func NewPingListCommand(p *commands.KnParams) *cobra.Command {
listFlags.EnsureWithNamespace()
}

printer, err := listFlags.ToPrinter()
if err != nil {
return nil
}

err = printer.PrintObj(sourceList, cmd.OutOrStdout())
err = listFlags.Print(sourceList, cmd.OutOrStdout())
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/kn/commands/trigger/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ func NewTriggerListCommand(p *commands.KnParams) *cobra.Command {
triggerListFlags.EnsureWithNamespace()
}

printer, err := triggerListFlags.ToPrinter()
if err != nil {
return err
}

err = printer.PrintObj(triggerList, cmd.OutOrStdout())
err = triggerListFlags.Print(triggerList, cmd.OutOrStdout())
if err != nil {
return err
}
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/ping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func TestSourcePing(t *testing.T) {
t.Log("create Ping sources with a sink to a service")

pingSourceCreate(t, it, r, "testpingsource0", "* * * * */1", "ping", "svc:testsvc0")
pingSourceListOutputName(t, it, r, "testpingsource0")

t.Log("delete Ping sources")
pingSourceDelete(t, it, r, "testpingsource0")
Expand Down Expand Up @@ -76,7 +77,12 @@ func pingSourceDelete(t *testing.T, it *test.KnTest, r *test.KnRunResultCollecto
out := it.Kn().Run("source", "ping", "delete", sourceName)
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "deleted", "namespace", it.Kn().Namespace()))
r.AssertNoError(out)
}

func pingSourceListOutputName(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, pingSource string) {
out := it.Kn().Run("source", "ping", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, pingSource))
}

func pingSourceCreateMissingSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestRevision(t *testing.T) {

t.Log("describe revision from hello service with print flags")
revName := findRevision(t, it, r, "hello")
revisionListOutputName(t, it, r, revName)
revisionDescribeWithPrintFlags(t, it, r, revName)

t.Log("update hello service and increase revision count to 2")
Expand All @@ -70,6 +71,12 @@ func TestRevision(t *testing.T) {
serviceDelete(t, it, r, "hello")
}

func revisionListOutputName(t *testing.T, it *test.KnTest,r *test.KnRunResultCollector, revisionName string) {
out := it.Kn().Run("revision", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, revisionName, "revision.serving.knative.dev"))
}

func revisionListWithService(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, serviceNames ...string) {
for _, svcName := range serviceNames {
confGen := findConfigurationGeneration(t, it, r, svcName)
Expand Down
9 changes: 9 additions & 0 deletions test/e2e/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func TestRoute(t *testing.T) {
t.Log("return a list of routes associated with hello service")
routeListWithArgument(t, it, r, "hello")

t.Log("return a list of routes associated with hello service with -oname flag")
routeListOutputName(t, it, r, "hello")

t.Log("return a list of routes associated with hello service with print flags")
routeListWithPrintFlags(t, it, r, "hello")

Expand All @@ -69,6 +72,12 @@ func routeList(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector) {
r.AssertNoError(out)
}

func routeListOutputName(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, routeName string) {
out := it.Kn().Run("route", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, routeName, "route.serving.knative.dev"))
}

func routeListWithArgument(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, routeName string) {
out := it.Kn().Run("route", "list", routeName)

Expand Down
7 changes: 7 additions & 0 deletions test/e2e/source_apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func TestSourceApiServer(t *testing.T) {
t.Log("create apiserver sources with a sink to a service")
apiServerSourceCreate(t, it, r, "testapisource0", "Event:v1:true", "testsa", "svc:testsvc0")
apiServerSourceCreate(t, it, r, "testapisource1", "Event:v1", "testsa", "svc:testsvc0")
apiServerSourceListOutputName(t, it, r, "testapisource0", "testapisource1")

t.Log("list sources")
output := sourceList(t, it, r)
Expand Down Expand Up @@ -91,6 +92,12 @@ func apiServerSourceCreate(t *testing.T, it *test.KnTest, r *test.KnRunResultCol
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "created", "namespace", it.Kn().Namespace()))
}

func apiServerSourceListOutputName(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, apiserverSources ...string) {
out := it.Kn().Run("source", "apiserver", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, apiserverSources...))
}

func apiServerSourceCreateMissingSink(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, sourceName string, resources string, sa string, sink string) {
out := it.Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink)
r.AssertError(out)
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/source_binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestSourceBinding(t *testing.T) {

t.Log("create source binding")
sourceBindingCreate(t, it, r, "my-binding0", "Deployment:apps/v1:myapp", "svc:testsvc0")
sourceBindingListOutputName(t, it, r, "my-binding0")

t.Log("delete source binding")
sourceBindingDelete(t, it, r, "my-binding0")
Expand Down Expand Up @@ -72,3 +73,9 @@ func sourceBindingUpdate(t *testing.T, it *test.KnTest, r *test.KnRunResultColle
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, bindingName, "updated", "namespace", it.Kn().Namespace()))
}

func sourceBindingListOutputName(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, bindingName string) {
out := it.Kn().Run("source", "binding", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAll(out.Stdout, bindingName))
}
7 changes: 7 additions & 0 deletions test/e2e/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func TestBrokerTrigger(t *testing.T) {
triggerCreate(t, it, r, "trigger1", "sinksvc0", []string{"a=b"})
triggerCreate(t, it, r, "trigger2", "sinksvc1", []string{"type=knative.dev.bar", "source=ping"})
verifyTriggerList(t, it, r, "trigger1", "trigger2")
verifyTriggerListOutputName(t, it, r, "trigger1", "trigger2")
triggerDelete(t, it, r, "trigger1")
triggerDelete(t, it, r, "trigger2")

Expand Down Expand Up @@ -141,6 +142,12 @@ func verifyTriggerList(t *testing.T, it *test.KnTest, r *test.KnRunResultCollect
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, triggers...))
}

func verifyTriggerListOutputName(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, triggers ...string) {
out := it.Kn().Run("trigger", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, triggers...))
}

func verifyTriggerDescribe(t *testing.T, it *test.KnTest, r *test.KnRunResultCollector, name string, broker string, sink string, filters []string) {
out := it.Kn().Run("trigger", "describe", name)
r.AssertNoError(out)
Expand Down

0 comments on commit 3c65765

Please sign in to comment.