Debian Codegraph @

plumbing/format/idxfile/encoder_test.go

raw
1 package idxfile_test
2
3 import (
4 "bytes"
5 "io"
6
7 . "github.com/go-git/go-git/v5/plumbing/format/idxfile"
8
9 fixtures "github.com/go-git/go-git-fixtures/v4"
10 . "gopkg.in/check.v1"
11 )
12
13 func (s *IdxfileSuite) TestDecodeEncode(c *C) {
14 fixtures.ByTag("packfile").Test(c, func(f *fixtures.Fixture) {
15 expected, err := io.ReadAll(f.Idx())
16 c.Assert(err, IsNil)
17
18 idx := new(MemoryIndex)
19 d := NewDecoder(bytes.NewBuffer(expected))
20 err = d.Decode(idx)
21 c.Assert(err, IsNil)
22
23 result := bytes.NewBuffer(nil)
24 e := NewEncoder(result)
25 size, err := e.Encode(idx)
26 c.Assert(err, IsNil)
27
28 c.Assert(size, Equals, len(expected))
29 c.Assert(result.Bytes(), DeepEquals, expected)
30 })
31 }