From 3b1828d79f0f9acd82878034008bf70c3d198585 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 1 May 2018 14:03:38 -0700 Subject: [PATCH] pkg/test: remove check that GOPATH is set We can also use the implicit one, so don't require an explicit one. Change-Id: Ie4712be849f40b8f8cc30f99d019dd863944289f --- internal/osutil/paths.go | 13 ++++++++++--- pkg/test/world.go | 7 ++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/internal/osutil/paths.go b/internal/osutil/paths.go index ea2a08ee8..3ae8f487a 100644 --- a/internal/osutil/paths.go +++ b/internal/osutil/paths.go @@ -275,12 +275,19 @@ func NewJSONConfigParser() *jsonconfig.ConfigParser { // GoPackagePath returns the path to the provided Go package's // source directory. // pkg may be a path prefix without any *.go files. -// The error is os.ErrNotExist if GOPATH is unset or the directory -// doesn't exist in any GOPATH component. +// The error is os.ErrNotExist if GOPATH is unset. func GoPackagePath(pkg string) (path string, err error) { gp := os.Getenv("GOPATH") if gp == "" { - return path, os.ErrNotExist + cmd := exec.Command("go", "env", "GOPATH") + out, err := cmd.Output() + if err != nil { + return "", fmt.Errorf("could not run 'go env GOPATH': %v, %s", err, out) + } + gp = strings.TrimSpace(string(out)) + if gp == "" { + return "", os.ErrNotExist + } } for _, p := range filepath.SplitList(gp) { dir := filepath.Join(p, "src", filepath.FromSlash(pkg)) diff --git a/pkg/test/world.go b/pkg/test/world.go index 65dd973ad..309656123 100644 --- a/pkg/test/world.go +++ b/pkg/test/world.go @@ -57,9 +57,6 @@ type World struct { // pkSourceRoot returns the root of the source tree, or an error. func pkSourceRoot() (string, error) { - if os.Getenv("GOPATH") == "" { - return "", errors.New("GOPATH environment variable isn't set; required to run Perkeep integration tests") - } root, err := osutil.GoPackagePath("perkeep.org") if err == os.ErrNotExist { return "", errors.New("directory \"perkeep.org\" not found under GOPATH/src; can't run Perkeep integration tests") @@ -68,14 +65,14 @@ func pkSourceRoot() (string, error) { } // NewWorld returns a new test world. -// It requires that GOPATH is set to find the "perkeep.org" root. +// It uses the GOPATH (explicit or implicit) to find the "perkeep.org" root. func NewWorld() (*World, error) { return WorldFromConfig("server-config.json") } // WorldFromConfig returns a new test world based on the given configuration file. // This cfg is the server config relative to pkg/test/testdata. -// It requires that GOPATH is set to find the "perkeep.org" root. +// It uses the GOPATH (explicit or implicit) to find the "perkeep.org" root. func WorldFromConfig(cfg string) (*World, error) { root, err := pkSourceRoot() if err != nil {