Skip to content

[test-improver] Improve tests for config/rules package#2042

Draft
github-actions[bot] wants to merge 1 commit intomainfrom
test-improver/rules-coverage-06ed91e09022f7ea
Draft

[test-improver] Improve tests for config/rules package#2042
github-actions[bot] wants to merge 1 commit intomainfrom
test-improver/rules-coverage-06ed91e09022f7ea

Conversation

@github-actions
Copy link
Contributor

File Analyzed

  • Test File: internal/config/rules/rules_test.go
  • Package: internal/config/rules
  • Lines of Code: 816 → 1046 (+230 lines)

Improvements Made

1. Increased Coverage

Three factory functions in rules.go were used throughout production code but had zero direct unit tests:

Function Used in
InvalidPattern validation_schema.go (container, mounts, url fields)
InvalidValue validation_schema.go, validation.go (entrypoint, domain, customSchemas)
SchemaValidationError validation.go (8 call sites for schema fetch/parse/validate failures)

2. New Tests Added

  • TestInvalidPattern (4 cases) — verifies ValidationError is constructed correctly for pattern mismatches: container image references, URLs, mount specs, and empty values. Asserts Field, Message contents, JSONPath, and Suggestion.

  • TestInvalidValue (4 cases) — verifies ValidationError is constructed for constraint violations: entrypoint whitespace, domain characters, customSchemas type conflicts, and empty message edge case. Asserts exact Message equality (no sprintf transformation).

  • TestSchemaValidationError (4 cases) — verifies ValidationError for schema validation failures, including the invariant that Field is 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:

  • Table-driven tests with name, inputs, and wantSubstr fields
  • require.NotNil to stop early on unexpected nil results
  • assert.Equal / assert.Contains for field-level assertions
  • assert.Contains loop over wantSubstr to verify Error() output

Why These Changes?

The config/rules package 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 in validation.go and validation_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

Generated by Test Improver ·

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants