From 54078cdfb9182e3f7f8407c0519aaa1b0b571b61 Mon Sep 17 00:00:00 2001 From: Calum Murray Date: Mon, 30 Oct 2023 14:50:19 -0400 Subject: [PATCH] try refactoring test Signed-off-by: Calum Murray --- test/rekt/features/broker/data_plane.go | 44 +++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/test/rekt/features/broker/data_plane.go b/test/rekt/features/broker/data_plane.go index 24ad575b0b3..311ec038937 100644 --- a/test/rekt/features/broker/data_plane.go +++ b/test/rekt/features/broker/data_plane.go @@ -19,6 +19,8 @@ package broker import ( "context" + cetest "github.com/cloudevents/sdk-go/v2/test" + "github.com/google/uuid" "knative.dev/eventing/test/rekt/features/knconf" "knative.dev/eventing/test/rekt/resources/broker" @@ -50,9 +52,11 @@ func DataPlaneIngress(brokerName string) *feature.Feature { state.SetOrFail(ctx, t, "brokerName", brokerName) }) + f = withBrokerAcceptsCEVersions(f, brokerName) + f.Stable("Conformance"). - Must("The ingress endpoint(s) MUST conform to at least one of the following versions of the specification: 0.3, 1.0", - brokerAcceptsCEVersions). + //Must("The ingress endpoint(s) MUST conform to at least one of the following versions of the specification: 0.3, 1.0", + // brokerAcceptsCEVersions). May("Other versions MAY be rejected.", brokerRejectsUnknownCEVersion). ShouldNot("The Broker SHOULD NOT perform an upgrade of the produced event's CloudEvents version.", @@ -70,6 +74,42 @@ func DataPlaneIngress(brokerName string) *feature.Feature { return f } +func withBrokerAcceptsCEVersions(f *feature.Feature, brokerName string) *feature.Feature { + uuids := map[string]string{ + uuid.New().String(): "1.0", + uuid.New().String(): "0.3", + } + + for id, version := range uuids { + // We need to use a different source name, otherwise, it will try to update + // the pod, which is immutable. + source := feature.MakeRandomK8sName("source") + event := cetest.FullEvent() + event.SetID(id) + event.SetSpecVersion(version) + f.Setup("Install Source", eventshub.Install(source, + eventshub.StartSenderToResource(broker.GVR(), brokerName), + eventshub.InputEvent(event), + )) + + f.Stable("Conformance").Must("The ingress endpoint(s) MUST conform to at least one of the following versions of the specification: 0.3, 1.0", func(ctx context.Context, t feature.T) { + store := eventshub.StoreFromContext(ctx, source) + // We are looking for two events, one of them is the sent event and the other + // is Response, so correlate them first. We want to make sure the event was sent and that the + // response was what was expected. + events := knconf.Correlate(store.AssertAtLeast(ctx, t, 2, knconf.SentEventMatcher(""))) + for _, e := range events { + // Make sure HTTP response code is 2XX + if e.Response.StatusCode < 200 || e.Response.StatusCode > 299 { + t.Errorf("Expected statuscode 2XX for sequence %d got %d", e.Response.Sequence, e.Response.StatusCode) + } + } + }) + } + + return f +} + func DataPlaneAddressability(brokerName string) *feature.Feature { f := feature.NewFeatureNamed("Broker Addressability")