Debian Codegraph @

storage/transactional/shallow_test.go

raw
1 package transactional
2
3 import (
4 "github.com/go-git/go-git/v5/plumbing"
5 "github.com/go-git/go-git/v5/storage/memory"
6
7 . "gopkg.in/check.v1"
8 )
9
10 var _ = Suite(&ShallowSuite{})
11
12 type ShallowSuite struct{}
13
14 func (s *ShallowSuite) TestShallow(c *C) {
15 base := memory.NewStorage()
16 temporal := memory.NewStorage()
17
18 rs := NewShallowStorage(base, temporal)
19
20 commitA := plumbing.NewHash("bc9968d75e48de59f0870ffb71f5e160bbbdcf52")
21 commitB := plumbing.NewHash("aa9968d75e48de59f0870ffb71f5e160bbbdcf52")
22
23 err := base.SetShallow([]plumbing.Hash{commitA})
24 c.Assert(err, IsNil)
25
26 err = rs.SetShallow([]plumbing.Hash{commitB})
27 c.Assert(err, IsNil)
28
29 commits, err := rs.Shallow()
30 c.Assert(err, IsNil)
31 c.Assert(commits, HasLen, 1)
32 c.Assert(commits[0], Equals, commitB)
33
34 commits, err = base.Shallow()
35 c.Assert(err, IsNil)
36 c.Assert(commits, HasLen, 1)
37 c.Assert(commits[0], Equals, commitA)
38 }
39
40 func (s *ShallowSuite) TestCommit(c *C) {
41 base := memory.NewStorage()
42 temporal := memory.NewStorage()
43
44 rs := NewShallowStorage(base, temporal)
45
46 commitA := plumbing.NewHash("bc9968d75e48de59f0870ffb71f5e160bbbdcf52")
47 commitB := plumbing.NewHash("aa9968d75e48de59f0870ffb71f5e160bbbdcf52")
48
49 c.Assert(base.SetShallow([]plumbing.Hash{commitA}), IsNil)
50 c.Assert(rs.SetShallow([]plumbing.Hash{commitB}), IsNil)
51
52 c.Assert(rs.Commit(), IsNil)
53
54 commits, err := rs.Shallow()
55 c.Assert(err, IsNil)
56 c.Assert(commits, HasLen, 1)
57 c.Assert(commits[0], Equals, commitB)
58
59 commits, err = base.Shallow()
60 c.Assert(err, IsNil)
61 c.Assert(commits, HasLen, 1)
62 c.Assert(commits[0], Equals, commitB)
63 }