diff options
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()) |