Skip to content

Commit

Permalink
Trigger reconciler tests
Browse files Browse the repository at this point in the history
Signed-off-by: aavarghese <avarghese@us.ibm.com>
  • Loading branch information
aavarghese committed Jan 18, 2022
1 parent 3033844 commit 3365c5e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
10 changes: 10 additions & 0 deletions control-plane/pkg/reconciler/testing/objects_consumergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,13 @@ func ConsumerGroupConsumerSpec(spec kafkainternals.ConsumerSpec) ConsumerGroupOp
cg.Spec.Template.Spec = spec
}
}

func WithDeadLetterSinkURI(uri string) func(cg *kafkainternals.ConsumerGroup) {
return func(cg *kafkainternals.ConsumerGroup) {
u, err := apis.ParseURL(uri)
if err != nil {
panic(err)
}
cg.Status.DeadLetterSinkURI = u
}
}
6 changes: 5 additions & 1 deletion control-plane/pkg/reconciler/trigger/v2/triggerv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ func (r *Reconciler) ReconcileKind(ctx context.Context, trigger *eventing.Trigge
trigger.Status.MarkDependencySucceeded()
} else {
topLevelCondition := cg.GetConditionSet().Manage(cg.GetStatus()).GetTopLevelCondition()
trigger.Status.MarkDependencyFailed(topLevelCondition.Reason, topLevelCondition.Message)
if topLevelCondition == nil {
trigger.Status.MarkDependencyUnknown("failed to reconcile consumer group", "consumer group not ready")
} else {
trigger.Status.MarkDependencyFailed(topLevelCondition.Reason, topLevelCondition.Message)
}
}
trigger.Status.SubscriberURI = cg.Status.SubscriberURI
trigger.Status.MarkSubscriberResolvedSucceeded()
Expand Down
22 changes: 12 additions & 10 deletions control-plane/pkg/reconciler/trigger/v2/triggerv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestReconcileKind(t *testing.T) {
reconcilertesting.WithInitTriggerConditions,
reconcilertesting.WithTriggerBrokerReady(),
withTriggerSubscriberResolvedSucceeded(),
reconcilertesting.WithTriggerDependencyReady(),
reconcilertesting.WithTriggerDependencyUnknown("failed to reconcile consumer group", "consumer group not ready"),
withDeadLetterSinkURI(""),
),
},
Expand Down Expand Up @@ -137,7 +137,7 @@ func TestReconcileKind(t *testing.T) {
reconcilertesting.WithInitTriggerConditions,
reconcilertesting.WithTriggerBrokerReady(),
withTriggerSubscriberResolvedSucceeded(),
reconcilertesting.WithTriggerDependencyReady(),
reconcilertesting.WithTriggerDependencyUnknown("failed to reconcile consumer group", "consumer group not ready"),
withDeadLetterSinkURI(""),
reconcilertesting.WithAnnotation(deliveryOrderAnnotation, string(internals.Ordered)),
),
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestReconcileKind(t *testing.T) {
reconcilertesting.WithInitTriggerConditions,
reconcilertesting.WithTriggerBrokerReady(),
withTriggerSubscriberResolvedSucceeded(),
reconcilertesting.WithTriggerDependencyReady(),
reconcilertesting.WithTriggerDependencyUnknown("failed to reconcile consumer group", "consumer group not ready"),
withDeadLetterSinkURI(""),
reconcilertesting.WithAnnotation(deliveryOrderAnnotation, string(internals.Unordered)),
),
Expand Down Expand Up @@ -225,6 +225,7 @@ func TestReconcileKind(t *testing.T) {
WithConsumerGroupNamespace(triggerNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(newTrigger())),
WithConsumerGroupLabels(nil),
ConsumerGroupReady,
),
},
Key: testKey,
Expand All @@ -244,6 +245,7 @@ func TestReconcileKind(t *testing.T) {
ConsumerDelivery(NewConsumerSpecDelivery(internals.Ordered)),
ConsumerFilters(NewConsumerSpecFilters()),
)),
ConsumerGroupReady,
),
},
},
Expand Down Expand Up @@ -299,7 +301,7 @@ func TestReconcileKind(t *testing.T) {
reconcilertesting.WithInitTriggerConditions,
reconcilertesting.WithTriggerBrokerReady(),
withTriggerSubscriberResolvedSucceeded(),
reconcilertesting.WithTriggerDependencyReady(),
reconcilertesting.WithTriggerDependencyUnknown("failed to reconcile consumer group", "consumer group not ready"),
withDeadLetterSinkURI(""),
),
},
Expand All @@ -325,6 +327,7 @@ func TestReconcileKind(t *testing.T) {
ConsumerDelivery(NewConsumerSpecDelivery(internals.Ordered)),
ConsumerFilters(NewConsumerSpecFilters()),
)),
ConsumerGroupReady,
),
},
Key: testKey,
Expand Down Expand Up @@ -369,7 +372,7 @@ func TestReconcileKind(t *testing.T) {
reconcilertesting.WithInitTriggerConditions,
reconcilertesting.WithTriggerBrokerReady(),
withTriggerSubscriberResolvedSucceeded(),
reconcilertesting.WithTriggerDependencyReady(),
reconcilertesting.WithTriggerDependencyUnknown("failed to reconcile consumer group", "consumer group not ready"),
withDeadLetterSinkURI(""),
),
},
Expand All @@ -382,9 +385,6 @@ func TestReconcileKind(t *testing.T) {
BrokerReady,
),
newTrigger(),
},
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupName(TriggerUUID),
WithConsumerGroupNamespace(triggerNamespace),
Expand All @@ -398,16 +398,18 @@ func TestReconcileKind(t *testing.T) {
ConsumerDelivery(NewConsumerSpecDelivery(internals.Ordered)),
ConsumerFilters(NewConsumerSpecFilters()),
)),
WithDeadLetterSinkURI(url.String()),
),
},
Key: testKey,
WantStatusUpdates: []clientgotesting.UpdateActionImpl{
{
Object: newTrigger(
reconcilertesting.WithInitTriggerConditions,
reconcilertesting.WithTriggerBrokerReady(),
withTriggerSubscriberResolvedSucceeded(),
reconcilertesting.WithTriggerDependencyReady(),
withDeadLetterSinkURI(""),
reconcilertesting.WithTriggerDependencyUnknown("failed to reconcile consumer group", "consumer group not ready"),
withDeadLetterSinkURI(url.String()),
),
},
},
Expand Down

0 comments on commit 3365c5e

Please sign in to comment.