Skip to content

Commit

Permalink
Support e2e-go tests when repo is not installed in GOPATH. (#3949)
Browse files Browse the repository at this point in the history
Running e2e go tests fails when the repo is not cloned inside the GOPATH.
This change looks up the current directory using runtime.Caller
as an alternative to hard coding the GOPATH location.
  • Loading branch information
winder authored May 4, 2022
1 parent 7a0cd7f commit 370d828
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 12 additions & 1 deletion test/framework/fixtures/baseFixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"runtime"
"testing"

"github.com/algorand/go-algorand/config"
Expand All @@ -35,6 +37,15 @@ type baseFixture struct {
instance Fixture
}

func getTestDir() string {
_, filename, _, ok := runtime.Caller(0)
if ok {
return path.Join(path.Dir(filename), "..", "..")
}
// fallback to the legacy GOPATH location.
return os.ExpandEnv("${GOPATH}/src/github.com/algorand/go-algorand/test/")
}

func (f *baseFixture) initialize(instance Fixture) {
f.instance = instance
f.Config = config.Protocol
Expand All @@ -49,7 +60,7 @@ func (f *baseFixture) initialize(instance Fixture) {
}
f.testDataDir = os.Getenv("TESTDATADIR")
if f.testDataDir == "" {
f.testDataDir = os.ExpandEnv("${GOPATH}/src/github.com/algorand/go-algorand/test/testdata")
f.testDataDir = path.Join(getTestDir(), "testdata")
}
}

Expand Down
5 changes: 1 addition & 4 deletions test/framework/fixtures/expectFixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"path"
"path/filepath"
"regexp"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -58,9 +57,7 @@ func (ef *ExpectFixture) initialize(t *testing.T) (err error) {
}
ef.testDataDir = os.Getenv("TESTDATADIR")
if ef.testDataDir == "" {
// Default to test/testdata in the source tree being tested
_, path, _, _ := runtime.Caller(0)
ef.testDataDir = filepath.Join(filepath.Dir(path), "../../testdata")
ef.testDataDir = filepath.Join(getTestDir(), "testdata")
}

ef.testFilter = os.Getenv("TESTFILTER")
Expand Down

0 comments on commit 370d828

Please sign in to comment.