Run validation in the selected module

This commit is contained in:
2026-10-10 02:43:23 +00:00
parent 02896b6e12
commit 8350cbf9c9
17 changed files with 577 additions and 55 deletions

View File

@@ -301,6 +301,72 @@ func TestPersistentSettingsPreserveCachesAndNativeCTools(t *testing.T) {
}
}
func TestOwnerReusesSettingsUntilInheritedEnvironmentChanges(t *testing.T) {
clearGoSettings(t)
t.Setenv("GOENV", "off")
owner := NewOwner(t.TempDir())
first, err := owner.Acquire(context.Background())
if err != nil {
t.Fatal(err)
}
second, err := owner.Acquire(context.Background())
if err != nil {
t.Fatal(err)
}
if first != second {
t.Fatal("unchanged Go inputs caused settings discovery to be repeated")
}
cache := filepath.Join(t.TempDir(), "changed-cache")
t.Setenv("GOCACHE", cache)
if err := owner.Refresh(context.Background()); err != nil {
t.Fatal(err)
}
third, err := owner.Acquire(context.Background())
if err != nil {
t.Fatal(err)
}
if third == first || third.settings["GOCACHE"] != cache {
t.Fatalf("changed inherited environment kept stale settings: tool=%p GOCACHE=%q", third, third.settings["GOCACHE"])
}
}
func TestOwnerRefreshesWhenPersistentSettingsChange(t *testing.T) {
clearGoSettings(t)
firstCache := filepath.Join(t.TempDir(), "first-cache")
secondCache := filepath.Join(t.TempDir(), "second-cache")
settingsFile := filepath.Join(t.TempDir(), "go-env")
writeSettings := func(cache string) {
t.Helper()
if err := os.WriteFile(settingsFile, []byte("GOCACHE="+cache+"\n"), 0o600); err != nil {
t.Fatal(err)
}
}
writeSettings(firstCache)
t.Setenv("GOENV", settingsFile)
owner := NewOwner(t.TempDir())
first, err := owner.Acquire(context.Background())
if err != nil {
t.Fatal(err)
}
if first.settings["GOCACHE"] != firstCache {
t.Fatalf("initial GOCACHE = %q, want %q", first.settings["GOCACHE"], firstCache)
}
writeSettings(secondCache)
if err := owner.Refresh(context.Background()); err != nil {
t.Fatal(err)
}
second, err := owner.Acquire(context.Background())
if err != nil {
t.Fatal(err)
}
if second == first || second.settings["GOCACHE"] != secondCache {
t.Fatalf("changed persistent settings were not rediscovered: tool=%p GOCACHE=%q", second, second.settings["GOCACHE"])
}
}
func readSettings(t *testing.T, tool *Tool, mode Mode, target Target, names ...string) map[string]string {
t.Helper()
args := append([]string{"env", "-json"}, names...)