diff options
author | Antonio Navarro Perez <antnavper@gmail.com> | 2017-01-12 08:46:32 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-12 08:46:32 +0100 |
commit | f9c7c8c2158140d75d4d5a2fa925fc35ad77be9b (patch) | |
tree | f0878e352cfa3f48cea2981b0202dbb494baada4 /plumbing/format/packfile/decoder_test.go | |
parent | 65d23b4620a76418dc4aeca83ce7a991a1945ef0 (diff) | |
download | go-git-f9c7c8c2158140d75d4d5a2fa925fc35ad77be9b.tar.gz |
packfile/decoder: speed up packfile iterator when specific type (#200)
Diffstat (limited to 'plumbing/format/packfile/decoder_test.go')
-rw-r--r-- | plumbing/format/packfile/decoder_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/plumbing/format/packfile/decoder_test.go b/plumbing/format/packfile/decoder_test.go index 10d3bc2..0ab5bc8 100644 --- a/plumbing/format/packfile/decoder_test.go +++ b/plumbing/format/packfile/decoder_test.go @@ -47,6 +47,52 @@ func (s *ReaderSuite) TestDecode(c *C) { }) } +func (s *ReaderSuite) TestDecodeByType(c *C) { + ts := []plumbing.ObjectType{ + plumbing.CommitObject, + plumbing.TagObject, + plumbing.TreeObject, + plumbing.BlobObject, + } + + fixtures.Basic().ByTag("packfile").Test(c, func(f *fixtures.Fixture) { + for _, t := range ts { + storage := memory.NewStorage() + scanner := packfile.NewScanner(f.Packfile()) + d, err := packfile.NewDecoderForType(scanner, storage, t) + c.Assert(err, IsNil) + defer d.Close() + + _, count, err := scanner.Header() + c.Assert(err, IsNil) + + var i uint32 + for i = 0; i < count; i++ { + obj, err := d.DecodeObject() + c.Assert(err, IsNil) + + if obj != nil { + c.Assert(obj.Type(), Equals, t) + } + } + } + }) +} +func (s *ReaderSuite) TestDecodeByTypeConstructor(c *C) { + f := fixtures.Basic().ByTag("packfile").One() + storage := memory.NewStorage() + scanner := packfile.NewScanner(f.Packfile()) + + _, err := packfile.NewDecoderForType(scanner, storage, plumbing.OFSDeltaObject) + c.Assert(err, Equals, plumbing.ErrInvalidType) + + _, err = packfile.NewDecoderForType(scanner, storage, plumbing.REFDeltaObject) + c.Assert(err, Equals, plumbing.ErrInvalidType) + + _, err = packfile.NewDecoderForType(scanner, storage, plumbing.InvalidObject) + c.Assert(err, Equals, plumbing.ErrInvalidType) +} + func (s *ReaderSuite) TestDecodeMultipleTimes(c *C) { f := fixtures.Basic().ByTag("packfile").One() scanner := packfile.NewScanner(f.Packfile()) |