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.
31 lines
652 B
Go
31 lines
652 B
Go
package forge
|
|
|
|
import (
|
|
"log/slog"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"testing"
|
|
|
|
"github.com/google/go-github/v78/github"
|
|
)
|
|
|
|
// newTestClient wires a GitHubClient at a local httptest server so its
|
|
// methods can be exercised without hitting the real GitHub API.
|
|
func newTestClient(t *testing.T) (*GitHubClient, *http.ServeMux) {
|
|
t.Helper()
|
|
mux := http.NewServeMux()
|
|
srv := httptest.NewServer(mux)
|
|
t.Cleanup(srv.Close)
|
|
|
|
gh := github.NewClient(nil)
|
|
base, err := url.Parse(srv.URL + "/")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
gh.BaseURL = base
|
|
gh.UploadURL = base
|
|
|
|
return &GitHubClient{gh: gh, log: slog.New(slog.DiscardHandler)}, mux
|
|
}
|