aboutsummaryrefslogtreecommitdiffstats
path: root/storage/transactional/index_test.go
blob: 88fa1f5bf9494e50856e831eb9b884fa48257014 (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
41
42
43
44
45
46
47
48
49
50
51
52
package transactional

import (
	. "gopkg.in/check.v1"
	"github.com/go-git/go-git/v5/plumbing/format/index"
	"github.com/go-git/go-git/v5/storage/memory"
)

var _ = Suite(&IndexSuite{})

type IndexSuite struct{}

func (s *IndexSuite) TestSetIndexBase(c *C) {
	idx := &index.Index{}
	idx.Version = 2

	base := memory.NewStorage()
	err := base.SetIndex(idx)
	c.Assert(err, IsNil)

	temporal := memory.NewStorage()
	cs := NewIndexStorage(base, temporal)

	idx, err = cs.Index()
	c.Assert(err, IsNil)
	c.Assert(idx.Version, Equals, uint32(2))
}

func (s *IndexSuite) TestCommit(c *C) {
	idx := &index.Index{}
	idx.Version = 2

	base := memory.NewStorage()
	err := base.SetIndex(idx)
	c.Assert(err, IsNil)

	temporal := memory.NewStorage()

	idx = &index.Index{}
	idx.Version = 3

	is := NewIndexStorage(base, temporal)
	err = is.SetIndex(idx)
	c.Assert(err, IsNil)

	err = is.Commit()
	c.Assert(err, IsNil)

	baseIndex, err := base.Index()
	c.Assert(err, IsNil)
	c.Assert(baseIndex.Version, Equals, uint32(3))
}