Skip to content

Commit

Permalink
Added rekt test for broker eventtype autocreate (knative#7202)
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 authored and mgencur committed Jan 29, 2024
1 parent 7890aeb commit 9f1024a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
17 changes: 17 additions & 0 deletions test/experimental/eventtype_autocreate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"knative.dev/pkg/system"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/knative"
)
Expand All @@ -41,6 +42,22 @@ func TestIMCEventTypeAutoCreate(t *testing.T) {
env.Test(ctx, t, eventtype_autocreate.AutoCreateEventTypesOnIMC())
}

func TestBrokerEventTypeAutoCreate(t *testing.T) {
t.Parallel()

ctx, env := global.Environment(
knative.WithKnativeNamespace(system.Namespace()),
knative.WithLoggingConfig,
knative.WithTracingConfig,
k8s.WithEventListener,
environment.Managed(t),
)
brokerName := feature.MakeRandomK8sName("broker")

env.Prerequisite(ctx, t, InstallMTBroker(brokerName))
env.Test(ctx, t, eventtype_autocreate.AutoCreateEventTypesOnBroker(brokerName))
}

func TestPingSourceEventTypeMatch(t *testing.T) {
t.Parallel()

Expand Down
33 changes: 32 additions & 1 deletion test/experimental/features/eventtype_autocreate/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"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"
)
Expand All @@ -38,7 +39,7 @@ func AutoCreateEventTypesOnIMC() *feature.Feature {
f := feature.NewFeature()

event := cetest.FullEvent()
event.SetType("test.custom.event.type")
event.SetType("test.imc.custom.event.type")

sender := feature.MakeRandomK8sName("sender")
sub := feature.MakeRandomK8sName("subscription")
Expand Down Expand Up @@ -69,6 +70,36 @@ func AutoCreateEventTypesOnIMC() *feature.Feature {
return f
}

func AutoCreateEventTypesOnBroker(brokerName string) *feature.Feature {
f := feature.NewFeature()

event := cetest.FullEvent()
event.SetType("test.broker.custom.event.type")

sender := feature.MakeRandomK8sName("sender")
triggerName := feature.MakeRandomK8sName("trigger")
sink := feature.MakeRandomK8sName("sink")

f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver))
f.Setup("install subscription", trigger.Install(triggerName, brokerName, trigger.WithSubscriber(service.AsKReference(sink), "")))

f.Setup("trigger is ready", trigger.IsReady(triggerName))
f.Setup("broker is addressable", k8s.IsAddressable(broker.GVR(), brokerName))

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

expectedTypes := sets.New(event.Type())

f.Alpha("broker").
Must("deliver events to subscriber", assert.OnStore(sink).MatchEvent(cetest.HasId(event.ID())).AtLeast(1)).
Must("create event type", eventtype.WaitForEventType(eventtype.AssertPresent(expectedTypes)))

return f
}

func AutoCreateEventTypeEventsFromPingSource() *feature.Feature {
source := feature.MakeRandomK8sName("source")
sink := feature.MakeRandomK8sName("sink")
Expand Down

0 comments on commit 9f1024a

Please sign in to comment.