Added unit test for cmd/resourcedistributiongenerator/generator/targets.go #151
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.