Skip to content

Commit 54e3adc

Browse files
committed
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 <matloob@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent ca379b1 commit 54e3adc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,25 +56,25 @@ var importTests = []struct {
5656
}
5757

5858
func TestQueryImport(t *testing.T) {
59+
loaderstate := NewState()
60+
loaderstate.RootMode = NoRoot
61+
5962
testenv.MustHaveExternalNetwork(t)
6063
testenv.MustHaveExecPath(t, "git")
6164

6265
oldAllowMissingModuleImports := allowMissingModuleImports
63-
oldRootMode := LoaderState.RootMode
6466
defer func() {
6567
allowMissingModuleImports = oldAllowMissingModuleImports
66-
LoaderState.RootMode = oldRootMode
6768
}()
6869
allowMissingModuleImports = true
69-
LoaderState.RootMode = NoRoot
7070

7171
ctx := context.Background()
72-
rs := LoadModFile(LoaderState, ctx)
72+
rs := LoadModFile(loaderstate, ctx)
7373

7474
for _, tt := range importTests {
7575
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
7676
// Note that there is no build list, so Import should always fail.
77-
m, err := queryImport(LoaderState, ctx, tt.path, rs)
77+
m, err := queryImport(loaderstate, ctx, tt.path, rs)
7878

7979
if tt.err == "" {
8080
if err != nil {

0 commit comments

Comments
 (0)