[test] Add tests for config.detailForKeyword and formatErrorContext branches#6907
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>
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
|
@copilot fix the failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/26839291929/job/79142563113?pr=6907 |
Fixed in commit 90eb868. I restored the missing |
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.