Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <[email protected]>
  • Loading branch information
pierDipi committed Nov 7, 2024
1 parent ac48041 commit 83f210b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/reconciler/broker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import (
eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1"
eventingv1alpha1 "knative.dev/eventing/pkg/apis/eventing/v1alpha1"
"knative.dev/eventing/pkg/apis/feature"
v1 "knative.dev/eventing/pkg/apis/messaging/v1"
"knative.dev/eventing/pkg/auth"
fakeeventingclient "knative.dev/eventing/pkg/client/injection/client/fake"
"knative.dev/eventing/pkg/client/injection/ducks/duck/v1/channelable"
Expand Down Expand Up @@ -405,6 +406,48 @@ func TestReconcile(t *testing.T) {
WithDLSNotConfigured(),
WithBrokerEventPoliciesReadyBecauseOIDCDisabled()),
}},
}, {
Name: "Propagate annotations",
Key: testKey,
Objects: []runtime.Object{
makeDLSServiceAsUnstructured(),
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerConfig(config()),
WithInitBrokerConditions,
WithBrokerAnnotation(v1.AsyncHandlerAnnotation, "true")),
createChannel(withChannelReady),
imcConfigMap(),
NewEndpoints(filterServiceName, systemNS,
WithEndpointsLabels(FilterLabels()),
WithEndpointsAddresses(corev1.EndpointAddress{IP: "127.0.0.1"})),
NewEndpoints(ingressServiceName, systemNS,
WithEndpointsLabels(IngressLabels()),
WithEndpointsAddresses(corev1.EndpointAddress{IP: "127.0.0.1"})),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerConfig(config()),
WithBrokerAnnotation(v1.AsyncHandlerAnnotation, "true"),
WithBrokerReady,
WithDLSNotConfigured(),
WithBrokerAddressURI(brokerAddress),
WithChannelAddressAnnotation(triggerChannelURL),
WithChannelAPIVersionAnnotation(triggerChannelAPIVersion),
WithChannelKindAnnotation(triggerChannelKind),
WithChannelNameAnnotation(triggerChannelName),
WithBrokerEventPoliciesReadyBecauseOIDCDisabled()),
}},
WantPatches: []clientgotesting.PatchActionImpl{
{
ActionImpl: clientgotesting.ActionImpl{
Namespace: testNS,
},
Name: fmt.Sprintf("%s-kne-trigger", brokerName),
Patch: []byte(`[{"op":"add","path":"/metadata/annotations/messaging.knative.dev~1async-handler","value":"` + "true" + `"}]`),
},
},
}, {
Name: "Successful Reconciliation with a Channel with CA certs",
Key: testKey,
Expand Down
9 changes: 9 additions & 0 deletions pkg/reconciler/testing/v1/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ func WithBrokerFinalizers(finalizers ...string) BrokerOption {
}
}

func WithBrokerAnnotation(key, value string) BrokerOption {
return func(b *v1.Broker) {
if b.Annotations == nil {
b.Annotations = map[string]string{}
}
b.Annotations[key] = value
}
}

func WithBrokerResourceVersion(rv string) BrokerOption {
return func(b *v1.Broker) {
b.ResourceVersion = rv
Expand Down

0 comments on commit 83f210b

Please sign in to comment.