Skip to content

[test] Add tests for strutil.CopyTrimmedStringIntMap#7007

Merged
lpcox merged 3 commits into
mainfrom
add-tests-strutil-copy-trimmed-string-int-map-9f5ee95d37357bf9
Jun 5, 2026
Merged

[test] Add tests for strutil.CopyTrimmedStringIntMap#7007
lpcox merged 3 commits into
mainfrom
add-tests-strutil-copy-trimmed-string-int-map-9f5ee95d37357bf9

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Jun 4, 2026

Test Coverage Improvement: CopyTrimmedStringIntMap

Function Analyzed

  • Package: internal/strutil
  • Function: CopyTrimmedStringIntMap
  • Previous Coverage: 0%
  • New Coverage: 100%
  • Package Coverage: 92.0% → 100.0%
  • Complexity: Low (2 branches: empty-input guard + key-trimming loop)

Why This Function?

CopyTrimmedStringIntMap had 0% coverage despite being a utility used throughout the codebase for defensive map copying. It was the only uncovered function in the internal/strutil package (all other functions were already at 100%).

The function has clear testable behaviour:

  • Early-return nil for nil/empty inputs
  • Key whitespace trimming via strings.TrimSpace
  • Defensive (independent) copy semantics

Tests Added

  • ✅ nil input returns nil
  • ✅ empty map returns nil
  • ✅ single entry with clean key
  • ✅ leading / trailing whitespace trimmed from key
  • ✅ tab and newline characters trimmed from key
  • ✅ internal whitespace in key is preserved (only edges trimmed)
  • ✅ multiple entries, all keys trimmed
  • ✅ integer edge cases: zero, negative, max int32
  • ✅ whitespace-only key becomes empty-string key
  • ✅ defensive copy: changes to the copy do not affect the original
  • ✅ changes to the original do not affect the copy
  • ✅ nil and empty inputs both produce nil (documented contract)

Coverage Report

Before: 92.0% (strutil package) — CopyTrimmedStringIntMap 0%
After:  100.0% (strutil package) — CopyTrimmedStringIntMap 100%
Improvement: +8% package / +100% function

Test Execution

=== RUN   TestCopyTrimmedStringIntMap
--- PASS: TestCopyTrimmedStringIntMap (0.00s)
=== RUN   TestCopyTrimmedStringIntMap_IsDefensiveCopy
--- PASS: TestCopyTrimmedStringIntMap_IsDefensiveCopy (0.00s)
=== RUN   TestCopyTrimmedStringIntMap_NilNotSameAsEmpty
--- PASS: TestCopyTrimmedStringIntMap_NilNotSameAsEmpty (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/strutil  0.006s  coverage: 100.0% of statements

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:

  • go.opentelemetry.io
  • go.yaml.in
  • golang.org
  • google.golang.org
  • gopkg.in
  • goproxy.cn
  • goproxy.io
  • proxy.golang.org
  • releaseassets.githubusercontent.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "go.opentelemetry.io"
    - "go.yaml.in"
    - "golang.org"
    - "google.golang.org"
    - "gopkg.in"
    - "goproxy.cn"
    - "goproxy.io"
    - "proxy.golang.org"
    - "releaseassets.githubusercontent.com"

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 5.8M ·

Add comprehensive table-driven tests for CopyTrimmedStringIntMap,
covering nil/empty input, key whitespace trimming (leading, trailing,
tabs, newlines), internal whitespace preservation, integer edge cases
(zero, negative, max int), defensive copy semantics, and the
whitespace-only key edge case.

Coverage: strutil package 92.0% → 100.0% (CopyTrimmedStringIntMap 0% → 100%)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lpcox lpcox marked this pull request as ready for review June 5, 2026 13:48
Copilot AI review requested due to automatic review settings June 5, 2026 13:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unit tests to fully cover internal/strutil.CopyTrimmedStringIntMap, validating the function’s key-trimming behavior and defensive-copy semantics so the internal/strutil package reaches full statement coverage.

Changes:

  • Introduces table-driven tests for nil/empty inputs and multiple whitespace-trimming cases.
  • Adds a defensive-copy test to ensure the returned map is independent of the input map.
  • Adds a small contract test asserting both nil and empty inputs return nil.
Show a summary per file
File Description
internal/strutil/copy_trimmed_string_int_map_test.go Adds comprehensive tests covering key trimming, nil/empty behavior, and defensive copy semantics for CopyTrimmedStringIntMap.

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

Comment thread internal/strutil/copy_trimmed_string_int_map_test.go Outdated
Comment thread internal/strutil/copy_trimmed_string_int_map_test.go Outdated
lpcox and others added 2 commits June 5, 2026 07:37
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox lpcox merged commit d9edf05 into main Jun 5, 2026
16 checks passed
@lpcox lpcox deleted the add-tests-strutil-copy-trimmed-string-int-map-9f5ee95d37357bf9 branch June 5, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants