test.bash: set GOPATH before running go list

The "go list" command is used only to get the module name.
However, just invoking the command results in a series of network IO
fetching package information about dependencies.
That information is then placed in the default GOPATH,
which previously was the system's default.

This is not generally a problem, but results in additional time spent
in Travis since the system's GOPATH is not cached between test runs.
By setting the GOPATH beforehand to be within TEST_DIR, we can ensure
that the result is cached and preserved between runs.

Change-Id: Ib750a9a31b9891b354fe9a70b3f592d949186ba3
Reviewed-on: https://go-review.googlesource.com/136738
Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
Joe Tsai 2018-09-22 16:00:02 -07:00 committed by Joe Tsai
parent ded92f8033
commit b4af2c62e0

View File

@ -55,11 +55,11 @@ register_binary gofmt $GO_LATEST/bin/gofmt
unset GOROOT
# Setup GOPATH for pre-module support.
export GOPATH=$TEST_DIR/gopath
MODULE_PATH=$(cd $REPO_ROOT && go list -m -f "{{.Path}}")
rm -f gopath/src/$MODULE_PATH # best-effort delete
rm -rf gopath/src # best-effort delete
mkdir -p gopath/src/$(dirname $MODULE_PATH)
(cd gopath/src/$(dirname $MODULE_PATH) && ln -s $REPO_ROOT $(basename $MODULE_PATH))
export GOPATH=$TEST_DIR/gopath
# Download dependencies using modules.
# For pre-module support, dump the dependencies in a vendor directory.