Skip to content

Commit

Permalink
try refactoring test
Browse files Browse the repository at this point in the history
Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 committed Oct 30, 2023
1 parent ff97c1d commit 54078cd
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions test/rekt/features/broker/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.",
Expand All @@ -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")

Expand Down

0 comments on commit 54078cd

Please sign in to comment.