Skip to content

Commit

Permalink
moar tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
vaikas committed Mar 18, 2020
1 parent f16285b commit 3980649
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 27 deletions.
9 changes: 8 additions & 1 deletion pkg/apis/eventing/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@ const (
BrokerClassKey = GroupName + "/broker.class"

// ChannelBrokerClassValue is the value we use to specify the
// Broker using channels. As in Broker from this repository.
// Broker using channels. As in Broker from this repository
// pkg/reconciler/broker
ChannelBrokerClassValue = "ChannelBasedBroker"

// MTChannelBrokerClassValue is the value we use to specify the
// Broker using channels, but the resources (ingress,filter) run
// in the system namespace. As in Broker from this repository
// pkg/reconciler/mtbroker
MTChannelBrokerClassValue = "MTChannelBasedBroker"

// ScopeAnnotationKey is the annotation key to indicate
// the scope of the component handling a given resource.
// Valid values are: cluster, namespace, resource.
Expand Down
65 changes: 44 additions & 21 deletions pkg/reconciler/mtbroker/broker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,8 @@ const (
filterContainerName = "filter"
ingressContainerName = "ingress"

triggerChannel channelType = "TriggerChannel"
triggerName = "test-trigger"
triggerUID = "test-trigger-uid"
triggerName = "test-trigger"
triggerUID = "test-trigger-uid"

subscriberURI = "http://example.com/subscriber/"
subscriberKind = "Service"
Expand Down Expand Up @@ -191,6 +190,7 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions,
WithBrokerDeletionTimestamp),
Expand All @@ -203,6 +203,7 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithInitBrokerConditions),
},
WantEvents: []string{
Expand All @@ -214,6 +215,7 @@ func TestReconcile(t *testing.T) {
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithInitBrokerConditions,
WithTriggerChannelFailed("ChannelTemplateFailed", "Error on setting up the ChannelTemplate: Broker.Spec.ChannelTemplate is nil")),
}},
Expand All @@ -224,14 +226,16 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions),
},
WantCreates: []runtime.Object{
createChannel(testNS, triggerChannel, false),
createChannel(testNS, false),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithInitBrokerConditions,
WithBrokerChannel(channel()),
WithTriggerChannelFailed("ChannelFailure", "inducing failure for create inmemorychannels")),
Expand All @@ -252,14 +256,16 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions),
},
WantCreates: []runtime.Object{
createChannel(testNS, triggerChannel, false),
createChannel(testNS, false),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithInitBrokerConditions,
WithBrokerChannel(channel()),
WithTriggerChannelFailed("NoAddress", "Channel does not have an address.")),
Expand All @@ -275,12 +281,14 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions),
createChannel(testNS, triggerChannel, false),
createChannel(testNS, false),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions,
WithTriggerChannelFailed("NoAddress", "Channel does not have an address.")),
Expand All @@ -296,12 +304,14 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions),
createChannel(testNS, triggerChannel, true),
createChannel(testNS, true),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithBrokerReady,
WithBrokerTriggerChannel(createTriggerChannelRef()),
Expand All @@ -319,15 +329,17 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions),
createChannel(testNS, triggerChannel, true),
createChannel(testNS, true),
},
WithReactors: []clientgotesting.ReactionFunc{
InduceFailure("update", "brokers"),
},
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithBrokerReady,
WithBrokerTriggerChannel(createTriggerChannelRef()),
Expand All @@ -347,9 +359,10 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions),
createChannel(testNS, triggerChannel, true),
createChannel(testNS, true),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
WithTriggerSubscriberURI(subscriberURI)),
Expand All @@ -368,6 +381,7 @@ func TestReconcile(t *testing.T) {
WithTriggerStatusSubscriberURI(subscriberURI)),
}, {
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithBrokerReady,
WithBrokerTriggerChannel(createTriggerChannelRef()),
Expand All @@ -385,6 +399,7 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithInitBrokerConditions),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
Expand All @@ -408,6 +423,7 @@ func TestReconcile(t *testing.T) {
WithTriggerStatusSubscriberURI(subscriberURI)),
}, {
Object: NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithInitBrokerConditions,
WithTriggerChannelFailed("ChannelTemplateFailed", "Error on setting up the ChannelTemplate: Broker.Spec.ChannelTemplate is nil")),
}},
Expand All @@ -424,6 +440,7 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions,
WithBrokerFinalizers("brokers.eventing.knative.dev"),
Expand Down Expand Up @@ -452,6 +469,7 @@ func TestReconcile(t *testing.T) {
Key: testKey,
Objects: []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions,
WithBrokerFinalizers("brokers.eventing.knative.dev"),
Expand Down Expand Up @@ -1159,20 +1177,22 @@ func servicePorts(httpInternal int) []corev1.ServicePort {
return svcPorts
}

func createChannel(namespace string, t channelType, ready bool) *unstructured.Unstructured {
func createChannel(namespace string, ready bool) *unstructured.Unstructured {
var labels map[string]interface{}
var annotations map[string]interface{}
var name string
var hostname string
var url string
if t == triggerChannel {
name = fmt.Sprintf("%s-kne-trigger", brokerName)
labels = map[string]interface{}{
eventing.BrokerLabelKey: brokerName,
"eventing.knative.dev/brokerEverything": "true",
}
hostname = triggerChannelHostname
url = fmt.Sprintf("http://%s", triggerChannelHostname)
name = fmt.Sprintf("%s-kne-trigger", brokerName)
labels = map[string]interface{}{
eventing.BrokerLabelKey: brokerName,
"eventing.knative.dev/brokerEverything": "true",
}
annotations = map[string]interface{}{
"eventing.knative.dev/scope": "cluster",
}
hostname = triggerChannelHostname
url = fmt.Sprintf("http://%s", triggerChannelHostname)
if ready {
return &unstructured.Unstructured{
Object: map[string]interface{}{
Expand All @@ -1192,7 +1212,8 @@ func createChannel(namespace string, t channelType, ready bool) *unstructured.Un
"uid": "",
},
},
"labels": labels,
"labels": labels,
"annotations": annotations,
},
"status": map[string]interface{}{
"address": map[string]interface{}{
Expand Down Expand Up @@ -1222,7 +1243,8 @@ func createChannel(namespace string, t channelType, ready bool) *unstructured.Un
"uid": "",
},
},
"labels": labels,
"labels": labels,
"annotations": annotations,
},
},
}
Expand Down Expand Up @@ -1307,14 +1329,15 @@ func makeBroker() *v1alpha1.Broker {
func allBrokerObjectsReadyPlus(objs ...runtime.Object) []runtime.Object {
brokerObjs := []runtime.Object{
NewBroker(brokerName, testNS,
WithBrokerClass(eventing.MTChannelBrokerClassValue),
WithBrokerChannel(channel()),
WithInitBrokerConditions,
WithBrokerReady,
WithBrokerFinalizers("brokers.eventing.knative.dev"),
WithBrokerResourceVersion(""),
WithBrokerTriggerChannel(createTriggerChannelRef()),
WithBrokerAddress(fmt.Sprintf("%s.%s.svc.%s", ingressServiceName, testNS, utils.GetClusterDomainName()))),
createChannel(testNS, triggerChannel, true),
createChannel(testNS, true),
}
return append(brokerObjs[:], objs...)
}
Expand Down
8 changes: 3 additions & 5 deletions pkg/reconciler/mtbroker/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ const (
// controllerAgentName is the string used by this controller to identify
// itself when creating events.
controllerAgentName = "mt-broker-controller"
// BrokerClass is our annotation
brokerClass = "MTChannelBasedBroker"
)

// NewController initializes the controller and is called by the generated code
Expand All @@ -71,9 +69,9 @@ func NewController(
deploymentLister: deploymentInformer.Lister(),
subscriptionLister: subscriptionInformer.Lister(),
triggerLister: triggerInformer.Lister(),
brokerClass: brokerClass,
brokerClass: eventing.MTChannelBrokerClassValue,
}
impl := brokerreconciler.NewImpl(ctx, r, brokerClass)
impl := brokerreconciler.NewImpl(ctx, r, eventing.MTChannelBrokerClassValue)

r.Logger.Info("Setting up event handlers")

Expand All @@ -83,7 +81,7 @@ func NewController(
r.uriResolver = resolver.NewURIResolver(ctx, impl.EnqueueKey)

brokerInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: pkgreconciler.AnnotationFilterFunc(brokerreconciler.ClassAnnotationKey, brokerClass, false /*allowUnset*/),
FilterFunc: pkgreconciler.AnnotationFilterFunc(brokerreconciler.ClassAnnotationKey, eventing.MTChannelBrokerClassValue, false /*allowUnset*/),
Handler: controller.HandleAll(impl.Enqueue),
})

Expand Down

0 comments on commit 3980649

Please sign in to comment.