From e549c1819773fd8ab302ecd1b7650c25aafaba43 Mon Sep 17 00:00:00 2001 From: Antonio Navarro Perez Date: Mon, 23 Jan 2017 13:29:19 +0100 Subject: fixtures: support more than one source folder (fix #217) (#219) GOPATH can contain more than one folder separated by ':'. To check it correctly, we use SrcDirs() method to be able to check into all the source folders if fixtures exists. --- fixtures/fixtures.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/fixtures/fixtures.go b/fixtures/fixtures.go index 8311d8b..6a86bdd 100644 --- a/fixtures/fixtures.go +++ b/fixtures/fixtures.go @@ -1,6 +1,7 @@ package fixtures import ( + "errors" "fmt" "go/build" "io/ioutil" @@ -28,7 +29,7 @@ var fixtures = Fixtures{{ PackfileHash: plumbing.NewHash("135fe3d1ad828afe68706f1d481aedbcfa7a86d2"), DotGitHash: plumbing.NewHash("78c5fb882e76286d8201016cffee63ea7060a0c2"), ObjectsCount: 68, -},{ +}, { Tags: []string{"packfile", "ofs-delta", ".git"}, URL: "https://github.com/git-fixtures/basic.git", Head: plumbing.NewHash("6ecf0ef2c2dffb796033e5a02219af86ec6584e5"), @@ -265,11 +266,21 @@ func (g Fixtures) Exclude(tag string) Fixtures { } // Init set the correct path to be able to access to the fixtures files -func Init() { - RootFolder = filepath.Join( - build.Default.GOPATH, - "src", "gopkg.in/src-d/go-git.v4", "fixtures", - ) +func Init() error { + srcs := build.Default.SrcDirs() + + for _, src := range srcs { + rf := filepath.Join( + src, "gopkg.in/src-d/go-git.v4", "fixtures", + ) + + if _, err := os.Stat(rf); err == nil { + RootFolder = rf + return nil + } + } + + return errors.New("fixtures folder not found") } // Clean cleans all the temporal files created @@ -289,7 +300,7 @@ func Clean() error { type Suite struct{} func (s *Suite) SetUpSuite(c *check.C) { - Init() + c.Assert(Init(), check.IsNil) } func (s *Suite) TearDownSuite(c *check.C) { -- cgit