Skip to content

Commit 7c388cc

Browse files
author
Bryan C. Mills
committed
go/internal/srcimporter: set -mod=vendor before running tests
Otherwise, if the working directory is inside a standard-library module, the test may try to fetch module contents from GOPROXY or upstream. Updates #26924 Updates #30228 Updates #30241 Change-Id: I4cb9a07721bd808fd094f7ed55a74cf7bce9cd6f Reviewed-on: https://go-review.googlesource.com/c/164625 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 8eef74b commit 7c388cc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/go/internal/srcimporter/srcimporter_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"go/types"
1111
"internal/testenv"
1212
"io/ioutil"
13+
"os"
1314
"path"
1415
"path/filepath"
1516
"runtime"
@@ -18,6 +19,23 @@ import (
1819
"time"
1920
)
2021

22+
func TestMain(m *testing.M) {
23+
// Add -mod=vendor to GOFLAGS to ensure that we don't fetch modules while importing std or cmd.
24+
//
25+
// TODO(golang.org/issue/30240): If we load go.mod files from vendor/
26+
// automatically, this will probably no longer be necessary.
27+
var goflags []string
28+
for _, f := range strings.Fields(os.Getenv("GOFLAGS")) {
29+
if !strings.HasPrefix(f, "-mod=") && !strings.HasPrefix(f, "--mod=") {
30+
goflags = append(goflags, f)
31+
}
32+
}
33+
goflags = append(goflags, "-mod=vendor")
34+
os.Setenv("GOFLAGS", strings.Join(goflags, " "))
35+
36+
os.Exit(m.Run())
37+
}
38+
2139
const maxTime = 2 * time.Second
2240

2341
var importer = New(&build.Default, token.NewFileSet(), make(map[string]*types.Package))

0 commit comments

Comments
 (0)