Skip to content

Add unit tests for scheduler util functions and ClusterAccessCredentialChanged#7378

Open
archy-rock3t-cloud wants to merge 2 commits intokarmada-io:masterfrom
sophotechlabs:test/add-unit-tests
Open

Add unit tests for scheduler util functions and ClusterAccessCredentialChanged#7378
archy-rock3t-cloud wants to merge 2 commits intokarmada-io:masterfrom
sophotechlabs:test/add-unit-tests

Conversation

@archy-rock3t-cloud
Copy link
Copy Markdown

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?:

NONE

…alChanged

Signed-off-by: Artem Muterko <artem@sopho.tech>
Copilot AI review requested due to automatic review settings April 9, 2026 20:01
@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Apr 9, 2026
@karmada-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign xishanyongye-chang for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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

  • Scheduler Utilities Testing: Added comprehensive unit tests for getDefaultWeightPreference and removeZeroReplicasCluster in the scheduler core package.
  • Cluster Credential Validation: Introduced unit tests for ClusterAccessCredentialChanged to verify detection of changes in API endpoints, TLS settings, and proxy configurations.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 9, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread pkg/scheduler/core/util_test.go Outdated
Comment on lines +144 to +146
if len(got) == 0 && len(tt.want) == 0 {
return
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 9, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.94%. Comparing base (ba0f291) to head (31d5cc6).
⚠️ Report is 54 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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     
Flag Coverage Δ
unittests 41.94% <ø> (-0.22%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Artem Muterko <artem@sopho.tech>
@archy-rock3t-cloud
Copy link
Copy Markdown
Author

Thanks for the review — removed the redundant length guard, reflect.DeepEqual handles the empty-slice case correctly since both got and want are non-nil empty slices from make(). /assign @XiShanYongYe-Chang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants