1
0
mirror of https://github.com/golang/go synced 2024-11-05 11:36:10 -07:00

cmd/godoc: fix TestWebIndex test

The godoc in the test was indexing sources in the default GOPATH.
If the default GOPATH pointed to local workspace, test would timeout.
The fix is to supply GOPATH set to non-existing path.

Fixes golang/go#24504

Change-Id: Iedf044cdec78d5c5642105650ad8ec17aa10a5ba
Reviewed-on: https://go-review.googlesource.com/102295
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Yury Smolsky 2018-03-23 13:59:17 +02:00 committed by Brad Fitzpatrick
parent 4c0f0e48a6
commit 77106db15f

View File

@ -236,7 +236,12 @@ func testWeb(t *testing.T, withIndex bool) {
cmd.Stdout = os.Stderr
cmd.Stderr = os.Stderr
cmd.Args[0] = "godoc"
cmd.Env = godocEnv()
// Set GOPATH variable to non-existing path.
// We cannot just unset GOPATH variable because godoc would default it to ~/go.
// (We don't want the indexer looking at the local workspace during tests.)
cmd.Env = append(os.Environ(), "GOPATH=does_not_exist")
if err := cmd.Start(); err != nil {
t.Fatalf("failed to start godoc: %s", err)
}
@ -390,14 +395,9 @@ func main() { print(lib.V) }
defer cleanup()
addr := serverAddress(t)
cmd := exec.Command(bin, fmt.Sprintf("-http=%s", addr), "-analysis=type")
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("GOROOT=%s", filepath.Join(tmpdir, "goroot")))
cmd.Env = append(cmd.Env, fmt.Sprintf("GOPATH=%s", filepath.Join(tmpdir, "gopath")))
for _, e := range os.Environ() {
if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") {
continue
}
cmd.Env = append(cmd.Env, e)
}
cmd.Stdout = os.Stderr
stderr, err := cmd.StderrPipe()
if err != nil {
@ -475,15 +475,3 @@ tryagain:
}
}
}
// godocEnv returns the process environment without the GOPATH variable.
// (We don't want the indexer looking at the local workspace during tests.)
func godocEnv() (env []string) {
for _, v := range os.Environ() {
if strings.HasPrefix(v, "GOPATH=") {
continue
}
env = append(env, v)
}
return
}