Skip to content

Commit

Permalink
fix panic for kn trigger describe with Sink URI (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand authored Jun 22, 2020
1 parent f82b323 commit 607e366
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/commands/trigger/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 48 additions & 2 deletions pkg/kn/commands/trigger/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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{
Expand All @@ -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{},
}
}

0 comments on commit 607e366

Please sign in to comment.