test(cmd/bd): preserve GOMODCACHE across the test HOME re-home

testMainInner already pins GOCACHE before pointing HOME at a temp dir,
but GOMODCACHE (default $HOME/go/pkg/mod) was left to follow the fake
HOME, so every buildEmbeddedBD run re-downloaded the full module set —
several minutes per run and a hard failure offline.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge 2026-06-12 17:58:55 -04:00
commit bc909834c2

View file

@ -72,6 +72,16 @@ func testMainInner(m *testing.M) int {
}
}
// Same for the module cache: GOMODCACHE defaults to $HOME/go/pkg/mod,
// so without this the in-test `go build` (buildEmbeddedBD) re-downloads
// every dependency into the temp HOME on each run — slow, and a hard
// failure when the network is unavailable.
if os.Getenv("GOMODCACHE") == "" {
if out, err := exec.Command("go", "env", "GOMODCACHE").Output(); err == nil {
_ = os.Setenv("GOMODCACHE", strings.TrimSpace(string(out)))
}
}
_ = os.Setenv("HOME", tmp)
_ = os.Setenv("USERPROFILE", tmp) // Windows compatibility
_ = os.Setenv("XDG_CONFIG_HOME", filepath.Join(tmp, "xdg-config"))