]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: use local loader state in test
authorIan Alexander <jitsu@google.com>
Fri, 10 Oct 2025 12:58:31 +0000 (08:58 -0400)
committerIan Alexander <jitsu@google.com>
Sun, 26 Oct 2025 21:11:34 +0000 (14:11 -0700)
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 <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/modload/import_test.go

index a5c4b837a0be12192f03ffdc8b5ca5cda4e084f6..0716675a91d2bd6f2f78c9c7c422ae118d094424 100644 (file)
@@ -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 {