Skip to content

Added Unit test for pkg/util/discovery/discovery.go#267

Open
GautamBytes wants to merge 2 commits intoopenkruise:masterfrom
GautamBytes:test/util-discovery
Open

Added Unit test for pkg/util/discovery/discovery.go#267
GautamBytes wants to merge 2 commits intoopenkruise:masterfrom
GautamBytes:test/util-discovery

Conversation

@GautamBytes
Copy link
Contributor

What this PR does

This PR introduces comprehensive unit tests for the pkg/util/discovery package, which previously had no test coverage.

To enable testing, the core logic of DiscoverGVK was extracted into a private discoverGVKWithClient function. This refactoring allows for dependency injection of a mock discovery client, making the logic fully testable in isolation.

Key Changes

  1. Refactoring for Testability: The DiscoverGVK function has been refactored to delegate its logic to a new private helper, discoverGVKWithClient, without changing any public-facing APIs.
  2. Added Unit Tests: A new test file, discovery_test.go, has been added with thorough test cases for:
    • Successful GVK discovery.
    • When a GVK is not found.
    • Generic API server errors.
    • Objects not registered in the scheme.
  3. Bug Fix: The new tests uncovered a bug where the discovery logic was not correctly handling standard Kubernetes "not found" errors. The code has been updated to use errors.IsNotFound() for robust error checking.

Signed-off-by: GautamBytes <manchandanigautam@gmail.com>
@kruise-bot kruise-bot requested review from furykerry and zmberg July 31, 2025 19:02
@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 furykerry for approval by writing /assign @furykerry 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.

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

@kruise-bot
Copy link

Welcome @GautamBytes! It looks like this is your first PR to openkruise/kruise-game 🎉

@codecov
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 31.14%. Comparing base (1ca95a5) to head (fe95b7a).
⚠️ Report is 23 commits behind head on master.

Files with missing lines Patch % Lines
pkg/util/discovery/discovery.go 87.50% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #267      +/-   ##
==========================================
+ Coverage   27.65%   31.14%   +3.48%     
==========================================
  Files          94       96       +2     
  Lines       10450    11328     +878     
==========================================
+ Hits         2890     3528     +638     
- Misses       7358     7567     +209     
- Partials      202      233      +31     
Flag Coverage Δ
unittests 31.14% <87.50%> (+3.48%) ⬆️

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 <manchandanigautam@gmail.com>
@GautamBytes
Copy link
Contributor Author

@ringtail , @chrisliu1995 , please rerun the workflow , the single failing workflow will pass then .
Also, you can review this whenever feasible!

@GautamBytes
Copy link
Contributor Author

GautamBytes commented Aug 8, 2025

@ringtail @furykerry just pinging to get a review . Thanks!

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

Comments