Skip to content

Commit

Permalink
Make some broker conformance tests decoratable with broker options (#…
Browse files Browse the repository at this point in the history
…6518)

Co-authored-by: Ali Ok <aliok@redhat.com>
  • Loading branch information
knative-prow-robot and aliok authored Sep 8, 2022
1 parent 80bd992 commit 9171ccb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
30 changes: 17 additions & 13 deletions test/rekt/features/broker/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"knative.dev/pkg/ptr"
"knative.dev/reconciler-test/pkg/environment"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/manifest"
"knative.dev/reconciler-test/pkg/state"
"knative.dev/reconciler-test/resources/svc"

Expand All @@ -47,22 +48,22 @@ import (
triggerresources "knative.dev/eventing/test/rekt/resources/trigger"
)

func ControlPlaneConformance(brokerName string) *feature.FeatureSet {
func ControlPlaneConformance(brokerName string, brokerOpts ...manifest.CfgFn) *feature.FeatureSet {
fs := &feature.FeatureSet{
Name: "Knative Broker Specification - Control Plane",
Features: []*feature.Feature{
ControlPlaneBroker(brokerName),
ControlPlaneBroker(brokerName, brokerOpts...),
ControlPlaneTrigger_GivenBroker(brokerName),
ControlPlaneTrigger_GivenBrokerTriggerReady(brokerName),
ControlPlaneTrigger_WithBrokerLifecycle(),
ControlPlaneTrigger_WithBrokerLifecycle(brokerOpts...),
ControlPlaneTrigger_WithValidFilters(brokerName),
ControlPlaneTrigger_WithInvalidFilters(brokerName),
},
}

// Add each feature of event routing and Delivery tests as a new feature
addControlPlaneEventRouting(fs)
addControlPlaneDelivery(fs)
addControlPlaneEventRouting(fs, brokerOpts...)
addControlPlaneDelivery(fs, brokerOpts...)
// TODO: This is not a control plane test, or at best it is a blend with data plane.
// Must("Events that pass the attributes filter MUST include context or extension attributes that match all key-value pairs exactly.", todo)

Expand All @@ -75,15 +76,16 @@ func setBrokerName(name string) feature.StepFn {
}
}

func ControlPlaneBroker(brokerName string) *feature.Feature {
func ControlPlaneBroker(brokerName string, brokerOpts ...manifest.CfgFn) *feature.Feature {
f := feature.NewFeatureNamed("Broker")
bName := feature.MakeRandomK8sName("broker")
sink := feature.MakeRandomK8sName("sink")

f.Setup("Set Broker Name", setBrokerName(bName))

f.Setup("install a service", svc.Install(sink, "app", "rekt"))
brokerOpts := append(brokerresources.WithEnvConfig(), delivery.WithDeadLetterSink(svc.AsKReference(sink), ""))
brokerOpts = append(brokerOpts, brokerresources.WithEnvConfig()...)
brokerOpts = append(brokerOpts, delivery.WithDeadLetterSink(svc.AsKReference(sink), ""))
f.Setup("update broker", broker.Install(bName, brokerOpts...))
f.Setup("broker goes ready", broker.IsReady(bName))

Expand Down Expand Up @@ -151,7 +153,7 @@ func ControlPlaneTrigger_GivenBrokerTriggerReady(brokerName string) *feature.Fea
return f
}

func ControlPlaneTrigger_WithBrokerLifecycle() *feature.Feature {
func ControlPlaneTrigger_WithBrokerLifecycle(brokerOpts ...manifest.CfgFn) *feature.Feature {
f := feature.NewFeatureNamed("Trigger, With Broker Lifecycle")

subscriberName := feature.MakeRandomK8sName("sub")
Expand All @@ -166,12 +168,14 @@ func ControlPlaneTrigger_WithBrokerLifecycle() *feature.Feature {

f.Setup("Set Trigger Name", triggerfeatures.SetTriggerName(triggerName))

brokerOpts = append(brokerOpts, brokerresources.WithEnvConfig()...)

f.Stable("Conformance").
May("A Trigger MAY be created before its assigned Broker exists.",
triggerHasOneBroker).
Should("A Trigger SHOULD progress to Ready when its assigned Broker exists and is Ready.",
func(ctx context.Context, t feature.T) {
brokerresources.Install(brokerName, brokerresources.WithEnvConfig()...)(ctx, t) // Default broker from Env.
brokerresources.Install(brokerName, brokerOpts...)(ctx, t) // Default broker from Env.
brokerresources.IsReady(brokerName)(ctx, t)
triggerresources.IsReady(triggerName)(ctx, t)
})
Expand Down Expand Up @@ -288,7 +292,7 @@ func ControlPlaneTrigger_WithInvalidFilters(brokerName string) *feature.Feature
return f
}

func addControlPlaneDelivery(fs *feature.FeatureSet) {
func addControlPlaneDelivery(fs *feature.FeatureSet, brokerOpts ...manifest.CfgFn) {
for i, tt := range []struct {
name string
brokerDS *v1.DeliverySpec
Expand Down Expand Up @@ -362,7 +366,7 @@ func addControlPlaneDelivery(fs *feature.FeatureSet) {
delivery: tt.t2DS,
failCount: tt.t2FailCount,
}}
prober := createBrokerTriggerTopology(f, brokerName, tt.brokerDS, cfg)
prober := createBrokerTriggerTopology(f, brokerName, tt.brokerDS, cfg, brokerOpts...)

// Send an event into the matrix and hope for the best
prober.SenderFullEvents(1)
Expand Down Expand Up @@ -394,7 +398,7 @@ func addControlPlaneDelivery(fs *feature.FeatureSet) {
}
}

func addControlPlaneEventRouting(fs *feature.FeatureSet) {
func addControlPlaneEventRouting(fs *feature.FeatureSet, brokerOpts ...manifest.CfgFn) {

fullEvent := cetest.FullEvent()
replyEvent := cetest.FullEvent()
Expand Down Expand Up @@ -505,7 +509,7 @@ func addControlPlaneEventRouting(fs *feature.FeatureSet) {
brokerName := fmt.Sprintf("routing-test-%d", i)
f := feature.NewFeatureNamed(fmt.Sprintf("Event Routing Spec - %s", brokerName))
f.Setup("Set Broker Name", setBrokerName(brokerName))
prober := createBrokerTriggerTopology(f, brokerName, nil, tt.config)
prober := createBrokerTriggerTopology(f, brokerName, nil, tt.config, brokerOpts...)

// Send an event into the matrix and hope for the best
// TODO: We need to do some work to get the event types into the Prober.
Expand Down
4 changes: 2 additions & 2 deletions test/rekt/features/broker/topology.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type triggerCfg struct {
// |
// +--[DLQ]--> "dlq" (optional)
//
func createBrokerTriggerTopology(f *feature.Feature, brokerName string, brokerDS *v1.DeliverySpec, triggers []triggerCfg) *eventshub.EventProber {
func createBrokerTriggerTopology(f *feature.Feature, brokerName string, brokerDS *v1.DeliverySpec, triggers []triggerCfg, brokerOpts ...manifest.CfgFn) *eventshub.EventProber {
prober := eventshub.NewProber()

f.Setup("install recorder for broker dlq", prober.ReceiverInstall("brokerdlq"))
brokerOpts := brokerresources.WithEnvConfig()
brokerOpts = append(brokerOpts, brokerresources.WithEnvConfig()...)

if brokerDS != nil {
if brokerDS.DeadLetterSink != nil {
Expand Down

0 comments on commit 9171ccb

Please sign in to comment.