Files
archie/internal/forge/github_test.go
T
sam 15d746c2f6 style: phase 1 of lint remediation — autofix pass (qa4)
golangci-lint run --fix plus the formatters: errorlint, gocritic,
sloglint, usestdlibvars, usetesting, gci, gofumpt, goimports.
160 issues -> 130.

One autofix was wrong and had to be reverted by hand. gocritic rewrote

    ctx, cancel = context.WithTimeout(ctx, m.prefetchTimeout)

to `:=` inside an if-block in internal/memory/manager.go. That does not
compile, which is the good outcome — had it compiled, the shadowed ctx
would have scoped the timeout to the if-block and the prefetch deadline
would silently never have applied. Restored the assignment and commented
why it must not be a declaration.

Worth recording: --fix is not a safe no-op. It broke the build on a
24-file change, and the failure mode it was one compiler error away from
was a silent behaviour change.
2026-07-28 01:37:20 +10:00

45 lines
1.0 KiB
Go

package forge
import (
"log/slog"
"testing"
)
func TestNewConfiguresHost(t *testing.T) {
tests := []struct {
name string
host string
wantBase string
wantUpload string
}{
{
name: "github.com",
host: "https://github.com",
wantBase: "https://api.github.com/",
wantUpload: "https://uploads.github.com/",
},
{
name: "enterprise",
host: "https://git.example.com",
wantBase: "https://git.example.com/api/v3/",
wantUpload: "https://git.example.com/api/uploads/",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
f, err := New("github", "token", tt.host, slog.New(slog.DiscardHandler))
if err != nil {
t.Fatal(err)
}
client := f.(*GitHubClient)
if got := client.gh.BaseURL.String(); got != tt.wantBase {
t.Errorf("BaseURL = %q, want %q", got, tt.wantBase)
}
if got := client.gh.UploadURL.String(); got != tt.wantUpload {
t.Errorf("UploadURL = %q, want %q", got, tt.wantUpload)
}
})
}
}