From 0245e1dfc6b09a30ad018bdcdadef4961067cfd4 Mon Sep 17 00:00:00 2001 From: Michael Matloob Date: Thu, 1 Jun 2023 15:02:12 -0400 Subject: [PATCH] gopls/internal/regtest/codelens: set GOWORK=off for go mod vendor We might be introducing vendoring for workspace mode. Set GOWORK=off when running go mod vendor in a single module context to make sure it has the right behavior and doesn't return an error. For golang/go#60056 Change-Id: I703d74d579aec6e4dad86ca092e3651e0b2e4eb0 Reviewed-on: https://go-review.googlesource.com/c/tools/+/499977 TryBot-Result: Gopher Robot Run-TryBot: Michael Matloob gopls-CI: kokoro Reviewed-by: Robert Findley --- gopls/internal/lsp/regtest/wrappers.go | 9 +++++++++ gopls/internal/regtest/codelens/codelens_test.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gopls/internal/lsp/regtest/wrappers.go b/gopls/internal/lsp/regtest/wrappers.go index 163960fa407..5d5d2f778f4 100644 --- a/gopls/internal/lsp/regtest/wrappers.go +++ b/gopls/internal/lsp/regtest/wrappers.go @@ -270,6 +270,15 @@ func (e *Env) RunGoCommandInDir(dir, verb string, args ...string) { } } +// RunGoCommandInDirWithEnv is like RunGoCommand, but executes in the given +// relative directory of the sandbox with the given additional environment variables. +func (e *Env) RunGoCommandInDirWithEnv(dir string, env []string, verb string, args ...string) { + e.T.Helper() + if err := e.Sandbox.RunGoCommand(e.Ctx, dir, verb, args, env, true); err != nil { + e.T.Fatal(err) + } +} + // GoVersion checks the version of the go command. // It returns the X in Go 1.X. func (e *Env) GoVersion() int { diff --git a/gopls/internal/regtest/codelens/codelens_test.go b/gopls/internal/regtest/codelens/codelens_test.go index 68f2982cd19..8f718855f66 100644 --- a/gopls/internal/regtest/codelens/codelens_test.go +++ b/gopls/internal/regtest/codelens/codelens_test.go @@ -201,7 +201,7 @@ require golang.org/x/hello v1.2.3 t.Run(fmt.Sprintf("Upgrade individual dependency vendoring=%v", vendoring), func(t *testing.T) { WithOptions(ProxyFiles(proxyWithLatest)).Run(t, shouldUpdateDep, func(t *testing.T, env *Env) { if vendoring { - env.RunGoCommandInDir("a", "mod", "vendor") + env.RunGoCommandInDirWithEnv("a", []string{"GOWORK=off"}, "mod", "vendor") } env.AfterChange() env.OpenFile("a/go.mod")