Skip to content

[test] Add tests for mcpresult.ExtractTextContent#7060

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
add-tests-mcpresult-extract-text-content-ea5516034a56cfbf
Draft

[test] Add tests for mcpresult.ExtractTextContent#7060
github-actions[bot] wants to merge 1 commit into
mainfrom
add-tests-mcpresult-extract-text-content-ea5516034a56cfbf

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

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

Test Coverage Improvement: ExtractTextContent

Function Analyzed

  • Package: internal/mcpresult
  • Function: ExtractTextContent
  • Previous Coverage: 0%
  • New Coverage: 100%
  • Complexity: Medium

Why This Function?

ExtractTextContent was selected because it had 0% coverage and meaningful complexity: it handles two distinct input slice types ([]interface{} vs []map[string]interface{}), filters content items by type (text/image/audio/resource/unknown), performs type assertions on the text field, and has several skip conditions. Covering all branches requires a rich test suite.

Tests Added

  • ✅ Happy path – single text item via []interface{} and []map[string]interface{}
  • ✅ Nil/missing content key and nil content value
  • ✅ Unsupported content types (string, int, map, bool → returns "")
  • ✅ Empty slices (both []interface{} and []map[string]interface{})
  • ✅ Item type filtering: "text" and "" kept; "image", "audio", "resource" skipped; unknown types kept per backward-compat
  • ✅ Non-map items in []interface{} are skipped
  • ✅ Items with empty text, missing text key, or non-string text value are skipped
  • ✅ Multi-item concatenation (including newlines and unicode)
  • ✅ Mixed type scenarios (text interspersed with skipped types)
  • ✅ Nil map input
  • ✅ Complex realistic scenario combining all edge cases

Coverage Report

Before: 0.0% coverage
After:  100.0% coverage
Improvement: +100%

Test Execution

All 37 sub-tests pass:

ok  github.com/github/gh-aw-mcpg/internal/mcpresult  0.003s  coverage: 100.0% of statements
github.com/github/gh-aw-mcpg/internal/mcpresult/text_content.go:8: ExtractTextContent  100.0%

Note: Tests use only the standard testing package. testify is the project convention but its module zip is unavailable in the network-restricted environment; the test patterns (table-driven, t.Parallel, descriptive names) match the project style otherwise.


Generated by Test Coverage Improver
Next run will target the next most complex under-tested function

Warning

Firewall blocked 2 domains

The following domains were blocked by the firewall during workflow execution:

  • proxy.golang.org
  • sum.golang.org

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

network:
  allowed:
    - defaults
    - "proxy.golang.org"
    - "sum.golang.org"

See Network Configuration for more information.

Generated by Test Coverage Improver · sonnet46 3M ·

Adds comprehensive table-driven tests for ExtractTextContent in the
internal/mcpresult package. Coverage goes from 0% to 100%.

Tests cover all branches in the function:
- Missing/nil content key
- Unsupported content types (string, int, map, bool)
- Empty []interface{} and []map[string]interface{} slices
- Item type filtering: text/empty (kept), image/audio/resource (skipped),
  unknown types (kept per backward-compat comment)
- Non-map items in []interface{} (skipped)
- Empty or non-string text values (skipped)
- []map[string]interface{} typed slice path
- Multi-item concatenation and mixed-type scenarios
- Nil map input, unicode content, whitespace-only text

Note: tests use only the standard library testing package; testify is
unavailable in the network-restricted CI environment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

0 participants