Make the external test work on more environments

GOPATH is actually a list of path and doesn't necessarily have to be
set. If unset it will default to $GOPATH/go in go 1.9+.

Assume that go install will install to the first path in the list.
This commit is contained in:
zimbatm 2017-03-31 11:46:48 +01:00 committed by Martin Atkins
parent 77d1709c32
commit 6ed873b72d
1 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"testing"
@ -117,8 +118,13 @@ func buildDataSourceTestProgram() (string, error) {
return "", fmt.Errorf("failed to build test stub program: %s", err)
}
gopath := os.Getenv("GOPATH")
if gopath == "" {
gopath = filepath.Join(os.Getenv("HOME") + "/go")
}
programPath := path.Join(
os.Getenv("GOPATH"), "bin", "tf-acc-external-data-source",
filepath.SplitList(gopath)[0], "bin", "tf-acc-external-data-source",
)
return programPath, nil
}