[test-improver] Improve tests for urlutil package#8008
Merged
Conversation
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>
This was referenced Jun 24, 2026
Contributor
There was a problem hiding this comment.
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.gowith table-driven tests forExtractURLDomains. - Adds coverage for
ExtractURLDomainsFromValueacross 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
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>
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.
File Analyzed
internal/urlutil/domains_test.go(new file)internal/urlutilinternal/urlutil/domains.go(101 lines)Improvements Made
1. Increased Coverage
domains_test.gofrom scratch — the package had zero test coverage2. Comprehensive Test Cases (50 total)
TestExtractURLDomains— 30 subtests covering:nilHTTPS://,Https://)EXAMPLE.COM→example.com),.;:!)]}"%GG,%ZZ) triggersurl.Parseerror → URL skipped(user/redacted)@(userinfo with no host) →nilTestExtractURLDomainsFromValue— 20 subtests covering:collectURLDomainstype branches:string,map[string]any,[]any,[]map[string]anyint,bool,nil) are ignoredmap[string]anyinsidemap[string]any[]anycontaining nested mapsnil3. Idiomatic Testing Patterns
t.Parallel()at both parent and subtest leveltestify/assertthroughout — consistent with codebase conventionsTest Execution
All 50 tests pass:
Why This File?
internal/urlutil/domains.gowas the only package in theinternal/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.ioSee Network Configuration for more information.