From 16e428360070cc66a4ffea73facd879283c30893 Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Mon, 28 Aug 2023 04:59:00 -0400 Subject: [PATCH] Added rekt test for broker eventtype autocreate (#7202) Signed-off-by: Calum Murray --- .../experimental/eventtype_autocreate_test.go | 17 ++++++++++ .../features/eventtype_autocreate/features.go | 33 ++++++++++++++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/test/experimental/eventtype_autocreate_test.go b/test/experimental/eventtype_autocreate_test.go index 9f4e8859f04..52ed72876a1 100644 --- a/test/experimental/eventtype_autocreate_test.go +++ b/test/experimental/eventtype_autocreate_test.go @@ -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" ) @@ -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() diff --git a/test/experimental/features/eventtype_autocreate/features.go b/test/experimental/features/eventtype_autocreate/features.go index 588741cd33e..d0a9c6be515 100644 --- a/test/experimental/features/eventtype_autocreate/features.go +++ b/test/experimental/features/eventtype_autocreate/features.go @@ -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" ) @@ -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") @@ -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")