Skip to content

test: add unit tests for NewPredicateForEndpointSliceCollectController and NewPredicateForEndpointSliceCollectControllerOnAgent#7661

Open
tushar-pandhare wants to merge 1 commit into
karmada-io:masterfrom
tushar-pandhare:test-predicate-endpointslice
Open

test: add unit tests for NewPredicateForEndpointSliceCollectController and NewPredicateForEndpointSliceCollectControllerOnAgent#7661
tushar-pandhare wants to merge 1 commit into
karmada-io:masterfrom
tushar-pandhare:test-predicate-endpointslice

Conversation

@tushar-pandhare

Copy link
Copy Markdown
Contributor

/kind cleanup

What this PR does / why we need it:
Add unit tests for two functions in pkg/util/helper/predicate.go that lacked test coverage:

  • NewPredicateForEndpointSliceCollectController — tests cluster name error, cluster not found, Pull mode, Push mode, and Update old/new combinations
  • NewPredicateForEndpointSliceCollectControllerOnAgent — tests cluster name error, unmatched cluster name, matched cluster name, and Update old/new combinations

Which issue(s) this PR fixes:
Fixes: #7660

Special notes for your reviewer:
All existing tests pass with the new additions:
ok github.com/karmada-io/karmada/pkg/util/helper

Does this PR introduce a user-facing change?:
NONE

…r and NewPredicateForEndpointSliceCollectControllerOnAgent

Signed-off-by: Tushar Pandhare <tusharpandharetp@gmail.com>
Copilot AI review requested due to automatic review settings June 23, 2026 09:01
@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jun 23, 2026
@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 improves the reliability of the codebase by introducing unit tests for predicate functions used in the EndpointSlice collection controller. These tests ensure that event filtering behaves as expected under different cluster configurations and state transitions, addressing previously uncovered code paths.

Highlights

  • Unit Test Coverage: Added comprehensive unit tests for NewPredicateForEndpointSliceCollectController and NewPredicateForEndpointSliceCollectControllerOnAgent to ensure proper filtering logic.
  • Edge Case Validation: Included test scenarios covering cluster name errors, missing clusters, sync mode variations (Pull/Push), and various update event combinations.
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 the 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 counterproductive. 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

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

@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds unit tests to cover previously untested event predicate helpers used by the EndpointSliceCollectController logic, improving confidence in behavior across error paths and Push/Pull or match/unmatch scenarios.

Changes:

  • Added unit tests for NewPredicateForEndpointSliceCollectController covering invalid namespace, missing cluster, Pull vs Push sync mode, and update old/new combinations.
  • Added unit tests for NewPredicateForEndpointSliceCollectControllerOnAgent covering invalid namespace, cluster-name match/unmatch, and update old/new combinations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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

Copy link
Copy Markdown

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 NewPredicateForEndpointSliceCollectController and NewPredicateForEndpointSliceCollectControllerOnAgent in pkg/util/helper/predicate_test.go. The feedback recommends removing the return statements after t.Errorf in the table-driven tests to ensure all assertions (Create, Update, Delete, and Generic) are executed and reported even if one fails.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +707 to +722
if got := pred.Create(event.CreateEvent{Object: tt.args.obj}); got != tt.want.create {
t.Errorf("Create() got = %v, want %v", got, tt.want.create)
return
}
if got := pred.Update(event.UpdateEvent{ObjectOld: tt.args.obj, ObjectNew: tt.args.obj}); got != tt.want.update {
t.Errorf("Update() got = %v, want %v", got, tt.want.update)
return
}
if got := pred.Delete(event.DeleteEvent{Object: tt.args.obj}); got != tt.want.delete {
t.Errorf("Delete() got = %v, want %v", got, tt.want.delete)
return
}
if got := pred.Generic(event.GenericEvent{Object: tt.args.obj}); got != tt.want.generic {
t.Errorf("Generic() got = %v, want %v", got, tt.want.generic)
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

In table-driven tests, using return after a non-fatal assertion failure (t.Errorf) is discouraged. It prevents subsequent independent assertions (like Update, Delete, and Generic) from running, which hides other potential failures and makes debugging harder. Removing the return statements allows all assertions to be evaluated and reported in a single test run.

Suggested change
if got := pred.Create(event.CreateEvent{Object: tt.args.obj}); got != tt.want.create {
t.Errorf("Create() got = %v, want %v", got, tt.want.create)
return
}
if got := pred.Update(event.UpdateEvent{ObjectOld: tt.args.obj, ObjectNew: tt.args.obj}); got != tt.want.update {
t.Errorf("Update() got = %v, want %v", got, tt.want.update)
return
}
if got := pred.Delete(event.DeleteEvent{Object: tt.args.obj}); got != tt.want.delete {
t.Errorf("Delete() got = %v, want %v", got, tt.want.delete)
return
}
if got := pred.Generic(event.GenericEvent{Object: tt.args.obj}); got != tt.want.generic {
t.Errorf("Generic() got = %v, want %v", got, tt.want.generic)
return
}
if got := pred.Create(event.CreateEvent{Object: tt.args.obj}); got != tt.want.create {
t.Errorf("Create() got = %v, want %v", got, tt.want.create)
}
if got := pred.Update(event.UpdateEvent{ObjectOld: tt.args.obj, ObjectNew: tt.args.obj}); got != tt.want.update {
t.Errorf("Update() got = %v, want %v", got, tt.want.update)
}
if got := pred.Delete(event.DeleteEvent{Object: tt.args.obj}); got != tt.want.delete {
t.Errorf("Delete() got = %v, want %v", got, tt.want.delete)
}
if got := pred.Generic(event.GenericEvent{Object: tt.args.obj}); got != tt.want.generic {
t.Errorf("Generic() got = %v, want %v", got, tt.want.generic)
}

Comment on lines +815 to +830
if got := pred.Create(event.CreateEvent{Object: tt.obj}); got != tt.want.create {
t.Errorf("Create() got = %v, want %v", got, tt.want.create)
return
}
if got := pred.Update(event.UpdateEvent{ObjectOld: tt.obj, ObjectNew: tt.obj}); got != tt.want.update {
t.Errorf("Update() got = %v, want %v", got, tt.want.update)
return
}
if got := pred.Delete(event.DeleteEvent{Object: tt.obj}); got != tt.want.delete {
t.Errorf("Delete() got = %v, want %v", got, tt.want.delete)
return
}
if got := pred.Generic(event.GenericEvent{Object: tt.obj}); got != tt.want.generic {
t.Errorf("Generic() got = %v, want %v", got, tt.want.generic)
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

Similarly, avoid using return after t.Errorf in this table-driven test to ensure that all independent assertions (Update, Delete, and Generic) are executed and reported even if one of them fails.

Suggested change
if got := pred.Create(event.CreateEvent{Object: tt.obj}); got != tt.want.create {
t.Errorf("Create() got = %v, want %v", got, tt.want.create)
return
}
if got := pred.Update(event.UpdateEvent{ObjectOld: tt.obj, ObjectNew: tt.obj}); got != tt.want.update {
t.Errorf("Update() got = %v, want %v", got, tt.want.update)
return
}
if got := pred.Delete(event.DeleteEvent{Object: tt.obj}); got != tt.want.delete {
t.Errorf("Delete() got = %v, want %v", got, tt.want.delete)
return
}
if got := pred.Generic(event.GenericEvent{Object: tt.obj}); got != tt.want.generic {
t.Errorf("Generic() got = %v, want %v", got, tt.want.generic)
return
}
if got := pred.Create(event.CreateEvent{Object: tt.obj}); got != tt.want.create {
t.Errorf("Create() got = %v, want %v", got, tt.want.create)
}
if got := pred.Update(event.UpdateEvent{ObjectOld: tt.obj, ObjectNew: tt.obj}); got != tt.want.update {
t.Errorf("Update() got = %v, want %v", got, tt.want.update)
}
if got := pred.Delete(event.DeleteEvent{Object: tt.obj}); got != tt.want.delete {
t.Errorf("Delete() got = %v, want %v", got, tt.want.delete)
}
if got := pred.Generic(event.GenericEvent{Object: tt.obj}); got != tt.want.generic {
t.Errorf("Generic() got = %v, want %v", got, tt.want.generic)
}

@codecov-commenter

Copy link
Copy Markdown

⚠️ 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 42.12%. Comparing base (1ae5ac6) to head (f387125).
⚠️ Report is 21 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    #7661      +/-   ##
==========================================
- Coverage   42.15%   42.12%   -0.04%     
==========================================
  Files         879      879              
  Lines       54669    54827     +158     
==========================================
+ Hits        23047    23097      +50     
- Misses      29875    29983     +108     
  Partials     1747     1747              
Flag Coverage Δ
unittests 42.12% <ø> (-0.04%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

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.

test: add unit tests for NewPredicateForEndpointSliceCollectController and NewPredicateForEndpointSliceCollectControllerOnAgent

4 participants