Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/webhook: unit test resource deletion protection #5499

Conversation

mohamedawnallah
Copy link
Contributor

@mohamedawnallah mohamedawnallah commented Sep 9, 2024

Description

In this commit, we add unit tests for the ValidatingAdmission validation webhook specifically for the resource deletion protection feature. These tests ensure that the webhook correctly handles various admission scenarios:

  • Tests the behavior when decoding the request object fails, verifying that admission is denied with an appropriate error message.
  • Ensures that resources labeled with DeletionProtectionAlways are denied deletion, validating that the error message is returned.
  • Confirms that resources without the deletion protection label are allowed to be deleted without errors.
  • Validates that resources with other labels are not impacted and are allowed to be deleted.
  • Confirms that non-delete operations (e.g., create) are allowed by default.

What type of PR is this?

/kind failing-test
/kind feature

Which issue(s) this PR fixes:
Part of #5491

Does this PR introduce a user-facing change?:

NONE

@karmada-bot karmada-bot added the kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. label Sep 9, 2024
@karmada-bot karmada-bot added kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 9, 2024
@mohamedawnallah mohamedawnallah force-pushed the unitTestResourceDeletionProtectionWebhook branch from 3e2c729 to 664f58a Compare September 9, 2024 00:48
In this commit, we add unit tests for the `ValidatingAdmission` validation webhook
specifically for the resource deletion protection feature. These tests ensure
that the webhook correctly handles various admission scenarios:

- Tests the behavior when decoding the request object fails, verifying that admission
is denied with an appropriate error message.
- Ensures that resources labeled with `DeletionProtectionAlways` are denied deletion,
validating that the error message is returned.
- Confirms that resources without the deletion protection label are allowed to be deleted
without errors.
- Validates that resources with other labels are not impacted and are allowed to be deleted.
- Confirms that non-delete operations (e.g., create) are allowed by default.

Signed-off-by: Mohamed Awnallah <mohamedmohey2352@gmail.com>
@mohamedawnallah mohamedawnallah force-pushed the unitTestResourceDeletionProtectionWebhook branch from 664f58a to fa4a077 Compare September 9, 2024 00:57
@codecov-commenter
Copy link

codecov-commenter commented Sep 9, 2024

⚠️ 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 31.73%. Comparing base (32c2ef7) to head (fa4a077).
Report is 12 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    #5499      +/-   ##
==========================================
+ Coverage   31.70%   31.73%   +0.02%     
==========================================
  Files         643      643              
  Lines       44445    44445              
==========================================
+ Hits        14090    14103      +13     
+ Misses      29325    29312      -13     
  Partials     1030     1030              
Flag Coverage Δ
unittests 31.73% <ø> (+0.02%) ⬆️

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.

Copy link
Member

@XiShanYongYe-Chang XiShanYongYe-Chang left a comment

Choose a reason for hiding this comment

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

Thanks~
/lgtm
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Sep 10, 2024
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: XiShanYongYe-Chang

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

The pull request process is described here

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 10, 2024
@karmada-bot karmada-bot merged commit 2577b5f into karmada-io:master Sep 10, 2024
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/failing-test Categorizes issue or PR as related to a consistently or frequently failing test. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. 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.

4 participants