diff options
author | Santiago M. Mola <santi@mola.io> | 2016-12-08 20:33:00 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-12-08 20:33:00 +0100 |
commit | 0f74faf7acb716941e462d4234f0d5b196e41f69 (patch) | |
tree | 469cceb06cca278ccb91673015eb6259a5af27e2 | |
parent | 7d9d9bfee34ea428a127da0df900d3a26de37c38 (diff) | |
download | go-git-0f74faf7acb716941e462d4234f0d5b196e41f69.tar.gz |
fixtures: always returna a new directory with DotGit. (#169)
DotGit now creates a new temporary directory on every call. This
allows test to easily get multiple copies of the same repository
(e.g. to test fetch/push cases). It also ensures that tests do
not have side effects on other tests unless they share the path
from the same DotGit call.
-rw-r--r-- | fixtures/fixtures.go | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/fixtures/fixtures.go b/fixtures/fixtures.go index 7cfceae..e751423 100644 --- a/fixtures/fixtures.go +++ b/fixtures/fixtures.go @@ -19,7 +19,7 @@ var RootFolder = "" const DataFolder = "data" -var folders = make(map[string]string, 0) +var folders = make(map[string]bool, 0) var fixtures = Fixtures{{ Tags: []string{"packfile", "ofs-delta", ".git"}, @@ -180,19 +180,16 @@ func (f *Fixture) Idx() *os.File { return file } +// DotGit creates a new temporary directory and unpacks the repository .git +// directory into it. Multiple calls to DotGit returns different directories. func (f *Fixture) DotGit() fs.Filesystem { - h := f.DotGitHash.String() - if path, ok := folders[h]; ok { - return osfs.New(path) - } - fn := filepath.Join(RootFolder, DataFolder, fmt.Sprintf("git-%s.tgz", f.DotGitHash)) path, err := tgz.Extract(fn) if err != nil { panic(err) } - folders[h] = path + folders[path] = true return osfs.New(path) } @@ -270,10 +267,10 @@ func (s *Suite) SetUpSuite(c *check.C) { } func (s *Suite) TearDownSuite(c *check.C) { - for hash, f := range folders { + for f := range folders { err := os.RemoveAll(f) c.Assert(err, check.IsNil) - delete(folders, hash) + delete(folders, f) } } |