Add comprehensive unit tests for event handler#292
Add comprehensive unit tests for event handler#292GautamBytes wants to merge 2 commits intoopenkruise:masterfrom
Conversation
|
[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 |
Signed-off-by: GautamBytes <manchandanigautam@gmail.com>
742921a to
d0dd578
Compare
Signed-off-by: GautamBytes <manchandanigautam@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #292 +/- ##
==========================================
+ Coverage 47.52% 47.83% +0.30%
==========================================
Files 63 63
Lines 9799 9799
==========================================
+ Hits 4657 4687 +30
+ Misses 4585 4553 -32
- Partials 557 559 +2
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:
|
|
@furykerry @veophi PTAL! |
What this PR does / Why we need it
The MutatingWebhookEventHandler in
pkg/controller/deployment/deployment_event_handler.gocontains critical logic for queueing Deployments but previously lacked unit test coverage. This made it difficult to refactor or protect against regressions.This PR adds a comprehensive and robust test suite to validate the handler's functionality, ensuring stability and correctness.
Key Improvements & Scenarios Covered
Complete Handler Coverage: Tests have been added for all event handler methods (Create, Update, Delete, and Generic).
Content Verification: Tests now verify the content of the enqueued reconcile.Request (i.e., the correct deployment name and namespace), not just that the queue length has changed.
Bulk Enqueue Testing: A scenario with multiple matching deployments is tested to ensure the handler's loop logic is correct.
Error Handling: A new test, TestEnqueueErrorHandling, was added to simulate an API client error and confirm that the handler fails gracefully without adding items to the queue.