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>
diff --git a/test.bash b/test.bash
index f3a4d5c..8d25906 100755
--- a/test.bash
+++ b/test.bash
@@ -55,11 +55,11 @@
 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.