[test-improver] Improve tests for config/rules package#2042
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[test-improver] Improve tests for config/rules package#2042github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
…tionError Add coverage for three untested factory functions in the config/rules package: - TestInvalidPattern: verifies ValidationError construction for pattern mismatches, including container images, URLs, mounts, and empty values - TestInvalidValue: verifies ValidationError construction for constraint violations, including entrypoint, domain, and customSchemas fields - TestSchemaValidationError: verifies ValidationError construction for schema validation failures, confirming Field is always 'type' and message/serverType are composed correctly All three functions are used in production (validation.go, validation_schema.go) but previously had no direct unit tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
File Analyzed
internal/config/rules/rules_test.gointernal/config/rulesImprovements Made
1. Increased Coverage
Three factory functions in
rules.gowere used throughout production code but had zero direct unit tests:InvalidPatternvalidation_schema.go(container, mounts, url fields)InvalidValuevalidation_schema.go,validation.go(entrypoint, domain, customSchemas)SchemaValidationErrorvalidation.go(8 call sites for schema fetch/parse/validate failures)2. New Tests Added
✅
TestInvalidPattern(4 cases) — verifiesValidationErroris constructed correctly for pattern mismatches: container image references, URLs, mount specs, and empty values. AssertsField,Messagecontents,JSONPath, andSuggestion.✅
TestInvalidValue(4 cases) — verifiesValidationErroris constructed for constraint violations: entrypoint whitespace, domain characters, customSchemas type conflicts, and empty message edge case. Asserts exactMessageequality (no sprintf transformation).✅
TestSchemaValidationError(4 cases) — verifiesValidationErrorfor schema validation failures, including the invariant thatFieldis always"type"regardless of inputs, and that the message format is"(message) for server type '(serverType)'".3. Consistent Testing Patterns
All new tests follow the exact patterns established in the existing test file:
name, inputs, andwantSubstrfieldsrequire.NotNilto stop early on unexpected nil resultsassert.Equal/assert.Containsfor field-level assertionsassert.Containsloop overwantSubstrto verifyError()outputWhy These Changes?
The
config/rulespackage is the foundation of all configuration validation in the gateway. Every validation error produced during config parsing goes through one of these factory functions. The three untested functions (InvalidPattern,InvalidValue,SchemaValidationError) are called from 11+ production call sites invalidation.goandvalidation_schema.go, yet had no direct tests. This PR closes that gap, ensuring the error message format and field assignments are locked in by tests.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests