[test-improver] Improve tests for config package#6813
Merged
lpcox merged 1 commit intoJun 1, 2026
Conversation
Add direct table-driven tests for the keywordFromLocation helper function in the config/validation_schema.go package. The function previously had 85.7% coverage because the no-slash branch (returning the input as-is) was never directly exercised by tests. The new TestKeywordFromLocation function covers all branches: - Empty string → returns empty string - Whitespace-only → returns empty string after trim - String with no slash → returns the full string (previously untested) - String with trailing slash → slash stripped before extraction - Slash-prefixed single keyword → returns the keyword - Standard nested path → returns terminal keyword - Edge case: single slash → returns empty string Coverage improvement: keywordFromLocation 85.7% → 100% Overall config package: 96.0% → 96.1% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves unit test coverage in the internal/config package by adding direct, table-driven coverage for the keywordFromLocation helper used by JSON Schema validation error formatting.
Changes:
- Added
TestKeywordFromLocationto directly exercise all branches ofkeywordFromLocation, including the previously untested “no slash” path. - Expanded edge-case coverage for empty/whitespace inputs, trailing slashes, and root
/.
Show a summary per file
| File | Description |
|---|---|
internal/config/validation_schema_error_format_test.go |
Adds a focused table-driven test covering keywordFromLocation’s full behavior surface. |
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
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 Improvements:
validation_schema_error_format_test.goFile Analyzed
internal/config/validation_schema_error_format_test.gointernal/configImprovements Made
1. Increased Coverage
TestKeywordFromLocation— a direct table-driven test for thekeywordFromLocationhelper functionkeywordFromLocationat 85.7% (6/7 statements)keywordFromLocationat 100%2. Better Testing Patterns
assert.Equalfrom testify (consistent with existing file conventions)3. Coverage Gap Identified
The
keywordFromLocationfunction extracts the terminal keyword from a slash-separated JSON Schema keyword-location path (e.g."/properties/foo/type"→"type"). It had three branches:return ""✅ covered indirectlyreturn keywordLocation❌ never directly testedreturn keywordLocation[lastSlash+1:]✅ covered indirectlyThe "no slash" branch (e.g. input
"type"with no path separator) was never exercised by any test, leaving a gap. The new test directly covers all branches including this missing case.Test Execution
All tests pass:
Why These Changes?
The
validation_schema_error_format_test.gofile tests JSON Schema error formatting utilities. While the file already had good coverage forformatErrorContext,detailForKeyword,formatValidationErrorRecursive, andformatSchemaError, the internalkeywordFromLocationhelper was only exercised indirectly through those functions — and only via inputs that always contained slashes. The "no slash" branch was silently untested.Adding a direct, focused test for
keywordFromLocationwith a complete set of cases (empty, whitespace, no-slash, slash-prefixed, nested, edge cases) makes the contract explicit and ensures the function behaves correctly across all inputs.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.