[test-improver] Improve tests for proxy package#6770
Merged
Conversation
Add table-driven tests for Server.upstreamHost() in forward_to_github_test.go, covering all three parsing strategies: - Full URL with scheme (fast path via url.Parse) - Scheme-less hostname (fallback prepending https://) - Empty/unresolvable URL (strings.Cut fallback) Coverage improvement: upstreamHost 37.5% → 100% Package total: 90.8% → 91.5% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves test coverage and clarity for Server.upstreamHost() in the internal/proxy package, ensuring all parsing branches are exercised and the expected hostname extraction behavior is documented through table-driven cases.
Changes:
- Added a new table-driven
TestUpstreamHostcovering scheme URLs, scheme-less hostnames (with/without paths), and empty input fallback behavior. - Expanded branch coverage for
upstreamHost()without introducing network dependencies or non-deterministic test behavior.
Show a summary per file
| File | Description |
|---|---|
internal/proxy/forward_to_github_test.go |
Adds comprehensive table-driven coverage for Server.upstreamHost() hostname extraction branches. |
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: 0
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.
Test Improvements:
forward_to_github_test.goFile Analyzed
internal/proxy/forward_to_github_test.gointernal/proxyImprovements Made
1. Increased Coverage
TestUpstreamHosttable-driven test covering all three parsing branches ofServer.upstreamHost()upstreamHost37.5% (3/8 statements)upstreamHost100% (8/8 statements)2. Better Testing Patterns
3. Coverage of All Three Parsing Strategies
The
upstreamHostfunction uses three strategies in order:https://api.github.com) —url.Parsereturns non-empty Host directlyapi.github.com,api.github.com/api/v3) — first parse gives empty Host (treated as relative path), so the function prependshttps://and re-parsesstrings.CutPreviously only the first strategy was exercised (by indirect coverage through
forwardToGitHubtests using ahttptest.ServerURL).Test Execution
All tests pass:
Why These Changes?
upstreamHosthad 37.5% coverage despite being used in production code to populate theserver.addressOpenTelemetry attribute. The scheme-less and fallback paths — designed to handle common deployment configurations likeapi.github.comor GHES without an explicithttps://prefix — were completely untested. The new tests verify all three parsing strategies and document the intended behaviour for each URL format.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.