test: require repository URL override precedence

This commit is contained in:
Micheal Wilkinson
2026-03-20 23:40:07 +00:00
parent d91ec2f6b1
commit f79eda21c1

View File

@@ -121,3 +121,26 @@ func TestDeriveRepositoryURLFromGitConfigFallback(t *testing.T) {
t.Fatalf("unexpected repository URL: %q", url) t.Fatalf("unexpected repository URL: %q", url)
} }
} }
func TestDeriveRepositoryURL_UsesOverrideAsHighestPriority(t *testing.T) {
t.Setenv("VOCIFERATE_REPOSITORY_URL", "https://git.hrafn.xyz/aether/vociferate")
t.Setenv("GITHUB_SERVER_URL", "http://teapot:3000")
t.Setenv("GITHUB_REPOSITORY", "aether/vociferate")
root := t.TempDir()
configPath := filepath.Join(root, ".git", "config")
if err := os.MkdirAll(filepath.Dir(configPath), 0o755); err != nil {
t.Fatalf("mkdir .git: %v", err)
}
if err := os.WriteFile(configPath, []byte("[remote \"origin\"]\n\turl = git@different.host:org/other.git\n"), 0o644); err != nil {
t.Fatalf("write git config: %v", err)
}
url, ok := deriveRepositoryURL(root)
if !ok {
t.Fatal("expected repository URL from override")
}
if url != "https://git.hrafn.xyz/aether/vociferate" {
t.Fatalf("unexpected repository URL: %q", url)
}
}