From: Ian Alexander Date: Fri, 10 Oct 2025 12:58:31 +0000 (-0400) Subject: cmd/go: use local loader state in test X-Git-Tag: go1.26rc1~478 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=54e3adc53321b9352bd0ae2aebae597d31873124;p=gostls13.git cmd/go: use local loader state in test This change converts the import test to use a local module loader state variable, instead of the dependency on global state. This commit is part of the overall effort to eliminate global modloader state. Change-Id: I5687090c160bf64ce36356768f7cf74333fab724 Reviewed-on: https://go-review.googlesource.com/c/go/+/711138 Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/go/internal/modload/import_test.go b/src/cmd/go/internal/modload/import_test.go index a5c4b837a0..0716675a91 100644 --- a/src/cmd/go/internal/modload/import_test.go +++ b/src/cmd/go/internal/modload/import_test.go @@ -56,25 +56,25 @@ var importTests = []struct { } func TestQueryImport(t *testing.T) { + loaderstate := NewState() + loaderstate.RootMode = NoRoot + testenv.MustHaveExternalNetwork(t) testenv.MustHaveExecPath(t, "git") oldAllowMissingModuleImports := allowMissingModuleImports - oldRootMode := LoaderState.RootMode defer func() { allowMissingModuleImports = oldAllowMissingModuleImports - LoaderState.RootMode = oldRootMode }() allowMissingModuleImports = true - LoaderState.RootMode = NoRoot ctx := context.Background() - rs := LoadModFile(LoaderState, ctx) + rs := LoadModFile(loaderstate, ctx) for _, tt := range importTests { t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) { // Note that there is no build list, so Import should always fail. - m, err := queryImport(LoaderState, ctx, tt.path, rs) + m, err := queryImport(loaderstate, ctx, tt.path, rs) if tt.err == "" { if err != nil {