diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 2d2880307e..649c2c16f3 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -18,6 +18,10 @@ |=== | | Description | PR +| 🐛 +| Fix Panic for `kn trigger describe` with Sink URI +| https://github.com/knative/client/pull/900[#900] + | 🎁 | Group commands in usage output with `kn --help` | https://github.com/knative/client/pull/887[#887] diff --git a/pkg/kn/commands/trigger/describe.go b/pkg/kn/commands/trigger/describe.go index 331b75082d..4cae159f83 100644 --- a/pkg/kn/commands/trigger/describe.go +++ b/pkg/kn/commands/trigger/describe.go @@ -98,10 +98,10 @@ func NewTriggerDescribeCommand(p *commands.KnParams) *cobra.Command { func writeSink(dw printers.PrefixWriter, sink *duckv1.Destination) { subWriter := dw.WriteAttribute("Sink", "") - subWriter.WriteAttribute("Name", sink.Ref.Name) - subWriter.WriteAttribute("Namespace", sink.Ref.Namespace) ref := sink.Ref if ref != nil { + subWriter.WriteAttribute("Name", sink.Ref.Name) + subWriter.WriteAttribute("Namespace", sink.Ref.Namespace) subWriter.WriteAttribute("Resource", fmt.Sprintf("%s (%s)", sink.Ref.Kind, sink.Ref.APIVersion)) } uri := sink.URI diff --git a/pkg/kn/commands/trigger/describe_test.go b/pkg/kn/commands/trigger/describe_test.go index 15285592d5..6e70afea23 100644 --- a/pkg/kn/commands/trigger/describe_test.go +++ b/pkg/kn/commands/trigger/describe_test.go @@ -23,6 +23,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" v1beta1 "knative.dev/eventing/pkg/apis/eventing/v1beta1" + "knative.dev/pkg/apis" duckv1 "knative.dev/pkg/apis/duck/v1" clientv1beta1 "knative.dev/client/pkg/eventing/v1beta1" @@ -33,7 +34,7 @@ func TestSimpleDescribe(t *testing.T) { client := clientv1beta1.NewMockKnEventingClient(t, "mynamespace") recorder := client.Recorder() - recorder.GetTrigger("testtrigger", getTrigger(), nil) + recorder.GetTrigger("testtrigger", getTriggerSinkRef(), nil) out, err := executeTriggerCommand(client, nil, "describe", "testtrigger") assert.NilError(t, err) @@ -60,8 +61,27 @@ func TestDescribeError(t *testing.T) { recorder.Validate() } +func TestDescribeTriggerWithSinkURI(t *testing.T) { + client := clientv1beta1.NewMockKnEventingClient(t, "mynamespace") + + recorder := client.Recorder() + recorder.GetTrigger("testtrigger", getTriggerSinkURI(), nil) + + out, err := executeTriggerCommand(client, nil, "describe", "testtrigger") + assert.NilError(t, err) -func getTrigger() *v1beta1.Trigger { + assert.Assert(t, cmp.Regexp("Name:\\s+testtrigger", out)) + assert.Assert(t, cmp.Regexp("Namespace:\\s+default", out)) + + assert.Assert(t, util.ContainsAll(out, "Broker:", "mybroker")) + assert.Assert(t, util.ContainsAll(out, "Filter:", "type", "foo.type.knative", "source", "src.eventing.knative")) + assert.Assert(t, util.ContainsAll(out, "Sink:", "URI", "https", "foo")) + + // Validate that all recorded API methods have been called + recorder.Validate() +} + +func getTriggerSinkRef() *v1beta1.Trigger { return &v1beta1.Trigger{ TypeMeta: v1.TypeMeta{}, ObjectMeta: metav1.ObjectMeta{ @@ -87,3 +107,29 @@ func getTrigger() *v1beta1.Trigger { Status: v1beta1.TriggerStatus{}, } } + +func getTriggerSinkURI() *v1beta1.Trigger { + return &v1beta1.Trigger{ + TypeMeta: v1.TypeMeta{}, + ObjectMeta: metav1.ObjectMeta{ + Name: "testtrigger", + Namespace: "default", + }, + Spec: v1beta1.TriggerSpec{ + Broker: "mybroker", + Filter: &v1beta1.TriggerFilter{ + Attributes: v1beta1.TriggerFilterAttributes{ + "type": "foo.type.knative", + "source": "src.eventing.knative", + }, + }, + Subscriber: duckv1.Destination{ + URI: &apis.URL{ + Scheme: "https", + Host: "foo", + }, + }, + }, + Status: v1beta1.TriggerStatus{}, + } +}