Summary
File: pkg/parser/github_host_test.go
Source pair: pkg/parser/github.go
Test functions: 1 (TestGetGitHubHostForRepo_PublicOrgFallback)
LOC: 60
Strengths
- Clean table-driven pattern with descriptive case names.
- Uses
t.Setenv correctly for hermetic env isolation.
Prioritized Improvements
1. Missing tests — GetGitHubHost is entirely uncovered
GetGitHubHost reads four env vars in priority order and normalises the URL. None of its behaviour is tested. High-value cases:
| Scenario |
Input |
Expected |
GITHUB_SERVER_URL wins over others |
GITHUB_SERVER_URL=(acme.ghe.com/redacted) |
(acme.ghe.com/redacted) |
Host without scheme gets https:// prefix |
GITHUB_ENTERPRISE_HOST=acme.ghe.com |
(acme.ghe.com/redacted) |
| Trailing slash stripped |
GITHUB_HOST=acme.ghe.com/ |
(acme.ghe.com/redacted) |
GH_HOST used when others are empty |
GH_HOST=acme.ghe.com |
(acme.ghe.com/redacted) |
| All vars empty → public fallback |
(none set) |
https://github.com |
Before/After example
Before: no GetGitHubHost tests exist.
After:
func TestGetGitHubHost(t *testing.T) {
tests := []struct {
name string
envs map[string]string
expected string
}{
{
name: "GITHUB_SERVER_URL takes priority",
envs: map[string]string{"GITHUB_SERVER_URL": "(acme.ghe.com/redacted)"},
expected: "(acme.ghe.com/redacted)",
},
{
name: "host without scheme gets https prefix",
envs: map[string]string{"GITHUB_ENTERPRISE_HOST": "acme.ghe.com"},
expected: "(acme.ghe.com/redacted)",
},
{
name: "trailing slash stripped",
envs: map[string]string{"GITHUB_HOST": "acme.ghe.com/"},
expected: "(acme.ghe.com/redacted)",
},
{
name: "GH_HOST used as last resort",
envs: map[string]string{"GH_HOST": "acme.ghe.com"},
expected: "(acme.ghe.com/redacted)",
},
{
name: "defaults to public github when no env set",
envs: map[string]string{},
expected: "https://github.com",
},
{
name: "GITHUB_SERVER_URL shadows GITHUB_ENTERPRISE_HOST",
envs: map[string]string{
"GITHUB_SERVER_URL": "(primary.ghe.com/redacted)",
"GITHUB_ENTERPRISE_HOST": "(secondary.ghe.com/redacted)",
},
expected: "(primary.ghe.com/redacted)",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
for _, key := range []string{"GITHUB_SERVER_URL", "GITHUB_ENTERPRISE_HOST", "GITHUB_HOST", "GH_HOST"} {
t.Setenv(key, "")
}
for k, v := range tt.envs {
t.Setenv(k, v)
}
require.Equal(t, tt.expected, GetGitHubHost())
})
}
}
2. Testify assertion upgrade — assert → require in table loop
Fatal failures in one sub-test should not bleed into others; require.Equal short-circuits the current sub-test immediately.
Before:
assert.Equal(t, tt.expectedHost, host, "GetGitHubHostForRepo(%q, %q)", tt.owner, tt.repo)
After:
require.Equal(t, tt.expectedHost, host, "GetGitHubHostForRepo(%q, %q)", tt.owner, tt.repo)
Also add "github.com/stretchr/testify/require" to the import block (currently only assert is imported).
3. Missing edge cases for GetGitHubHostForRepo
The existing table omits:
- Empty
gheHost: all env vars blank → should return https://github.com for any owner.
- Non-fallback owner with no GHE env:
owner="acme", no env set → https://github.com.
microsoft org explicitly: verify public host is used (no case present).
{
name: "empty gheHost falls back to public for non-fallback owner",
owner: "acme",
repo: "repo",
gheHost: "",
expectedHost: "https://github.com",
},
{
name: "microsoft owner always uses public host",
owner: "microsoft",
repo: "vscode",
gheHost: "myorg.ghe.com",
expectedHost: "https://github.com",
},
4. Build tag consistency
The file carries //go:build !integration but tests only env vars — no network or filesystem access. The tag may cause the tests to be excluded when running targeted unit builds without the integration tag cleared. Consider removing the tag or aligning with the naming conventions in neighbouring files that do need it (e.g., import_cache_integration_test.go).
Acceptance Checklist
Generated by 🧪 Daily Testify Uber Super Expert · 19.3 AIC · ⌖ 12.3 AIC · ⊞ 5.2K · ◷
Summary
File:
pkg/parser/github_host_test.goSource pair:
pkg/parser/github.goTest functions: 1 (
TestGetGitHubHostForRepo_PublicOrgFallback)LOC: 60
Strengths
t.Setenvcorrectly for hermetic env isolation.Prioritized Improvements
1. Missing tests —
GetGitHubHostis entirely uncoveredGetGitHubHostreads four env vars in priority order and normalises the URL. None of its behaviour is tested. High-value cases:GITHUB_SERVER_URLwins over othersGITHUB_SERVER_URL=(acme.ghe.com/redacted)(acme.ghe.com/redacted)https://prefixGITHUB_ENTERPRISE_HOST=acme.ghe.com(acme.ghe.com/redacted)GITHUB_HOST=acme.ghe.com/(acme.ghe.com/redacted)GH_HOSTused when others are emptyGH_HOST=acme.ghe.com(acme.ghe.com/redacted)https://github.comBefore/After example
Before: no
GetGitHubHosttests exist.After:
2. Testify assertion upgrade —
assert→requirein table loopFatal failures in one sub-test should not bleed into others;
require.Equalshort-circuits the current sub-test immediately.Before:
After:
Also add
"github.com/stretchr/testify/require"to the import block (currently onlyassertis imported).3. Missing edge cases for
GetGitHubHostForRepoThe existing table omits:
gheHost: all env vars blank → should returnhttps://github.comfor any owner.owner="acme", no env set →https://github.com.microsoftorg explicitly: verify public host is used (no case present).{ name: "empty gheHost falls back to public for non-fallback owner", owner: "acme", repo: "repo", gheHost: "", expectedHost: "https://github.com", }, { name: "microsoft owner always uses public host", owner: "microsoft", repo: "vscode", gheHost: "myorg.ghe.com", expectedHost: "https://github.com", },4. Build tag consistency
The file carries
//go:build !integrationbut tests only env vars — no network or filesystem access. The tag may cause the tests to be excluded when running targeted unit builds without theintegrationtag cleared. Consider removing the tag or aligning with the naming conventions in neighbouring files that do need it (e.g.,import_cache_integration_test.go).Acceptance Checklist
TestGetGitHubHostadded covering priority order, scheme normalisation, trailing slash, and empty-env fallback.require.Equalused inside all sub-test loops.microsoftowner and empty-gheHost edge cases added toTestGetGitHubHostForRepo_PublicOrgFallback.//go:build !integrationif no integration resources are needed.make test-unitpasses with no regressions.