Skip to content

Conversation

@GautamBytes
Copy link
Contributor

What this PR does / Why we need it
The utility functions in pkg/webhook/util/util.go are responsible for configuring the webhook from environment variables. These functions previously lacked unit test coverage, making it hard to verify their behavior or prevent future regressions.

This PR adds unit tests to ensure this critical configuration logic is reliable and works as expected.

Key Scenarios Covered

  • Functions correctly return a default value when an environment variable is not set.
  • Functions correctly return the value from a set environment variable.
  • The GetPort function is tested for both its default behavior and for correctly parsing a valid integer from the WEBHOOK_PORT environment variable.

@kruise-bot kruise-bot requested review from FillZpp and zmberg July 14, 2025 16:08
@kruise-bot
Copy link

[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 zmberg for approval by writing /assign @zmberg in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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

Signed-off-by: GautamBytes <[email protected]>
@GautamBytes GautamBytes force-pushed the add-webhook-util-tests branch from 9099293 to a1557ea Compare August 13, 2025 18:17
@codecov
Copy link

codecov bot commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 47.42%. Comparing base (00aae12) to head (3bf25d3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #293      +/-   ##
==========================================
- Coverage   47.52%   47.42%   -0.11%     
==========================================
  Files          63       65       +2     
  Lines        9799     9890      +91     
==========================================
+ Hits         4657     4690      +33     
- Misses       4585     4643      +58     
  Partials      557      557              
Flag Coverage Δ
unittests 47.42% <ø> (-0.11%) ⬇️

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: GautamBytes <[email protected]>
@kruise-bot kruise-bot added size/L and removed size/M labels Aug 14, 2025
Signed-off-by: GautamBytes <[email protected]>
@GautamBytes
Copy link
Contributor Author

@furykerry can you help me with why 'codecov/project' fails saying low coverage. it seems to be 100% as i can check on terminal

gautam@Gautam:/mnt/e/rollouts$ go tool cover -func=util.cover | grep "util.go"
github.com/openkruise/rollouts/pkg/webhook/util/util.go:26:     GetHost         100.0%
github.com/openkruise/rollouts/pkg/webhook/util/util.go:30:     GetNamespace    100.0%
github.com/openkruise/rollouts/pkg/webhook/util/util.go:37:     GetSecretName   100.0%
github.com/openkruise/rollouts/pkg/webhook/util/util.go:44:     GetServiceName  100.0%
github.com/openkruise/rollouts/pkg/webhook/util/util.go:51:     GetPort         100.0%
github.com/openkruise/rollouts/pkg/webhook/util/util.go:63:     GetCertDir      100.0%
github.com/openkruise/rollouts/pkg/webhook/util/util.go:70:     GetCertWriter   100.0%

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants