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:
parent
33bf6d0c02
commit
bc909834c2
1 changed files with 10 additions and 0 deletions
|
|
@ -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"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue