aboutsummaryrefslogtreecommitdiffstats
path: root/storage/transactional/shallow_test.go
blob: 15d423c000fadba774f1d1d7d95765b3e7f93722 (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
53
54
55
56
57
58
59
60
61
62
63
package transactional

import (
	"github.com/go-git/go-git/v5/plumbing"
	"github.com/go-git/go-git/v5/storage/memory"

	. "gopkg.in/check.v1"
)

var _ = Suite(&ShallowSuite{})

type ShallowSuite struct{}

func (s *ShallowSuite) TestShallow(c *C) {
	base := memory.NewStorage()
	temporal := memory.NewStorage()

	rs := NewShallowStorage(base, temporal)

	commitA := plumbing.NewHash("bc9968d75e48de59f0870ffb71f5e160bbbdcf52")
	commitB := plumbing.NewHash("aa9968d75e48de59f0870ffb71f5e160bbbdcf52")

	err := base.SetShallow([]plumbing.Hash{commitA})
	c.Assert(err, IsNil)

	err = rs.SetShallow([]plumbing.Hash{commitB})
	c.Assert(err, IsNil)

	commits, err := rs.Shallow()
	c.Assert(err, IsNil)
	c.Assert(commits, HasLen, 1)
	c.Assert(commits[0], Equals, commitB)

	commits, err = base.Shallow()
	c.Assert(err, IsNil)
	c.Assert(commits, HasLen, 1)
	c.Assert(commits[0], Equals, commitA)
}

func (s *ShallowSuite) TestCommit(c *C) {
	base := memory.NewStorage()
	temporal := memory.NewStorage()

	rs := NewShallowStorage(base, temporal)

	commitA := plumbing.NewHash("bc9968d75e48de59f0870ffb71f5e160bbbdcf52")
	commitB := plumbing.NewHash("aa9968d75e48de59f0870ffb71f5e160bbbdcf52")

	c.Assert(base.SetShallow([]plumbing.Hash{commitA}), IsNil)
	c.Assert(rs.SetShallow([]plumbing.Hash{commitB}), IsNil)

	c.Assert(rs.Commit(), IsNil)

	commits, err := rs.Shallow()
	c.Assert(err, IsNil)
	c.Assert(commits, HasLen, 1)
	c.Assert(commits[0], Equals, commitB)

	commits, err = base.Shallow()
	c.Assert(err, IsNil)
	c.Assert(commits, HasLen, 1)
	c.Assert(commits[0], Equals, commitB)
}