test: add unit tests for NewPredicateForEndpointSliceCollectController and NewPredicateForEndpointSliceCollectControllerOnAgent#7661
Conversation
…r and NewPredicateForEndpointSliceCollectControllerOnAgent Signed-off-by: Tushar Pandhare <tusharpandharetp@gmail.com>
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 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
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 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 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
|
|
[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 |
There was a problem hiding this comment.
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
NewPredicateForEndpointSliceCollectControllercovering invalid namespace, missing cluster, Pull vs Push sync mode, and update old/new combinations. - Added unit tests for
NewPredicateForEndpointSliceCollectControllerOnAgentcovering 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.
There was a problem hiding this comment.
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.
| 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 | ||
| } |
There was a problem hiding this comment.
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.
| 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) | |
| } |
| 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 | ||
| } |
There was a problem hiding this comment.
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.
| 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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
/kind cleanup
What this PR does / why we need it:
Add unit tests for two functions in
pkg/util/helper/predicate.gothat lacked test coverage:NewPredicateForEndpointSliceCollectController— tests cluster name error, cluster not found, Pull mode, Push mode, and Update old/new combinationsNewPredicateForEndpointSliceCollectControllerOnAgent— tests cluster name error, unmatched cluster name, matched cluster name, and Update old/new combinationsWhich 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