Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 8e4fb52

Browse files
committed
Added helper function for test fixture unpacking
1 parent ffe26fe commit 8e4fb52

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

common_test.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"gopkg.in/src-d/go-git.v3/clients/common"
99
"gopkg.in/src-d/go-git.v3/core"
10+
"gopkg.in/src-d/go-git.v3/formats/packfile"
1011

1112
. "gopkg.in/check.v1"
1213
)
@@ -46,15 +47,41 @@ func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadC
4647
return s.RC, err
4748
}
4849

49-
var fixtureRepos = [...]struct {
50+
type packedFixture struct {
5051
url string
5152
packfile string
52-
}{
53+
}
54+
55+
var fixtureRepos = []packedFixture{
5356
{"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"},
5457
{"https://github.com/jamesob/desk.git", "formats/packfile/fixtures/jamesob-desk.pack"},
5558
{"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"},
5659
}
5760

61+
func unpackFixtures(c *C, fixtures ...[]packedFixture) map[string]*Repository {
62+
repos := make(map[string]*Repository, 0)
63+
for _, group := range fixtures {
64+
for _, fixture := range group {
65+
if _, existing := repos[fixture.url]; existing {
66+
continue
67+
}
68+
repos[fixture.url] = NewPlainRepository()
69+
70+
d, err := os.Open(fixture.packfile)
71+
c.Assert(err, IsNil)
72+
73+
r := packfile.NewReader(d)
74+
r.Format = packfile.OFSDeltaFormat // TODO: how to know the format of a pack file ahead of time?
75+
76+
_, err = r.Read(repos[fixture.url].Storage)
77+
c.Assert(err, IsNil)
78+
79+
c.Assert(d.Close(), IsNil)
80+
}
81+
}
82+
return repos
83+
}
84+
5885
type SuiteCommon struct{}
5986

6087
var _ = Suite(&SuiteCommon{})

0 commit comments

Comments
 (0)