Skip to content

[test-improver] Improve tests for urlutil package#8008

Merged
lpcox merged 3 commits into
mainfrom
test-improver/urlutil-coverage-ad14aa1667f11e2e
Jun 24, 2026
Merged

[test-improver] Improve tests for urlutil package#8008
lpcox merged 3 commits into
mainfrom
test-improver/urlutil-coverage-ad14aa1667f11e2e

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

File Analyzed

  • Test File: internal/urlutil/domains_test.go (new file)
  • Package: internal/urlutil
  • Implementation: internal/urlutil/domains.go (101 lines)

Improvements Made

1. Increased Coverage

  • ✅ Created domains_test.go from scratch — the package had zero test coverage
  • Previous Coverage: 0%
  • New Coverage: 97.8%
  • Improvement: +97.8%

2. Comprehensive Test Cases (50 total)

TestExtractURLDomains — 30 subtests covering:

  • Empty/no-URL strings → nil
  • HTTP and HTTPS schemes
  • Case-insensitive scheme matching (HTTPS://, Https://)
  • Hostname lowercasing (EXAMPLE.COMexample.com)
  • URL components: path, query string, fragment, port, userinfo, IPv4
  • All trailing punctuation characters stripped: , . ; : ! ) ] } "
  • Deduplication of identical hostnames across multiple URLs
  • Sorted output for multiple distinct domains
  • URL embedded in Markdown and HTML markup
  • Subdomains preserved as distinct entries
  • Error paths: invalid percent-encoding (%GG, %ZZ) triggers url.Parse error → URL skipped
  • Empty hostname path: (user/redacted)@ (userinfo with no host) → nil

TestExtractURLDomainsFromValue — 20 subtests covering:

  • All four collectURLDomains type branches: string, map[string]any, []any, []map[string]any
  • Unmatched types (int, bool, nil) are ignored
  • Nested map[string]any inside map[string]any
  • []any containing nested maps
  • Cross-value deduplication and sorted output
  • Empty slices and maps with non-URL values → nil

3. Idiomatic Testing Patterns

  • ✅ Table-driven tests with t.Parallel() at both parent and subtest level
  • ✅ Uses testify/assert throughout — consistent with codebase conventions
  • ✅ Descriptive subtest names that document each tested behavior

Test Execution

All 50 tests pass:

ok  github.com/github/gh-aw-mcpg/internal/urlutil  0.006s  coverage: 97.8% of statements
ExtractURLDomainsFromValue  100.0%
collectURLDomains           100.0%
ExtractURLDomains            96.0%
total:                       97.8%

Why This File?

internal/urlutil/domains.go was the only package in the internal/ tree with 0% test coverage — no test file existed at all. The package provides URL domain extraction used across the codebase, making thorough testing especially valuable. The functions have clear, verifiable behavior across a range of input types and edge cases.


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.io

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

network:
  allowed:
    - defaults
    - "index.crates.io"

See Network Configuration for more information.

Generated by Test Improver · 1.1K AIC · ⊞ 29.5K ·

Adds comprehensive test coverage for the urlutil package which had
0% coverage. The new test file covers:

- ExtractURLDomains: empty/no-URL strings, http/https schemes,
  case-insensitive scheme matching, hostname lowercasing, URL components
  (path, query, fragment, port, userinfo), trailing punctuation stripping
  (comma, period, semicolon, exclamation, parentheses, brackets, quotes),
  deduplication, sorted output, and error paths (invalid percent-encoding,
  empty hostname after parsing).

- ExtractURLDomainsFromValue: string, map[string]any, []any, and
  []map[string]any inputs including nested structures, unmatched types
  (int, bool, nil), deduplication across values, and sorted output.

Coverage: 0% → 97.8% (50 test cases)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds initial unit test coverage for the internal/urlutil domain-extraction helpers, which parse strings / nested values and return sorted, deduplicated hostname lists.

Changes:

  • Introduces a new domains_test.go with table-driven tests for ExtractURLDomains.
  • Adds coverage for ExtractURLDomainsFromValue across supported input shapes (string, map[string]any, []any, []map[string]any), including recursion + deduplication.
Show a summary per file
File Description
internal/urlutil/domains_test.go New test suite covering URL domain extraction and recursive value-walking behavior.

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/urlutil/domains_test.go
Comment thread internal/urlutil/domains_test.go Outdated
lpcox and others added 2 commits June 24, 2026 07:32
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>
GitHub Advanced Security started work on behalf of lpcox June 24, 2026 14:33 View session
GitHub Advanced Security started work on behalf of lpcox June 24, 2026 14:33 View session
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 14:33
GitHub Advanced Security finished work on behalf of lpcox June 24, 2026 14:33
@lpcox lpcox merged commit 970bcc2 into main Jun 24, 2026
27 checks passed
@lpcox lpcox deleted the test-improver/urlutil-coverage-ad14aa1667f11e2e branch June 24, 2026 14:47
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