diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 358ab7b6fd..5a9fcc776e 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -18,9 +18,13 @@ |=== | | Description | PR +| 🐛 +| Fix filter delete for trigger update command +| https://github.com/knative/client/pull/746[#746] + | 🐛 | Fix trigger create --filter flag to be optional -| https://github.com/knative/client/pull/735[#745] +| https://github.com/knative/client/pull/745[#745] ## v0.13.0 (2020-03-11) diff --git a/pkg/eventing/v1alpha1/client.go b/pkg/eventing/v1alpha1/client.go index 2e6c910a65..16037fe7de 100644 --- a/pkg/eventing/v1alpha1/client.go +++ b/pkg/eventing/v1alpha1/client.go @@ -189,13 +189,9 @@ func (b *TriggerBuilder) Filters(filters map[string]string) *TriggerBuilder { filter = &v1alpha1.TriggerFilter{} b.trigger.Spec.Filter = filter } - attributes := filter.Attributes - if attributes == nil { - attributes = &v1alpha1.TriggerFilterAttributes{} - filter.Attributes = attributes - } + filter.Attributes = &v1alpha1.TriggerFilterAttributes{} for k, v := range filters { - (*attributes)[k] = v + (*filter.Attributes)[k] = v } return b } diff --git a/test/e2e/trigger_test.go b/test/e2e/trigger_test.go index 3aaf445a98..ee4b36bae2 100644 --- a/test/e2e/trigger_test.go +++ b/test/e2e/trigger_test.go @@ -57,6 +57,15 @@ func TestBrokerTrigger(t *testing.T) { test.triggerDelete(t, r, "deltrigger") test.verifyTriggerNotfound(t, r, "deltrigger") + t.Log("create a trigger with filters and remove them one by one") + test.triggerCreate(t, r, "filtertrigger", "sinksvc0", []string{"foo=bar", "source=ping"}) + test.verifyTriggerDescribe(t, r, "filtertrigger", "default", "sinksvc0", []string{"foo", "bar", "source", "ping"}) + test.triggerUpdate(t, r, "filtertrigger", "foo-", "sinksvc0") + test.verifyTriggerDescribe(t, r, "filtertrigger", "default", "sinksvc0", []string{"source", "ping"}) + test.triggerUpdate(t, r, "filtertrigger", "source-", "sinksvc0") + test.verifyTriggerDescribe(t, r, "filtertrigger", "default", "sinksvc0", nil) + test.triggerDelete(t, r, "filtertrigger") + t.Log("create a trigger, describe and update it") test.triggerCreate(t, r, "updtrigger", "sinksvc0", []string{"a=b"}) test.verifyTriggerDescribe(t, r, "updtrigger", "default", "sinksvc0", []string{"a", "b"}) @@ -130,7 +139,11 @@ func (test *e2eTest) verifyTriggerList(t *testing.T, r *KnRunResultCollector, tr func (test *e2eTest) verifyTriggerDescribe(t *testing.T, r *KnRunResultCollector, name string, broker string, sink string, filters []string) { out := test.kn.Run("trigger", "describe", name) r.AssertNoError(out) - assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, filters...)) + if len(filters) > 0 { + assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, filters...)) + } else { + assert.Check(t, util.ContainsNone(out.Stdout, "Filter")) + } assert.Check(t, util.ContainsAllIgnoreCase(out.Stdout, name, broker, sink)) }