-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: add unit test for GenerateScaledObjectName #3892
base: main
Are you sure you want to change the base?
test: add unit test for GenerateScaledObjectName #3892
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: converge The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3892 +/- ##
=============================================
- Coverage 61.99% 49.37% -12.63%
=============================================
Files 188 247 +59
Lines 12634 14909 +2275
Branches 273 0 -273
=============================================
- Hits 7833 7361 -472
- Misses 4187 6792 +2605
- Partials 614 756 +142
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@converge: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func TestGenerateScaledObjectName(t *testing.T) { | ||
type args struct { | ||
obj v1.Object | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
wantPrefix string | ||
wantSuffix types.UID | ||
}{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of the table testing pattern! This is how we normally do unit tests in eventing (as I'm sure you noticed)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you consider having a test in https:/knative-extensions/eventing-kafka-broker/blob/main/control-plane/pkg/reconciler/consumergroup/consumergroup_test.go that would assert that the ConsumerGroup
reconciler creates all KEDA objects when the feature flag is enabeled?
Such test would cover also the GenerateScaledObjectName
since we need to explicitly indicate the object names (and spec), similar to how is done here for Consumer
s
eventing-kafka-broker/control-plane/pkg/reconciler/consumergroup/consumergroup_test.go
Lines 112 to 137 in 865fea6
WantCreates: []runtime.Object{ | |
NewConsumer(1, | |
ConsumerFinalizer(), | |
ConsumerSpec(NewConsumerSpec( | |
ConsumerTopics("t1", "t2"), | |
ConsumerConfigs( | |
ConsumerBootstrapServersConfig(ChannelBootstrapServers), | |
ConsumerGroupIdConfig("my.group.id"), | |
), | |
ConsumerVReplicas(1), | |
ConsumerPlacement(kafkainternals.PodBind{PodName: "p1", PodNamespace: systemNamespace}), | |
)), | |
), | |
NewConsumer(2, | |
ConsumerFinalizer(), | |
ConsumerSpec(NewConsumerSpec( | |
ConsumerTopics("t1", "t2"), | |
ConsumerConfigs( | |
ConsumerBootstrapServersConfig(ChannelBootstrapServers), | |
ConsumerGroupIdConfig("my.group.id"), | |
), | |
ConsumerVReplicas(1), | |
ConsumerPlacement(kafkainternals.PodBind{PodName: "p2", PodNamespace: systemNamespace}), | |
)), | |
), | |
}, |
The benefit is that we don't need to have mocks, while having the benefit of a "unit test" that is fast and doesn't interact with the real k8s API
This Pull Request is stale because it has been open for 90 days with |
Fixes #
Proposed Changes
GenerateScaledObjectName
note: this is a PR to validate how unit tests should be written for knative. Upcoming unit test is for Keda integration.