revert to default GOPATH if necessary (#279)

* revert to default GOPATH if necessary
This commit is contained in:
Joaquin L. Pereyra 2019-02-06 20:34:52 -03:00 committed by Grant Murphy
parent 04ce7baf6c
commit e2752bc191

View file

@ -31,8 +31,14 @@ type TestPackage struct {
// NewTestPackage will create a new and empty package. Must call Close() to cleanup // NewTestPackage will create a new and empty package. Must call Close() to cleanup
// auxiliary files // auxiliary files
func NewTestPackage() *TestPackage { func NewTestPackage() *TestPackage {
goPath := os.Getenv("GOPATH")
// if user did not set GOPATH, set to the default
if goPath == "" {
goPath = build.Default.GOPATH
}
// Files must exist in $GOPATH // Files must exist in $GOPATH
sourceDir := path.Join(os.Getenv("GOPATH"), "src") sourceDir := path.Join(goPath, "src")
workingDir, err := ioutil.TempDir(sourceDir, "gosecs_test") workingDir, err := ioutil.TempDir(sourceDir, "gosecs_test")
if err != nil { if err != nil {
return nil return nil