[test-improver] Improve tests for strutil package#7011
Merged
lpcox merged 1 commit intoJun 5, 2026
Conversation
Add comprehensive tests for CopyTrimmedStringIntMap in util_test.go. The function had 0% coverage within its own package (it was only tested indirectly from server/copy_tool_call_limits_test.go). New tests cover: - nil input returns nil - empty map returns nil - single and multiple entries copied correctly - leading/trailing space trimming from keys - tab character trimming from keys - zero and negative limit values preserved - defensive copy: mutations to copy don't affect original - defensive copy: mutations to original don't affect copy Package coverage: 92.0% → 100.0% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Jun 5, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds direct unit test coverage for CopyTrimmedStringIntMap in internal/strutil, bringing that helper’s coverage into the package’s own test suite (rather than relying on indirect coverage from other packages).
Changes:
- Added a table-driven test covering
CopyTrimmedStringIntMapbehavior across nil/empty inputs, key trimming, and value edge cases. - Added two focused tests to assert the returned map is a defensive copy (mutations don’t leak across original/copy boundaries).
- Updated imports to include
requirefor fail-fast assertions in the defensive-copy tests.
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/util_test.go | Adds comprehensive unit tests for CopyTrimmedStringIntMap, including defensive-copy invariants. |
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:
util_test.goFile Analyzed
internal/strutil/util_test.gointernal/strutilImprovements Made
1. Increased Coverage
TestCopyTrimmedStringIntMap— table-driven test with 8 cases forCopyTrimmedStringIntMap, which had 0% coverage within its own packageTestCopyTrimmedStringIntMap_DefensiveCopy— verifies that mutating the returned copy does not affect the original mapTestCopyTrimmedStringIntMap_OriginalMutationDoesNotAffectCopy— verifies that mutating the original after copying does not affect the returned copyCopyTrimmedStringIntMap: 0.0%)CopyTrimmedStringIntMap: 100.0%)2. Better Testing Patterns
require.NotNilbefore asserting on the copy (fail-fast for nil)TestGetStringFromMapstyle3. Cleaner & More Stable Tests
t.Parallel()for faster test executionsnake_casesubtest conventionTest Execution
All tests pass with 100% coverage:
Why These Changes?
CopyTrimmedStringIntMapis a utility in thestrutilpackage used byserver/guard_init.goto copy tool-call limit maps. The function was tested indirectly viainternal/server/copy_tool_call_limits_test.go(which runs inpackage server), meaning its own package had 0% coverage for this function. Adding direct unit tests inutil_test.goensures the function is tested at the package level, surfaces any future regressions immediately instrutilpackage test runs, and brings the package to 100% coverage.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.