Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
pierDipi committed Sep 20, 2023
1 parent e044d1b commit 137644f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
13 changes: 13 additions & 0 deletions control-plane/pkg/reconciler/consumergroup/consumergroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand All @@ -119,6 +120,7 @@ func TestReconcileKind(t *testing.T) {
)),
),
NewConsumer(2,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -194,6 +196,7 @@ func TestReconcileKind(t *testing.T) {
NewConfigMapWithBinaryData(systemNamespace, "p1", nil, DispatcherPodAsOwnerReference("p1")),
NewConfigMapWithBinaryData(systemNamespace, "p2", nil, DispatcherPodAsOwnerReference("p2")),
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand All @@ -205,6 +208,7 @@ func TestReconcileKind(t *testing.T) {
)),
),
NewConsumer(2,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -402,6 +406,7 @@ func TestReconcileKind(t *testing.T) {
WantErr: false,
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -525,6 +530,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -871,6 +877,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -1112,6 +1119,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -1197,6 +1205,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -1290,6 +1299,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -1411,6 +1421,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down Expand Up @@ -1529,6 +1540,7 @@ func TestReconcileKind(t *testing.T) {
},
WantCreates: []runtime.Object{
NewConsumer(1,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand All @@ -1540,6 +1552,7 @@ func TestReconcileKind(t *testing.T) {
)),
),
NewConsumer(2,
ConsumerFinalizer(),
ConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
ConsumerConfigs(
Expand Down
11 changes: 11 additions & 0 deletions control-plane/pkg/reconciler/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -163,6 +164,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -216,6 +218,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -272,6 +275,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -327,6 +331,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -430,6 +435,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -557,6 +563,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -638,6 +645,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -696,6 +704,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -1389,6 +1398,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down Expand Up @@ -1442,6 +1452,7 @@ func TestReconcileKind(t *testing.T) {
Key: testKey,
WantCreates: []runtime.Object{
NewConsumerGroup(
WithConsumerGroupFinalizer(),
WithConsumerGroupName(SourceUUID),
WithConsumerGroupNamespace(SourceNamespace),
WithConsumerGroupOwnerRef(kmeta.NewControllerRef(NewSource())),
Expand Down
6 changes: 6 additions & 0 deletions control-plane/pkg/reconciler/testing/objects_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,9 @@ func ConsumerDeletedTimeStamp() ConsumerOption {
WithDeletedTimeStamp(c)
}
}

func ConsumerFinalizer() ConsumerOption {
return func(c *kafkainternals.Consumer) {
c.Finalizers = []string{"consumers.internal.kafka.eventing.knative.dev"}
}
}
6 changes: 6 additions & 0 deletions control-plane/pkg/reconciler/testing/objects_consumergroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ func WithConsumerGroupLabels(labels map[string]string) ConsumerGroupOption {
}
}

func WithConsumerGroupFinalizer() ConsumerGroupOption {
return func(cg *kafkainternals.ConsumerGroup) {
cg.Finalizers = []string{"consumergroups.internal.kafka.eventing.knative.dev"}
}
}

func ConsumerGroupReplicas(replicas int32) ConsumerGroupOption {
return func(cg *kafkainternals.ConsumerGroup) {
cg.Spec.Replicas = pointer.Int32(replicas)
Expand Down

0 comments on commit 137644f

Please sign in to comment.