diff options
author | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-18 21:56:00 -0800 |
---|---|---|
committer | Joshua Sjoding <joshua.sjoding@scjalliance.com> | 2016-02-18 23:17:19 -0800 |
commit | 8e4fb520044f01e3f79c03e4752005dddc359188 (patch) | |
tree | 8295ee0c4fb1360d91b084f6ff8cf36e595a4fcd /common_test.go | |
parent | ffe26fecc9b1435054d851ef93f156536f2a4584 (diff) | |
download | go-git-8e4fb520044f01e3f79c03e4752005dddc359188.tar.gz |
Added helper function for test fixture unpacking
Diffstat (limited to 'common_test.go')
-rw-r--r-- | common_test.go | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/common_test.go b/common_test.go index 0cd61f1..fe8227b 100644 --- a/common_test.go +++ b/common_test.go @@ -7,6 +7,7 @@ import ( "gopkg.in/src-d/go-git.v3/clients/common" "gopkg.in/src-d/go-git.v3/core" + "gopkg.in/src-d/go-git.v3/formats/packfile" . "gopkg.in/check.v1" ) @@ -46,15 +47,41 @@ func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadC return s.RC, err } -var fixtureRepos = [...]struct { +type packedFixture struct { url string packfile string -}{ +} + +var fixtureRepos = []packedFixture{ {"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"}, {"https://github.com/jamesob/desk.git", "formats/packfile/fixtures/jamesob-desk.pack"}, {"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"}, } +func unpackFixtures(c *C, fixtures ...[]packedFixture) map[string]*Repository { + repos := make(map[string]*Repository, 0) + for _, group := range fixtures { + for _, fixture := range group { + if _, existing := repos[fixture.url]; existing { + continue + } + repos[fixture.url] = NewPlainRepository() + + d, err := os.Open(fixture.packfile) + c.Assert(err, IsNil) + + r := packfile.NewReader(d) + r.Format = packfile.OFSDeltaFormat // TODO: how to know the format of a pack file ahead of time? + + _, err = r.Read(repos[fixture.url].Storage) + c.Assert(err, IsNil) + + c.Assert(d.Close(), IsNil) + } + } + return repos +} + type SuiteCommon struct{} var _ = Suite(&SuiteCommon{}) |