Skip to content

Commit

Permalink
fix(trigger): Fix filter delete for trigger update (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsimansk authored Mar 18, 2020
1 parent 58ee9c4 commit 1b0e712
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 2 additions & 6 deletions pkg/eventing/v1alpha1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
15 changes: 14 additions & 1 deletion test/e2e/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down Expand Up @@ -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))
}

Expand Down

0 comments on commit 1b0e712

Please sign in to comment.