Skip to content

Commit

Permalink
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 18, 2024
1 parent 9af5bf2 commit 1427344
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ func TestReconcileKind(t *testing.T) {
Name: "Consumers in multiple pods, with pods pending and unknown phase",
Objects: []runtime.Object{
NewService(),
NewDispatcherPod("p1", PodLabel(kafkainternals.SourceStatefulSetName), PodPending()),
NewDispatcherPod("p2", PodLabel(kafkainternals.SourceStatefulSetName)),
NewDispatcherPod("p1", PodLabel("app", kafkainternals.SourceStatefulSetName), DispatcherLabel(), PodPending()),
NewDispatcherPod("p2", PodLabel("app", kafkainternals.SourceStatefulSetName), DispatcherLabel()),
NewConsumerGroup(
ConsumerGroupConsumerSpec(NewConsumerSpec(
ConsumerTopics("t1", "t2"),
Expand Down Expand Up @@ -1723,6 +1723,10 @@ func TestReconcileKind(t *testing.T) {

}

func DispatcherLabel() PodOption {
return PodLabel("app.kubernetes.io/kind", "kafka-dispatcher")
}

func TestReconcileKindNoAutoscaler(t *testing.T) {

tt := TableTest{
Expand Down
3 changes: 2 additions & 1 deletion control-plane/pkg/reconciler/testing/objects_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,8 @@ func BrokerDispatcherPod(namespace string, annotations map[string]string) runtim
Namespace: namespace,
Annotations: annotations,
Labels: map[string]string{
"app": base.BrokerDispatcherLabel,
"app": base.BrokerDispatcherLabel,
"app.kubernetes.io/kind": "kafka-dispatcher",
},
},
Status: corev1.PodStatus{
Expand Down
3 changes: 2 additions & 1 deletion control-plane/pkg/reconciler/testing/objects_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func ChannelDispatcherPod(namespace string, annotations map[string]string) runti
Namespace: namespace,
Annotations: annotations,
Labels: map[string]string{
"app": base.ChannelDispatcherLabel,
"app": base.ChannelDispatcherLabel,
"app.kubernetes.io/kind": "kafka-dispatcher",
},
},
Status: corev1.PodStatus{
Expand Down
4 changes: 2 additions & 2 deletions control-plane/pkg/reconciler/testing/objects_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,12 +616,12 @@ func NewDispatcherPod(name string, options ...PodOption) *corev1.Pod {
return p
}

func PodLabel(value string) PodOption {
func PodLabel(key, value string) PodOption {
return func(pod *corev1.Pod) {
if pod.Labels == nil {
pod.Labels = make(map[string]string, 2)
}
pod.Labels["app"] = value
pod.Labels[key] = value
}
}

Expand Down
8 changes: 5 additions & 3 deletions control-plane/pkg/reconciler/testing/objects_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/utils/pointer"
"knative.dev/eventing-kafka-broker/control-plane/pkg/apis/bindings/v1beta1"
sources "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"
eventingduck "knative.dev/eventing/pkg/apis/duck/v1"
"knative.dev/eventing/pkg/apis/feature"
"knative.dev/eventing/pkg/eventingtls/eventingtlstesting"
"knative.dev/pkg/apis"
duckv1 "knative.dev/pkg/apis/duck/v1"

"knative.dev/eventing-kafka-broker/control-plane/pkg/apis/bindings/v1beta1"
sources "knative.dev/eventing-kafka-broker/control-plane/pkg/apis/sources/v1beta1"

"knative.dev/eventing-kafka-broker/control-plane/pkg/contract"
"knative.dev/eventing-kafka-broker/control-plane/pkg/reconciler/base"
)
Expand Down Expand Up @@ -215,7 +216,8 @@ func SourceDispatcherPod(namespace string, annotations map[string]string) runtim
Namespace: namespace,
Annotations: annotations,
Labels: map[string]string{
"app": base.SourceDispatcherLabel,
"app": base.SourceDispatcherLabel,
"app.kubernetes.io/kind": "kafka-dispatcher",
},
},
Status: corev1.PodStatus{
Expand Down

0 comments on commit 1427344

Please sign in to comment.