Skip to content

Commit

Permalink
Refactored new filter tests to all use the same helper functions (#7397)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 authored Oct 31, 2023
1 parent 5ed1b7a commit c8f4624
Showing 1 changed file with 14 additions and 39 deletions.
53 changes: 14 additions & 39 deletions test/rekt/features/new_trigger_filters/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,9 @@ import (
"fmt"

. "github.com/cloudevents/sdk-go/v2/test"
"knative.dev/reconciler-test/pkg/eventshub"
. "knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/pkg/resources/service"

eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/trigger"
)

// FiltersFeatureSet creates a feature set for testing the broker implementation of the new trigger filters experimental feature
Expand All @@ -42,10 +35,22 @@ func FiltersFeatureSet(brokerName string) *feature.FeatureSet {
unmatchedEvent.SetType("org.wrong.type")
unmatchedEvent.SetSource("org.wrong.source")

eventContexts := []CloudEventsContext{
{
eventType: matchedEvent.Type(),
eventSource: matchedEvent.Source(),
shouldDeliver: true,
},
{
eventType: unmatchedEvent.Type(),
eventSource: unmatchedEvent.Source(),
shouldDeliver: false,
},
}

features := make([]*feature.Feature, 0, 8)
tests := map[string]struct {
filters []eventingv1.SubscriptionsAPIFilter
step feature.StepFn
}{
"Exact filter": {
filters: []eventingv1.SubscriptionsAPIFilter{
Expand Down Expand Up @@ -87,38 +92,8 @@ func FiltersFeatureSet(brokerName string) *feature.FeatureSet {
}

for name, fs := range tests {
matchedSender := feature.MakeRandomK8sName("sender")
unmatchedSender := feature.MakeRandomK8sName("sender")
subscriber := feature.MakeRandomK8sName("subscriber")
triggerName := feature.MakeRandomK8sName("viaTrigger")

f := feature.NewFeatureNamed(name)

f.Setup("Install trigger subscriber", eventshub.Install(subscriber, eventshub.StartReceiver))

// Set the Trigger subscriber.
cfg := []manifest.CfgFn{
trigger.WithSubscriber(service.AsKReference(subscriber), ""),
trigger.WithNewFilters(fs.filters),
}

f.Setup("Install trigger", trigger.Install(triggerName, brokerName, cfg...))
f.Setup("Wait for trigger to become ready", trigger.IsReady(triggerName))
f.Setup("Broker is addressable", k8s.IsAddressable(broker.GVR(), brokerName))

f.Requirement("Install matched event sender", eventshub.Install(matchedSender,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.InputEvent(matchedEvent)),
)

f.Requirement("Install unmatched event sender", eventshub.Install(unmatchedSender,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.InputEvent(unmatchedEvent)),
)

f.Beta("Triggers with new filters").
Must("must deliver matched events", OnStore(subscriber).MatchEvent(HasId(matchedEvent.ID())).AtLeast(1)).
MustNot("must not deliver unmatched events", OnStore(subscriber).MatchEvent(HasId(unmatchedEvent.ID())).Not())
f = newEventFilterFeature(eventContexts, fs.filters, f, brokerName)
features = append(features, f)
}

Expand Down

0 comments on commit c8f4624

Please sign in to comment.