aboutsummaryrefslogtreecommitdiffstats
path: root/formats/idxfile/decoder_test.go
blob: 597a0027b2fb098ee68430f3c87cec8e162b5559 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package idxfile

import (
	"fmt"
	"os"
	"testing"

	. "gopkg.in/check.v1"
)

func Test(t *testing.T) { TestingT(t) }

type IdxfileSuite struct{}

var _ = Suite(&IdxfileSuite{})

func (s *IdxfileSuite) TestDecode(c *C) {
	f, err := os.Open("fixtures/git-fixture.idx")
	c.Assert(err, IsNil)

	d := NewDecoder(f)
	idx := &Idxfile{}
	err = d.Decode(idx)
	c.Assert(err, IsNil)

	err = f.Close()
	c.Assert(err, IsNil)

	c.Assert(int(idx.ObjectCount), Equals, 31)
	c.Assert(idx.Entries, HasLen, 31)
	c.Assert(idx.Entries[0].Hash.String(), Equals,
		"1669dce138d9b841a518c64b10914d88f5e488ea")
	c.Assert(idx.Entries[0].Offset, Equals, uint64(615))

	c.Assert(fmt.Sprintf("%x", idx.IdxChecksum), Equals,
		"bba9b7a9895724819225a044c857d391bb9d61d9")
	c.Assert(fmt.Sprintf("%x", idx.PackfileChecksum), Equals,
		"54bb61360ab2dad1a3e344a8cd3f82b848518cba")

}