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

Commit 38ebf56

Browse files
committed
plumbing/format/packfile: Added thin pack test
Signed-off-by: Javier Peletier <[email protected]>
1 parent 66d82a5 commit 38ebf56

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

plumbing/format/packfile/parser_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package packfile_test
22

33
import (
4+
"io"
45
"testing"
56

7+
git "gopkg.in/src-d/go-git.v4"
68
"gopkg.in/src-d/go-git.v4/plumbing"
79
"gopkg.in/src-d/go-git.v4/plumbing/format/packfile"
10+
"gopkg.in/src-d/go-git.v4/plumbing/storer"
811

912
. "gopkg.in/check.v1"
1013
"gopkg.in/src-d/go-git-fixtures.v3"
@@ -74,6 +77,53 @@ func (s *ParserSuite) TestParserHashes(c *C) {
7477
c.Assert(obs.objects, DeepEquals, objs)
7578
}
7679

80+
func (s *ParserSuite) TestThinPack(c *C) {
81+
82+
// Initialize an empty repository
83+
fs, err := git.PlainInit(c.MkDir(), true)
84+
c.Assert(err, IsNil)
85+
86+
// Try to parse a thin pack without having the required objects in the repo to
87+
// see if the correct errors are returned
88+
thinpack := fixtures.ByTag("thinpack").One()
89+
scanner := packfile.NewScanner(thinpack.Packfile())
90+
parser, err := packfile.NewParserWithStorage(scanner, fs.Storer) // ParserWithStorage writes to the storer all parsed objects!
91+
c.Assert(err, IsNil)
92+
93+
_, err = parser.Parse()
94+
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
95+
96+
// start over with a clean repo
97+
fs, err = git.PlainInit(c.MkDir(), true)
98+
c.Assert(err, IsNil)
99+
100+
// Now unpack a base packfile into our empty repo:
101+
f := fixtures.ByURL("https://github.com/spinnaker/spinnaker.git").One()
102+
w, err := fs.Storer.(storer.PackfileWriter).PackfileWriter()
103+
c.Assert(err, IsNil)
104+
_, err = io.Copy(w, f.Packfile())
105+
c.Assert(err, IsNil)
106+
w.Close()
107+
108+
// Check that the test object that will come with our thin pack is *not* in the repo
109+
_, err = fs.Storer.EncodedObject(plumbing.CommitObject, thinpack.Head)
110+
c.Assert(err, Equals, plumbing.ErrObjectNotFound)
111+
112+
// Now unpack the thin pack:
113+
scanner = packfile.NewScanner(thinpack.Packfile())
114+
parser, err = packfile.NewParserWithStorage(scanner, fs.Storer) // ParserWithStorage writes to the storer all parsed objects!
115+
c.Assert(err, IsNil)
116+
117+
h, err := parser.Parse()
118+
c.Assert(err, IsNil)
119+
c.Assert(h, Equals, plumbing.NewHash("1288734cbe0b95892e663221d94b95de1f5d7be8"))
120+
121+
// Check that our test object is now accessible
122+
_, err = fs.Storer.EncodedObject(plumbing.CommitObject, thinpack.Head)
123+
c.Assert(err, IsNil)
124+
125+
}
126+
77127
type observerObject struct {
78128
hash string
79129
otype plumbing.ObjectType

0 commit comments

Comments
 (0)