[test] Add tests for config.detailForKeyword and formatErrorContext branches#6907
Merged
Merged
Conversation
…ntext branches Expand TestDetailForKeyword from 2 test cases (additionalProperties + unknown) to a table-driven test covering all 7 known keywords: additionalProperties, type, enum, required, pattern, range, and oneOf — plus the empty-string case. Add TestFormatErrorContextDeduplication to verify the addDetail deduplication map prevents the same category lines from appearing twice when both the keyword-location switch and the message-content fallback would match the same category. Add 10 new TestFormatErrorContext table entries covering the previously untested formatErrorContext keyword-switch branches: - maximum, exclusiveMinimum, exclusiveMaximum keyword locations (→ range) - type, enum, required, pattern, oneOf keyword locations (→ direct detail) - keyword+message same-category deduplication scenario Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves test coverage for JSON Schema validation error formatting helpers in internal/config, specifically targeting previously untested switch/fallback/deduplication branches in detailForKeyword and formatErrorContext.
Changes:
- Expands
TestFormatErrorContextwith additional keyword-location cases (range/type/enum/required/pattern/oneOf) and a keyword+message overlap scenario. - Adds a dedicated deduplication test to ensure identical detail categories are emitted only once.
- Refactors
TestDetailForKeywordinto a broader table-driven set of cases (but currently introduces a compile issue due to a missing test function wrapper).
Show a summary per file
| File | Description |
|---|---|
| internal/config/validation_schema_error_format_test.go | Adds/extends table-driven tests for formatErrorContext and detailForKeyword, including deduplication coverage. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 0
Collaborator
Contributor
Fixed in commit 90eb868. I restored the missing |
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.
Test Coverage Improvement:
detailForKeyword+formatErrorContextFunction Analyzed
internal/configinternal/config/validation_schema.godetailForKeyword,formatErrorContextTestDetailForKeywordcovered 2/7 keyword switch cases (≈28%); severalformatErrorContextkeyword-location switch branches untestedformatErrorContexthas a layered dispatch: keyword-location switch → message-content fallback → deduplication map → schema-location suffixWhy These Functions?
detailForKeywordhas a 7-caseswitchstatement butTestDetailForKeywordonly exercised"additionalProperties"and"unknown", leaving five keyword branches (type,enum,required,pattern,range,oneOf) uncovered.formatErrorContextroutes validation errors to detail lines via two mechanisms — a keyword-location switch (which mapsminimum/maximum/exclusiveMinimum/exclusiveMaximumto"range") and a message-content fallback — plus anaddeddeduplication map that prevents the same detail from appearing twice. Themaximum,exclusiveMinimum, andexclusiveMaximumkeyword-location branches were never exercised, nor was the deduplication scenario.Tests Added
TestDetailForKeyword— expanded from 2 → 9 table casesadditionalProperties— "Configuration contains field(s)"type— "Type mismatch"enum— "Invalid value"required— "Required field(s) are missing"pattern— "Value format is incorrect"range— "Value is outside the allowed range"oneOf— "doesn't match any of the expected formats"→) in the second lineTestFormatErrorContext— 10 new table entriesmaximumkeyword location → range detailexclusiveMinimumkeyword location → range detailexclusiveMaximumkeyword location → range detailtypekeyword location → type mismatch detailenumkeyword location → invalid value detailrequiredkeyword location → missing fields detailpatternkeyword location → value format detailoneOfkeyword location → no-matching-format detailTestFormatErrorContextDeduplication— new standalone testaddedmap prevents "Configuration contains field(s)" from appearing twice when both the keyword-location switch and the message-content fallback fire for the same categoryCoverage Impact
detailForKeywordswitch coverage: 2/7 cases (28%) → 7/7 cases (100%)formatErrorContextkeyword-switch: previously missingmaximum,exclusiveMinimum,exclusiveMaximum, and five other keyword-location branches — all now covered.Generated by Test Coverage Improver
Next run will target the next most complex under-tested function
Warning
Firewall blocked 9 domains
The following domains were blocked by the firewall during workflow execution:
172.30.0.50go.opentelemetry.iogo.yaml.ingolang.orggoogle.golang.orggopkg.inproxy.golang.orgreleaseassets.githubusercontent.comsum.golang.orgSee Network Configuration for more information.