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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
package packp
import (
"bytes"
"github.com/go-git/go-git/v5/plumbing"
. "gopkg.in/check.v1"
)
type ShallowUpdateSuite struct{}
var _ = Suite(&ShallowUpdateSuite{})
func (s *ShallowUpdateSuite) TestDecodeWithLF(c *C) {
raw := "" +
"0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +
"0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +
"0000"
su := &ShallowUpdate{}
err := su.Decode(bytes.NewBufferString(raw))
c.Assert(err, IsNil)
plumbing.HashesSort(su.Shallows)
c.Assert(su.Unshallows, HasLen, 0)
c.Assert(su.Shallows, HasLen, 2)
c.Assert(su.Shallows, DeepEquals, []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
})
}
func (s *ShallowUpdateSuite) TestDecode(c *C) {
raw := "" +
"0034shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"0034shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" +
"0000"
su := &ShallowUpdate{}
err := su.Decode(bytes.NewBufferString(raw))
c.Assert(err, IsNil)
plumbing.HashesSort(su.Shallows)
c.Assert(su.Unshallows, HasLen, 0)
c.Assert(su.Shallows, HasLen, 2)
c.Assert(su.Shallows, DeepEquals, []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
})
}
func (s *ShallowUpdateSuite) TestDecodeUnshallow(c *C) {
raw := "" +
"0036unshallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"0036unshallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" +
"0000"
su := &ShallowUpdate{}
err := su.Decode(bytes.NewBufferString(raw))
c.Assert(err, IsNil)
plumbing.HashesSort(su.Unshallows)
c.Assert(su.Shallows, HasLen, 0)
c.Assert(su.Unshallows, HasLen, 2)
c.Assert(su.Unshallows, DeepEquals, []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
})
}
func (s *ShallowUpdateSuite) TestDecodeMalformed(c *C) {
raw := "" +
"0035unshallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" +
"0000"
su := &ShallowUpdate{}
err := su.Decode(bytes.NewBufferString(raw))
c.Assert(err, NotNil)
}
func (s *ShallowUpdateSuite) TestEncodeEmpty(c *C) {
su := &ShallowUpdate{}
buf := bytes.NewBuffer(nil)
c.Assert(su.Encode(buf), IsNil)
c.Assert(buf.String(), Equals, "0000")
}
func (s *ShallowUpdateSuite) TestEncode(c *C) {
su := &ShallowUpdate{
Shallows: []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
},
Unshallows: []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
},
}
buf := bytes.NewBuffer(nil)
c.Assert(su.Encode(buf), IsNil)
expected := "" +
"0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +
"0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +
"0037unshallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +
"0037unshallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +
"0000"
c.Assert(buf.String(), Equals, expected)
}
func (s *ShallowUpdateSuite) TestEncodeShallow(c *C) {
su := &ShallowUpdate{
Shallows: []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
},
}
buf := bytes.NewBuffer(nil)
c.Assert(su.Encode(buf), IsNil)
expected := "" +
"0035shallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +
"0035shallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +
"0000"
c.Assert(buf.String(), Equals, expected)
}
func (s *ShallowUpdateSuite) TestEncodeUnshallow(c *C) {
su := &ShallowUpdate{
Unshallows: []plumbing.Hash{
plumbing.NewHash("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
plumbing.NewHash("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
},
}
buf := bytes.NewBuffer(nil)
c.Assert(su.Encode(buf), IsNil)
expected := "" +
"0037unshallow aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n" +
"0037unshallow bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n" +
"0000"
c.Assert(buf.String(), Equals, expected)
}
|