Add unit tests for scheduler util functions and ClusterAccessCredentialChanged#7378
Add unit tests for scheduler util functions and ClusterAccessCredentialChanged#7378archy-rock3t-cloud wants to merge 2 commits intokarmada-io:masterfrom
Conversation
…alChanged Signed-off-by: Artem Muterko <artem@sopho.tech>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on improving the test coverage for critical utility functions within the scheduler and cluster management modules. By adding these unit tests, the codebase gains better verification for cluster preference calculations, replica handling, and credential change detection, ensuring more robust behavior in the scheduling and cluster registration workflows. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces unit tests for several utility functions. Specifically, it adds tests for getDefaultWeightPreference and removeZeroReplicasCluster in the scheduler core utilities, and ClusterAccessCredentialChanged in the cluster utilities. A review comment suggests simplifying the test logic in Test_removeZeroReplicasCluster by removing a redundant length check, allowing reflect.DeepEqual to handle empty slice comparisons more effectively.
| if len(got) == 0 && len(tt.want) == 0 { | ||
| return | ||
| } |
There was a problem hiding this comment.
The check if len(got) == 0 && len(tt.want) == 0 { return } is redundant. Since removeZeroReplicasCluster is implemented using make, it returns a non-nil empty slice for empty results. The test cases also define want as a non-nil empty slice []workv1alpha2.TargetCluster{}. Removing this check allows reflect.DeepEqual to perform a more robust comparison (ensuring both are non-nil) and maintains consistency with other tests in this file, such as Test_getDefaultWeightPreference.
| if len(got) == 0 && len(tt.want) == 0 { | |
| return | |
| } | |
| if !reflect.DeepEqual(got, tt.want) { | |
| t.Errorf("removeZeroReplicasCluster() = %v, want %v", got, tt.want) | |
| } |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7378 +/- ##
==========================================
- Coverage 42.15% 41.94% -0.22%
==========================================
Files 875 879 +4
Lines 53603 54324 +721
==========================================
+ Hits 22596 22785 +189
- Misses 29308 29817 +509
- Partials 1699 1722 +23
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Artem Muterko <artem@sopho.tech>
|
Thanks for the review — removed the redundant length guard, |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Add unit tests for scheduler util functions and ClusterAccessCredentialChanged.
Does this PR introduce a user-facing change?: