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
This commit is contained in:
Brad Fitzpatrick 2018-05-01 14:03:38 -07:00
parent 2f39adc517
commit 3b1828d79f
2 changed files with 12 additions and 8 deletions

View File

@ -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))

View File

@ -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 {