Skip to content

Commit

Permalink
fix panic for kn source ping describe with sink uri (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhelfand authored May 20, 2020
1 parent c7d28d5 commit 9803cd6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
|===
| | Description | PR

| 🐛
| Fix Panic for kn source ping describe with Sink URI
| https://github.com/knative/client/pull/848[#848]

| 🎁
| Add kn service delete --all
| https://github.com/knative/client/pull/836[#836]
Expand Down
4 changes: 2 additions & 2 deletions pkg/kn/commands/source/ping/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func NewPingDescribeCommand(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
51 changes: 43 additions & 8 deletions pkg/kn/commands/source/ping/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,33 @@ import (

clientv1alpha2 "knative.dev/client/pkg/sources/v1alpha2"
"knative.dev/client/pkg/util"
"knative.dev/pkg/apis"
)

func TestSimpleDescribe(t *testing.T) {
func TestDescribeRef(t *testing.T) {
pingClient := clientv1alpha2.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource", getPingSource(), nil)
pingRecorder.GetPingSource("testsource-ref", getPingSourceSinkRef(), nil)

out, err := executePingSourceCommand(pingClient, nil, "describe", "testsource")
out, err := executePingSourceCommand(pingClient, nil, "describe", "testsource-ref")
assert.NilError(t, err)
util.ContainsAll(out, "1 2 3 4 5", "honeymoon", "myservicenamespace", "mysvc", "Service", "testsource")
util.ContainsAll(out, "myaccount", "100m", "128Mi", "200m", "256Mi")
assert.Assert(t, util.ContainsAll(out, "1 2 3 4 5", "honeymoon", "myservicenamespace", "mysvc", "Service", "testsource-ref"))

pingRecorder.Validate()
}

func TestDescribeURI(t *testing.T) {
pingClient := clientv1alpha2.NewMockKnPingSourceClient(t, "mynamespace")

pingRecorder := pingClient.Recorder()
pingRecorder.GetPingSource("testsource-uri", getPingSourceSinkURI(), nil)

out, err := executePingSourceCommand(pingClient, nil, "describe", "testsource-uri")
assert.NilError(t, err)
assert.Assert(t, util.ContainsAll(out, "mynamespace", "1 2 3 4 5", "honeymoon", "URI", "https", "foo", "testsource-uri"))

pingRecorder.Validate()
}

func TestDescribeError(t *testing.T) {
Expand All @@ -50,17 +62,17 @@ func TestDescribeError(t *testing.T) {

out, err := executePingSourceCommand(pingClient, nil, "describe", "testsource")
assert.ErrorContains(t, err, "testsource")
util.ContainsAll(out, "Usage", "testsource")
assert.Assert(t, util.ContainsAll(out, "Usage", "testsource"))

pingRecorder.Validate()

}

func getPingSource() *v1alpha2.PingSource {
func getPingSourceSinkRef() *v1alpha2.PingSource {
return &v1alpha2.PingSource{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "testsource",
Name: "testsource-ref",
},
Spec: v1alpha2.PingSourceSpec{
Schedule: "1 2 3 4 5",
Expand All @@ -78,3 +90,26 @@ func getPingSource() *v1alpha2.PingSource {
Status: v1alpha2.PingSourceStatus{},
}
}

func getPingSourceSinkURI() *v1alpha2.PingSource {
return &v1alpha2.PingSource{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: "testsource-uri",
Namespace: "mynamespace",
},
Spec: v1alpha2.PingSourceSpec{
Schedule: "1 2 3 4 5",
JsonData: "honeymoon",
SourceSpec: duckv1.SourceSpec{
Sink: duckv1.Destination{
URI: &apis.URL{
Scheme: "https",
Host: "foo",
},
},
},
},
Status: v1alpha2.PingSourceStatus{},
}
}

0 comments on commit 9803cd6

Please sign in to comment.