mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
ca379b1c56
commit
54e3adc533
1 changed files with 5 additions and 5 deletions
|
|
@ -56,25 +56,25 @@ var importTests = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestQueryImport(t *testing.T) {
|
func TestQueryImport(t *testing.T) {
|
||||||
|
loaderstate := NewState()
|
||||||
|
loaderstate.RootMode = NoRoot
|
||||||
|
|
||||||
testenv.MustHaveExternalNetwork(t)
|
testenv.MustHaveExternalNetwork(t)
|
||||||
testenv.MustHaveExecPath(t, "git")
|
testenv.MustHaveExecPath(t, "git")
|
||||||
|
|
||||||
oldAllowMissingModuleImports := allowMissingModuleImports
|
oldAllowMissingModuleImports := allowMissingModuleImports
|
||||||
oldRootMode := LoaderState.RootMode
|
|
||||||
defer func() {
|
defer func() {
|
||||||
allowMissingModuleImports = oldAllowMissingModuleImports
|
allowMissingModuleImports = oldAllowMissingModuleImports
|
||||||
LoaderState.RootMode = oldRootMode
|
|
||||||
}()
|
}()
|
||||||
allowMissingModuleImports = true
|
allowMissingModuleImports = true
|
||||||
LoaderState.RootMode = NoRoot
|
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
rs := LoadModFile(LoaderState, ctx)
|
rs := LoadModFile(loaderstate, ctx)
|
||||||
|
|
||||||
for _, tt := range importTests {
|
for _, tt := range importTests {
|
||||||
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
|
t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) {
|
||||||
// Note that there is no build list, so Import should always fail.
|
// 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 tt.err == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue