Added unit test for cmd/resourcedistributiongenerator/generator/targets.go#151
Open
GautamBytes wants to merge 3 commits intoopenkruise:masterfrom
Open
Added unit test for cmd/resourcedistributiongenerator/generator/targets.go#151GautamBytes wants to merge 3 commits intoopenkruise:masterfrom
GautamBytes wants to merge 3 commits intoopenkruise:masterfrom
Conversation
Signed-off-by: GautamBytes <manchandanigautam@gmail.com>
|
[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>
Signed-off-by: GautamBytes <manchandanigautam@gmail.com>
Contributor
Author
|
@furykerry please take a look! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's in this PR?
This PR significantly improves the quality and reliability of the ResourceDistribution generator by introducing two comprehensive test suites and fixing a critical bug that was uncovered during the process.
The Bug Fix in
targets.goThe most important change is a fix to the
newNameListRNodefunction intargets.go.Problem: The function was generating an invalid YAML structure for namespace lists that would be rejected by the Kubernetes API server.
Solution: The function has been corrected to produce a simple list of strings, which is the valid schema required by the ResourceDistribution CRD.
New Test Coverage
Two new test files have been added to validate the generator's behavior:
resourcedistribution_test.go: A high-level test for the main MakeResourceDistribution function.
targets_test.go: A granular unit test for the complex validation and transformation logic in targets.go.
These tests cover all key scenarios, including:
Data generation via literalSources.
Applying options to resources via resourceOptions.
Combining all targeting mechanisms (allNamespaces, included/excluded lists, label selectors).
All error and validation paths.