Fix resource listing with -oname flag (#799)

* Fix resource listing with -oname flag

* add e2e tests
This commit is contained in:
Ying Chun Guo 2020-04-14 22:10:16 +08:00 committed by GitHub
parent 88109bd439
commit 2225b4c8dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 49 additions and 35 deletions

View File

@ -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)

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -43,6 +43,7 @@ func TestSourcePing(t *testing.T) {
t.Log("create Ping sources with a sink to a service")
pingSourceCreate(r, "testpingsource0", "* * * * */1", "ping", "svc:testsvc0")
pingSourceListOutputName(r, "testpingsource0")
t.Log("delete Ping sources")
pingSourceDelete(r, "testpingsource0")
@ -76,7 +77,12 @@ func pingSourceDelete(r *test.KnRunResultCollector, sourceName string) {
out := r.KnTest().Kn().Run("source", "ping", "delete", sourceName)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "ping", "source", sourceName, "deleted", "namespace", r.KnTest().Kn().Namespace()))
r.AssertNoError(out)
}
func pingSourceListOutputName(r *test.KnRunResultCollector, pingSource string) {
out := r.KnTest().Kn().Run("source", "ping", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAll(out.Stdout, pingSource))
}
func pingSourceCreateMissingSink(r *test.KnRunResultCollector, sourceName string, schedule string, data string, sink string) {

View File

@ -45,6 +45,7 @@ func TestRevision(t *testing.T) {
t.Log("describe revision from hello service with print flags")
revName := findRevision(r, "hello")
revisionListOutputName(r, revName)
revisionDescribeWithPrintFlags(r, revName)
t.Log("update hello service and increase revision count to 2")
@ -70,6 +71,12 @@ func TestRevision(t *testing.T) {
serviceDelete(r, "hello")
}
func revisionListOutputName(r *test.KnRunResultCollector, revisionName string) {
out := r.KnTest().Kn().Run("revision", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAll(out.Stdout, revisionName, "revision.serving.knative.dev"))
}
func revisionListWithService(r *test.KnRunResultCollector, serviceNames ...string) {
for _, svcName := range serviceNames {
confGen := findConfigurationGeneration(r, svcName)

View File

@ -48,6 +48,9 @@ func TestRoute(t *testing.T) {
t.Log("return a list of routes associated with hello service")
routeListWithArgument(r, "hello")
t.Log("return a list of routes associated with hello service with -oname flag")
routeListOutputName(r, "hello")
t.Log("return a list of routes associated with hello service with print flags")
routeListWithPrintFlags(r, "hello")
@ -69,6 +72,12 @@ func routeList(r *test.KnRunResultCollector) {
r.AssertNoError(out)
}
func routeListOutputName(r *test.KnRunResultCollector, routeName string) {
out := r.KnTest().Kn().Run("route", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAll(out.Stdout, routeName, "route.serving.knative.dev"))
}
func routeListWithArgument(r *test.KnRunResultCollector, routeName string) {
out := r.KnTest().Kn().Run("route", "list", routeName)

View File

@ -56,6 +56,7 @@ func TestSourceApiServer(t *testing.T) {
t.Log("create apiserver sources with a sink to a service")
apiServerSourceCreate(r, "testapisource0", "Event:v1:true", "testsa", "svc:testsvc0")
apiServerSourceCreate(r, "testapisource1", "Event:v1", "testsa", "svc:testsvc0")
apiServerSourceListOutputName(r, "testapisource0", "testapisource1")
t.Log("list sources")
output := sourceList(r)
@ -91,6 +92,12 @@ func apiServerSourceCreate(r *test.KnRunResultCollector, sourceName string, reso
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, "apiserver", "source", sourceName, "created", "namespace", r.KnTest().Kn().Namespace()))
}
func apiServerSourceListOutputName(r *test.KnRunResultCollector, apiserverSources ...string) {
out := r.KnTest().Kn().Run("source", "apiserver", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAll(out.Stdout, apiserverSources...))
}
func apiServerSourceCreateMissingSink(r *test.KnRunResultCollector, sourceName string, resources string, sa string, sink string) {
out := r.KnTest().Kn().Run("source", "apiserver", "create", sourceName, "--resource", resources, "--service-account", sa, "--sink", sink)
r.AssertError(out)

View File

@ -41,6 +41,7 @@ func TestSourceBinding(t *testing.T) {
t.Log("create source binding")
sourceBindingCreate(r, "my-binding0", "Deployment:apps/v1:myapp", "svc:testsvc0")
sourceBindingListOutputName(r, "my-binding0")
t.Log("delete source binding")
sourceBindingDelete(r, "my-binding0")
@ -72,3 +73,9 @@ func sourceBindingUpdate(r *test.KnRunResultCollector, bindingName string, subje
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAll(out.Stdout, bindingName, "updated", "namespace", r.KnTest().Kn().Namespace()))
}
func sourceBindingListOutputName(r *test.KnRunResultCollector, bindingName string) {
out := r.KnTest().Kn().Run("source", "binding", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAll(out.Stdout, bindingName))
}

View File

@ -51,6 +51,7 @@ func TestBrokerTrigger(t *testing.T) {
triggerCreate(r, "trigger1", "sinksvc0", []string{"a=b"})
triggerCreate(r, "trigger2", "sinksvc1", []string{"type=knative.dev.bar", "source=ping"})
verifyTriggerList(r, "trigger1", "trigger2")
verifyTriggerListOutputName(r, "trigger1", "trigger2")
triggerDelete(r, "trigger1")
triggerDelete(r, "trigger2")
@ -141,6 +142,12 @@ func verifyTriggerList(r *test.KnRunResultCollector, triggers ...string) {
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, triggers...))
}
func verifyTriggerListOutputName(r *test.KnRunResultCollector, triggers ...string) {
out := r.KnTest().Kn().Run("trigger", "list", "--output", "name")
r.AssertNoError(out)
assert.Check(r.T(), util.ContainsAllIgnoreCase(out.Stdout, triggers...))
}
func verifyTriggerDescribe(r *test.KnRunResultCollector, name string, broker string, sink string, filters []string) {
out := r.KnTest().Kn().Run("trigger", "describe", name)
r.AssertNoError(out)