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")