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()) -}