diff options
| author | Bryan C. Mills <bcmills@google.com> | 2019-03-01 09:23:44 -0500 |
|---|---|---|
| committer | Bryan C. Mills <bcmills@google.com> | 2019-03-01 17:21:57 +0000 |
| commit | 7c388cc89c76bc7167287fb488afcaf5a4aa12bf (patch) | |
| tree | bb9f676240e5f59e9b6fe7713aa91e720bd1aaf5 /src | |
| parent | 8eef74b493e48f3dfac6619b01ac7efe26c134b5 (diff) | |
| download | go-7c388cc89c76bc7167287fb488afcaf5a4aa12bf.tar.xz | |
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 <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/go/internal/srcimporter/srcimporter_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/go/internal/srcimporter/srcimporter_test.go b/src/go/internal/srcimporter/srcimporter_test.go index b84672610c..f8e1c323b3 100644 --- a/src/go/internal/srcimporter/srcimporter_test.go +++ b/src/go/internal/srcimporter/srcimporter_test.go @@ -10,6 +10,7 @@ import ( "go/types" "internal/testenv" "io/ioutil" + "os" "path" "path/filepath" "runtime" @@ -18,6 +19,23 @@ import ( "time" ) +func TestMain(m *testing.M) { + // Add -mod=vendor to GOFLAGS to ensure that we don't fetch modules while importing std or cmd. + // + // TODO(golang.org/issue/30240): If we load go.mod files from vendor/ + // automatically, this will probably no longer be necessary. + var goflags []string + for _, f := range strings.Fields(os.Getenv("GOFLAGS")) { + if !strings.HasPrefix(f, "-mod=") && !strings.HasPrefix(f, "--mod=") { + goflags = append(goflags, f) + } + } + goflags = append(goflags, "-mod=vendor") + os.Setenv("GOFLAGS", strings.Join(goflags, " ")) + + os.Exit(m.Run()) +} + const maxTime = 2 * time.Second var importer = New(&build.Default, token.NewFileSet(), make(map[string]*types.Package)) |
