From c8d12c3f387eae6d7f7378f0d07b42f2ae164ef7 Mon Sep 17 00:00:00 2001 From: Leo Li Date: Thu, 24 Aug 2023 15:31:57 -0400 Subject: [PATCH] Move eventtype rekttest pingsource to experiment (#7180) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix the merge conflict and fix the logical error in the test Signed-off-by: Leo Li * Add the auto eventType creation support Signed-off-by: Leo Li * reformat and remove the comments Signed-off-by: Leo Li * Remove the assertReference function Signed-off-by: Leo Li * fix reviewDog issue Signed-off-by: Leo Li * Update test/rekt/resources/eventtype/eventtype.go Co-authored-by: Calum Murray * fix reviewDog issue Signed-off-by: Leo Li * Move the test to experimental rekt Signed-off-by: Leo Li * Remove the eventtype test from the pingsource rekt test Signed-off-by: Leo Li * Rename the test name to make it more intuitive Signed-off-by: Leo Li * Revert the unit test change Signed-off-by: Leo Li * Format fix Signed-off-by: Leo Li * format fix Signed-off-by: Leo Li * Fix Christoph's comment Signed-off-by: Leo Li * go imports Signed-off-by: Leo Li * Update test/experimental/features/eventtype_autocreation/eventtype.go Co-authored-by: Christoph Stäbler * Update test/experimental/eventtype_autocreation_test.go Co-authored-by: Christoph Stäbler * Apply suggestions from code review Co-authored-by: Christoph Stäbler * Change the name of the file Signed-off-by: Leo Li * Update the deprecated string Signed-off-by: Leo Li * Update test/rekt/features/pingsource/features.go Co-authored-by: Calum Murray * Manually merge the chanhges from Calum's ticket Signed-off-by: Leo Li * Manually merge the chanhges from Calum's ticket Signed-off-by: Leo Li --------- Signed-off-by: Leo Li Co-authored-by: Calum Murray Co-authored-by: Christoph Stäbler Co-authored-by: Matthias Wessendorf --- .../experimental/eventtype_autocreate_test.go | 14 ++++++ .../features/eventtype_autocreate/features.go | 49 +++++++++++++++++++ test/rekt/features/pingsource/features.go | 15 +++--- test/rekt/pingsource_test.go | 16 ------ 4 files changed, 71 insertions(+), 23 deletions(-) diff --git a/test/experimental/eventtype_autocreate_test.go b/test/experimental/eventtype_autocreate_test.go index b64404bcc80..9f4e8859f04 100644 --- a/test/experimental/eventtype_autocreate_test.go +++ b/test/experimental/eventtype_autocreate_test.go @@ -40,3 +40,17 @@ func TestIMCEventTypeAutoCreate(t *testing.T) { env.Test(ctx, t, eventtype_autocreate.AutoCreateEventTypesOnIMC()) } + +func TestPingSourceEventTypeMatch(t *testing.T) { + t.Parallel() + + ctx, env := global.Environment( + knative.WithKnativeNamespace(system.Namespace()), + knative.WithLoggingConfig, + knative.WithTracingConfig, + k8s.WithEventListener, + environment.Managed(t), + ) + + env.Test(ctx, t, eventtype_autocreate.AutoCreateEventTypeEventsFromPingSource()) +} diff --git a/test/experimental/features/eventtype_autocreate/features.go b/test/experimental/features/eventtype_autocreate/features.go index a2248e30ab2..588741cd33e 100644 --- a/test/experimental/features/eventtype_autocreate/features.go +++ b/test/experimental/features/eventtype_autocreate/features.go @@ -14,14 +14,23 @@ limitations under the License. package eventtype_autocreate import ( + "context" + + "github.com/cloudevents/sdk-go/v2/test" cetest "github.com/cloudevents/sdk-go/v2/test" "k8s.io/apimachinery/pkg/util/sets" + sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1" + "knative.dev/eventing/test/rekt/resources/broker" "knative.dev/eventing/test/rekt/resources/channel_impl" "knative.dev/eventing/test/rekt/resources/eventtype" + "knative.dev/eventing/test/rekt/resources/pingsource" "knative.dev/eventing/test/rekt/resources/subscription" + "knative.dev/eventing/test/rekt/resources/trigger" + duckv1 "knative.dev/pkg/apis/duck/v1" "knative.dev/reconciler-test/pkg/eventshub" "knative.dev/reconciler-test/pkg/eventshub/assert" "knative.dev/reconciler-test/pkg/feature" + "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/service" ) @@ -59,3 +68,43 @@ func AutoCreateEventTypesOnIMC() *feature.Feature { return f } + +func AutoCreateEventTypeEventsFromPingSource() *feature.Feature { + source := feature.MakeRandomK8sName("source") + sink := feature.MakeRandomK8sName("sink") + via := feature.MakeRandomK8sName("via") + + f := new(feature.Feature) + + //Install the broker + brokerName := feature.MakeRandomK8sName("broker") + f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...)) + f.Setup("broker is ready", broker.IsReady(brokerName)) + f.Setup("broker is addressable", broker.IsAddressable(brokerName)) + f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiver)) + f.Setup("install trigger", trigger.Install(via, brokerName, trigger.WithSubscriber(service.AsKReference(sink), ""))) + f.Setup("trigger goes ready", trigger.IsReady(via)) + + f.Requirement("install pingsource", func(ctx context.Context, t feature.T) { + brokeruri, err := broker.Address(ctx, brokerName) + if err != nil { + t.Error("failed to get address of broker", err) + } + cfg := []manifest.CfgFn{ + pingsource.WithSink(&duckv1.Destination{URI: brokeruri.URL, CACerts: brokeruri.CACerts}), + pingsource.WithData("text/plain", "hello, world!"), + } + pingsource.Install(source, cfg...)(ctx, t) + }) + f.Requirement("PingSource goes ready", pingsource.IsReady(source)) + + expectedCeTypes := sets.New(sourcesv1.PingSourceEventType) + + f.Stable("pingsource as event source"). + Must("delivers events on broker with URI", assert.OnStore(sink).MatchEvent( + test.HasType(sourcesv1.PingSourceEventType)).AtLeast(1)). + Must("PingSource test eventtypes match", eventtype.WaitForEventType( + eventtype.AssertPresent(expectedCeTypes))) + + return f +} diff --git a/test/rekt/features/pingsource/features.go b/test/rekt/features/pingsource/features.go index 33cbcc279e3..d16f4fa36a2 100644 --- a/test/rekt/features/pingsource/features.go +++ b/test/rekt/features/pingsource/features.go @@ -18,27 +18,28 @@ package pingsource import ( "context" - - "github.com/cloudevents/sdk-go/v2/test" + "k8s.io/apimachinery/pkg/util/sets" + sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1" + "knative.dev/eventing/test/rekt/resources/broker" + "knative.dev/eventing/test/rekt/resources/eventtype" + "knative.dev/eventing/test/rekt/resources/trigger" duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/reconciler-test/pkg/manifest" + + "github.com/cloudevents/sdk-go/v2/test" "knative.dev/reconciler-test/pkg/environment" "knative.dev/reconciler-test/pkg/eventshub" "knative.dev/reconciler-test/pkg/feature" - "knative.dev/reconciler-test/pkg/manifest" "knative.dev/reconciler-test/pkg/resources/service" "knative.dev/reconciler-test/pkg/eventshub/assert" eventassert "knative.dev/reconciler-test/pkg/eventshub/assert" - sourcesv1 "knative.dev/eventing/pkg/apis/sources/v1" "knative.dev/eventing/test/rekt/features" "knative.dev/eventing/test/rekt/features/featureflags" "knative.dev/eventing/test/rekt/features/source" - "knative.dev/eventing/test/rekt/resources/broker" - "knative.dev/eventing/test/rekt/resources/eventtype" "knative.dev/eventing/test/rekt/resources/pingsource" - "knative.dev/eventing/test/rekt/resources/trigger" ) func SendsEventsWithSinkRef() *feature.Feature { diff --git a/test/rekt/pingsource_test.go b/test/rekt/pingsource_test.go index e2a3277daa1..fda0c7e9e79 100644 --- a/test/rekt/pingsource_test.go +++ b/test/rekt/pingsource_test.go @@ -21,7 +21,6 @@ package rekt import ( "testing" - "time" "knative.dev/pkg/system" "knative.dev/reconciler-test/pkg/environment" @@ -90,18 +89,3 @@ func TestPingSourceWithCloudEventData(t *testing.T) { env.Test(ctx, t, pingsource.SendsEventsWithCloudEventData()) } - -func TestPingSourceWithEventTypes(t *testing.T) { - t.Parallel() - - ctx, env := global.Environment( - knative.WithKnativeNamespace(system.Namespace()), - knative.WithLoggingConfig, - knative.WithTracingConfig, - k8s.WithEventListener, - environment.Managed(t), - environment.WithPollTimings(5*time.Second, 2*time.Minute), - ) - - env.Test(ctx, t, pingsource.SendsEventsWithEventTypes()) -}