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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
package capability
import (
"testing"
check "gopkg.in/check.v1"
)
func Test(t *testing.T) { check.TestingT(t) }
type SuiteCapabilities struct{}
var _ = check.Suite(&SuiteCapabilities{})
func (s *SuiteCapabilities) TestIsEmpty(c *check.C) {
cap := NewList()
c.Assert(cap.IsEmpty(), check.Equals, true)
}
func (s *SuiteCapabilities) TestDecode(c *check.C) {
cap := NewList()
err := cap.Decode([]byte("symref=foo symref=qux thin-pack"))
c.Assert(err, check.IsNil)
c.Assert(cap.m, check.HasLen, 2)
c.Assert(cap.Get(SymRef), check.DeepEquals, []string{"foo", "qux"})
c.Assert(cap.Get(ThinPack), check.IsNil)
}
func (s *SuiteCapabilities) TestDecodeWithLeadingSpace(c *check.C) {
cap := NewList()
err := cap.Decode([]byte(" report-status"))
c.Assert(err, check.IsNil)
c.Assert(cap.m, check.HasLen, 1)
c.Assert(cap.Supports(ReportStatus), check.Equals, true)
}
func (s *SuiteCapabilities) TestDecodeEmpty(c *check.C) {
cap := NewList()
err := cap.Decode(nil)
c.Assert(err, check.IsNil)
c.Assert(cap, check.DeepEquals, NewList())
}
func (s *SuiteCapabilities) TestDecodeWithErrArguments(c *check.C) {
cap := NewList()
err := cap.Decode([]byte("thin-pack=foo"))
c.Assert(err, check.Equals, ErrArguments)
}
func (s *SuiteCapabilities) TestDecodeWithEqual(c *check.C) {
cap := NewList()
err := cap.Decode([]byte("agent=foo=bar"))
c.Assert(err, check.IsNil)
c.Assert(cap.m, check.HasLen, 1)
c.Assert(cap.Get(Agent), check.DeepEquals, []string{"foo=bar"})
}
func (s *SuiteCapabilities) TestDecodeWithErrUnknownCapability(c *check.C) {
cap := NewList()
err := cap.Decode([]byte("foo"))
c.Assert(err, check.Equals, ErrUnknownCapability)
}
func (s *SuiteCapabilities) TestString(c *check.C) {
cap := NewList()
cap.Set(Agent, "bar")
cap.Set(SymRef, "foo:qux")
cap.Set(ThinPack)
c.Assert(cap.String(), check.Equals, "agent=bar symref=foo:qux thin-pack")
}
func (s *SuiteCapabilities) TestStringSort(c *check.C) {
cap := NewList()
cap.Set(Agent, "bar")
cap.Set(SymRef, "foo:qux")
cap.Set(ThinPack)
c.Assert(cap.String(), check.Equals, "agent=bar symref=foo:qux thin-pack")
}
func (s *SuiteCapabilities) TestSet(c *check.C) {
cap := NewList()
err := cap.Add(SymRef, "foo", "qux")
c.Assert(err, check.IsNil)
err = cap.Set(SymRef, "bar")
c.Assert(err, check.IsNil)
c.Assert(cap.m, check.HasLen, 1)
c.Assert(cap.Get(SymRef), check.DeepEquals, []string{"bar"})
}
func (s *SuiteCapabilities) TestSetEmpty(c *check.C) {
cap := NewList()
err := cap.Set(Agent, "bar")
c.Assert(err, check.IsNil)
c.Assert(cap.Get(Agent), check.HasLen, 1)
}
func (s *SuiteCapabilities) TestGetEmpty(c *check.C) {
cap := NewList()
c.Assert(cap.Get(Agent), check.HasLen, 0)
}
func (s *SuiteCapabilities) TestDelete(c *check.C) {
cap := NewList()
cap.Delete(SymRef)
err := cap.Add(Sideband)
c.Assert(err, check.IsNil)
err = cap.Set(SymRef, "bar")
c.Assert(err, check.IsNil)
err = cap.Set(Sideband64k)
c.Assert(err, check.IsNil)
cap.Delete(SymRef)
c.Assert(cap.String(), check.Equals, "side-band side-band-64k")
}
func (s *SuiteCapabilities) TestAdd(c *check.C) {
cap := NewList()
err := cap.Add(SymRef, "foo", "qux")
c.Assert(err, check.IsNil)
err = cap.Add(ThinPack)
c.Assert(err, check.IsNil)
c.Assert(cap.String(), check.Equals, "symref=foo symref=qux thin-pack")
}
func (s *SuiteCapabilities) TestAddErrUnknownCapability(c *check.C) {
cap := NewList()
err := cap.Add(Capability("foo"))
c.Assert(err, check.Equals, ErrUnknownCapability)
}
func (s *SuiteCapabilities) TestAddErrArgumentsRequired(c *check.C) {
cap := NewList()
err := cap.Add(SymRef)
c.Assert(err, check.Equals, ErrArgumentsRequired)
}
func (s *SuiteCapabilities) TestAddErrArgumentsNotAllowed(c *check.C) {
cap := NewList()
err := cap.Add(OFSDelta, "foo")
c.Assert(err, check.Equals, ErrArguments)
}
func (s *SuiteCapabilities) TestAddErrArgumendts(c *check.C) {
cap := NewList()
err := cap.Add(SymRef, "")
c.Assert(err, check.Equals, ErrEmtpyArgument)
}
func (s *SuiteCapabilities) TestAddErrMultipleArguments(c *check.C) {
cap := NewList()
err := cap.Add(Agent, "foo")
c.Assert(err, check.IsNil)
err = cap.Add(Agent, "bar")
c.Assert(err, check.Equals, ErrMultipleArguments)
}
func (s *SuiteCapabilities) TestAddErrMultipleArgumentsAtTheSameTime(c *check.C) {
cap := NewList()
err := cap.Add(Agent, "foo", "bar")
c.Assert(err, check.Equals, ErrMultipleArguments)
}
func (s *SuiteCapabilities) TestAll(c *check.C) {
cap := NewList()
c.Assert(NewList().All(), check.IsNil)
cap.Add(Agent, "foo")
c.Assert(cap.All(), check.DeepEquals, []Capability{Agent})
cap.Add(OFSDelta)
c.Assert(cap.All(), check.DeepEquals, []Capability{Agent, OFSDelta})
}
|