[test-improver] Improve tests for strutil package (DeepCloneJSON)#7240
Conversation
Add deepclone_test.go covering all branches of DeepCloneJSON: - nil and scalar inputs (default branch) - empty/flat maps and slices - nested maps, slices of maps, maps with slice values - deeply nested structures (3+ levels) - mutation-independence: clones are fully independent of originals - mixed JSON-compatible types (string, float64, bool, nil) Coverage for internal/strutil: 88.2% → 100.0% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a new unit test suite for internal/strutil.DeepCloneJSON to cover all cloning branches (map, slice, scalar) and validate deep-copy semantics for nested JSON-like structures in the strutil helper package.
Changes:
- Introduces
internal/strutil/deepclone_test.gowith subtests for nil/scalars, maps, slices, and nested structures. - Adds mutation-based assertions to confirm cloned structures are independent from their originals.
- Uses
testify/assertandtestify/requireconsistent with otherinternal/strutiltests.
Show a summary per file
| File | Description |
|---|---|
| internal/strutil/deepclone_test.go | New test coverage for DeepCloneJSON, including deep-copy behavior for nested maps/slices. |
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: 2
| t.Run("empty map returns new empty map", func(t *testing.T) { | ||
| input := map[string]interface{}{} | ||
| result := DeepCloneJSON(input) | ||
| require.NotNil(t, result) | ||
| assert.Equal(t, map[string]interface{}{}, result) | ||
| }) |
| t.Run("empty slice returns new empty slice", func(t *testing.T) { | ||
| input := []interface{}{} | ||
| result := DeepCloneJSON(input) | ||
| require.NotNil(t, result) | ||
| assert.Equal(t, []interface{}{}, result) | ||
| }) |
|
@copilot resolve the merge conflicts in this pull request and address review feedback |
Resolved the merge conflict in
The merged version also adds |
|
@copilot fix this failing ci check https://github.com/github/gh-aw-mcpg/actions/runs/27214153350/job/80355639417?pr=7240 |
The failing check is |
Test Improvements:
deepclone_test.goFile Analyzed
internal/strutil/deepclone_test.go(new file)internal/strutil/deepclone.gointernal/strutilWhy This File?
DeepCloneJSONhad 0% coverage — no test file existed for it at all. It is a recursive function used to deep-copy JSON-compatible Go values, with three distinct code paths:map[string]interface{},[]interface{}, and the scalar/default case. Without tests, silent regressions in copy semantics (e.g., accidentally making a shallow copy) would go undetected.The previous improvement session had addressed
util_test.go; this session targets the remaining gap.Improvements Made
1. Full Branch Coverage
map[string]interface{}branch: flat maps, nested maps, maps with mixed value types[]interface{}branch: flat slices, slices of maps, slices of slicesstring,int,float64,bool,nil2. Increased Coverage
DeepCloneJSON: 0.0%)3. Deep-Copy Semantics Verified
map_with_nested_map_is_deep_cloned,map_with_slice_value_is_deep_cloned,slice_of_maps_is_deep_cloned,slice_of_slices_is_deep_cloned,deeply_nested_structure_is_fully_cloned)cloned_map_is_independent,cloned_slice_is_independent)4. Testify Patterns
assertandrequirefromgithub.com/stretchr/testifyt.Run()for all cases, descriptive names followingTestFunctionName/scenarioconventionTest Execution
All 25 test cases pass:
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.