|
7 | 7 |
|
8 | 8 | "gopkg.in/src-d/go-git.v3/clients/common" |
9 | 9 | "gopkg.in/src-d/go-git.v3/core" |
| 10 | + "gopkg.in/src-d/go-git.v3/formats/packfile" |
10 | 11 |
|
11 | 12 | . "gopkg.in/check.v1" |
12 | 13 | ) |
@@ -46,15 +47,41 @@ func (s *MockGitUploadPackService) Fetch(*common.GitUploadPackRequest) (io.ReadC |
46 | 47 | return s.RC, err |
47 | 48 | } |
48 | 49 |
|
49 | | -var fixtureRepos = [...]struct { |
| 50 | +type packedFixture struct { |
50 | 51 | url string |
51 | 52 | packfile string |
52 | | -}{ |
| 53 | +} |
| 54 | + |
| 55 | +var fixtureRepos = []packedFixture{ |
53 | 56 | {"https://github.com/tyba/git-fixture.git", "formats/packfile/fixtures/git-fixture.ofs-delta"}, |
54 | 57 | {"https://github.com/jamesob/desk.git", "formats/packfile/fixtures/jamesob-desk.pack"}, |
55 | 58 | {"https://github.com/spinnaker/spinnaker.git", "formats/packfile/fixtures/spinnaker-spinnaker.pack"}, |
56 | 59 | } |
57 | 60 |
|
| 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 | + |
58 | 85 | type SuiteCommon struct{} |
59 | 86 |
|
60 | 87 | var _ = Suite(&SuiteCommon{}) |
|
0 commit comments