diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-06 19:59:44 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2016-09-06 19:59:44 +0200 |
commit | 98a22e72a808aa0d5dd62339817404fd9e1c4db6 (patch) | |
tree | d5544dce0176b55172f2fd25564618e8c0f18558 /formats/packfile/parser_test.go | |
parent | ae2b10d50da5455b382ab9d543be4fe859afe9e0 (diff) | |
download | go-git-98a22e72a808aa0d5dd62339817404fd9e1c4db6.tar.gz |
format: packfile new interface (wip)
Diffstat (limited to 'formats/packfile/parser_test.go')
-rw-r--r-- | formats/packfile/parser_test.go | 67 |
1 files changed, 64 insertions, 3 deletions
diff --git a/formats/packfile/parser_test.go b/formats/packfile/parser_test.go index f4aff83..a7959a0 100644 --- a/formats/packfile/parser_test.go +++ b/formats/packfile/parser_test.go @@ -2,14 +2,74 @@ package packfile import ( "bytes" - "io" - "io/ioutil" - "os" + "encoding/base64" . "gopkg.in/check.v1" "gopkg.in/src-d/go-git.v4/core" ) +type ScannerSuite struct{} + +var _ = Suite(&ScannerSuite{}) + +func (s *ScannerSuite) TestHeader(c *C) { + data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects) + + p := NewParser(bytes.NewReader(data)) + version, objects, err := p.Header() + c.Assert(err, IsNil) + c.Assert(version, Equals, VersionSupported) + c.Assert(objects, Equals, uint32(11)) +} + +func (s *ScannerSuite) TestNextObjectHeader(c *C) { + data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects) + + p := NewParser(bytes.NewReader(data)) + _, objects, err := p.Header() + c.Assert(err, IsNil) + + for i := 0; i < int(objects); i++ { + h, err := p.NextObjectHeader() + c.Assert(err, IsNil) + c.Assert(*h, DeepEquals, expectedHeaders[i]) + + buf := bytes.NewBuffer(nil) + n, err := p.NextObject(buf) + c.Assert(err, IsNil) + c.Assert(n, Equals, h.Length) + } +} + +func (s *ScannerSuite) TestNextObjectHeaderWithOutReadObject(c *C) { + data, _ := base64.StdEncoding.DecodeString(packFileWithEmptyObjects) + + p := NewParser(bytes.NewReader(data)) + _, objects, err := p.Header() + c.Assert(err, IsNil) + + for i := 0; i < int(objects); i++ { + h, err := p.NextObjectHeader() + c.Assert(err, IsNil) + c.Assert(*h, DeepEquals, expectedHeaders[i]) + } +} + +var expectedHeaders = []ObjectHeader{ + {Type: core.CommitObject, Offset: 12, Length: 239}, + {Type: core.CommitObject, Offset: 177, Length: 244}, + {Type: core.CommitObject, Offset: 345, Length: 239}, + {Type: core.CommitObject, Offset: 507, Length: 191}, + {Type: core.TreeObject, Offset: 639, Length: 91}, + {Type: core.BlobObject, Offset: 714, Length: 0}, + {Type: core.BlobObject, Offset: 723, Length: 14}, + {Type: core.OFSDeltaObject, Offset: 740, Length: 4, OffsetReference: 639}, + {Type: core.TreeObject, Offset: 754, Length: 58}, + {Type: core.BlobObject, Offset: 820, Length: 7}, + {Type: core.TreeObject, Offset: 833, Length: 29}, +} + +/* const ( sigOffset = 0 verOffset = 4 @@ -426,3 +486,4 @@ func (s *ParserSuite) TestReadHeader(c *C) { c.Assert(err, IsNil) c.Assert(count, Equals, uint32(0x50)) } +*/ |