From 0f74faf7acb716941e462d4234f0d5b196e41f69 Mon Sep 17 00:00:00 2001 From: "Santiago M. Mola" Date: Thu, 8 Dec 2016 20:33:00 +0100 Subject: 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. --- fixtures/fixtures.go | 15 ++++++--------- 1 file 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) } } -- cgit