5 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
11 // Gocheck boilerplate
12 func Test(t *testing.T) {
18 var _ = Suite(&MySuite{})
20 // Helper method to declare string sets more succinctly
21 // Could be placed somewhere more general.
22 func stringSet(slice ...string) (m map[string]struct{}) {
23 m = map[string]struct{}{}
24 for _, s := range slice {
30 func (s *MySuite) TestPullListPrintsJSONCorrectly(c *C) {
31 pl := PullList{PullRequest{
32 Locator: Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)},
33 Servers: []string{"keep0.qr1hi.arvadosapi.com:25107",
34 "keep1.qr1hi.arvadosapi.com:25108"}}}
36 b, err := json.Marshal(pl)
38 expectedOutput := `[{"locator":"0000000000000000000000000badbeef",` +
39 `"servers":["keep0.qr1hi.arvadosapi.com:25107",` +
40 `"keep1.qr1hi.arvadosapi.com:25108"]}]`
41 c.Check(string(b), Equals, expectedOutput)
44 func (s *MySuite) TestCreatePullServers(c *C) {
45 var cs CanonicalString
53 PullServers{To: []string{}, From: []string{}})
57 stringSet("keep0:25107", "keep1:25108"),
62 PullServers{To: []string{}, From: []string{}})
66 stringSet("keep0:25107", "keep1:25108"),
67 stringSet("keep0:25107"),
68 []string{"keep0:25107"},
71 PullServers{To: []string{}, From: []string{"keep0:25107"}})
75 stringSet("keep0:25107", "keep1:25108"),
76 stringSet("keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"),
77 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
80 PullServers{To: []string{"keep3:25110", "keep2:25109"},
81 From: []string{"keep1:25108", "keep0:25107"}})
85 stringSet("keep0:25107", "keep1:25108"),
86 stringSet("keep3:25110", "keep1:25108", "keep0:25107"),
87 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
90 PullServers{To: []string{"keep3:25110"},
91 From: []string{"keep1:25108", "keep0:25107"}})
95 stringSet("keep0:25107", "keep1:25108"),
96 stringSet("keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"),
97 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
100 PullServers{To: []string{"keep3:25110"},
101 From: []string{"keep1:25108", "keep0:25107"}})
104 CreatePullServers(cs,
105 stringSet("keep0:25107", "keep1:25108"),
106 stringSet("keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"),
107 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
110 PullServers{To: []string{},
111 From: []string{"keep1:25108", "keep0:25107"}})
114 // Checks whether two pull list maps are equal. Since pull lists are
115 // ordered arbitrarily, we need to sort them by digest before
116 // comparing them for deep equality.
117 type pullListMapEqualsChecker struct {
121 func (c *pullListMapEqualsChecker) Check(params []interface{}, names []string) (result bool, error string) {
122 obtained, ok := params[0].(map[string]PullList)
124 return false, "First parameter is not a PullList map"
126 expected, ok := params[1].(map[string]PullList)
128 return false, "Second parameter is not a PullList map"
131 for _, v := range obtained {
132 sort.Sort(PullListByDigest(v))
134 for _, v := range expected {
135 sort.Sort(PullListByDigest(v))
138 return DeepEquals.Check(params, names)
141 var PullListMapEquals Checker = &pullListMapEqualsChecker{&CheckerInfo{
142 Name: "PullListMapEquals",
143 Params: []string{"obtained", "expected"},
146 func (s *MySuite) TestBuildPullLists(c *C) {
148 BuildPullLists(map[Locator]PullServers{}),
150 map[string]PullList{})
152 locator1 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)}
154 BuildPullLists(map[Locator]PullServers{
155 locator1: PullServers{To: []string{}, From: []string{}}}),
157 map[string]PullList{})
160 BuildPullLists(map[Locator]PullServers{
161 locator1: PullServers{To: []string{}, From: []string{"f1", "f2"}}}),
163 map[string]PullList{})
166 BuildPullLists(map[Locator]PullServers{
167 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}}}),
170 "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}})
173 BuildPullLists(map[Locator]PullServers{
174 locator1: PullServers{To: []string{"t1"}, From: []string{}}}),
176 map[string]PullList{"t1": PullList{
177 PullRequest{locator1, []string{}}}})
180 BuildPullLists(map[Locator]PullServers{
181 locator1: PullServers{
182 To: []string{"t1", "t2"},
183 From: []string{"f1", "f2"},
187 "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}},
188 "t2": PullList{PullRequest{locator1, []string{"f1", "f2"}}},
191 locator2 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xCabbed)}
193 BuildPullLists(map[Locator]PullServers{
194 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}},
195 locator2: PullServers{To: []string{"t2"}, From: []string{"f3", "f4"}}}),
198 "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}},
199 "t2": PullList{PullRequest{locator2, []string{"f3", "f4"}}},
203 BuildPullLists(map[Locator]PullServers{
204 locator1: PullServers{
206 From: []string{"f1", "f2"}},
207 locator2: PullServers{
208 To: []string{"t2", "t1"},
209 From: []string{"f3", "f4"}},
214 PullRequest{locator1, []string{"f1", "f2"}},
215 PullRequest{locator2, []string{"f3", "f4"}},
218 PullRequest{locator2, []string{"f3", "f4"}},
222 locator3 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xDeadBeef)}
223 locator4 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xFedBeef)}
225 BuildPullLists(map[Locator]PullServers{
226 locator1: PullServers{
228 From: []string{"f1", "f2"}},
229 locator2: PullServers{
230 To: []string{"t2", "t1"},
231 From: []string{"f3", "f4"}},
232 locator3: PullServers{
233 To: []string{"t3", "t2", "t1"},
234 From: []string{"f4", "f5"}},
235 locator4: PullServers{
236 To: []string{"t4", "t3", "t2", "t1"},
237 From: []string{"f1", "f5"}},
242 PullRequest{locator1, []string{"f1", "f2"}},
243 PullRequest{locator2, []string{"f3", "f4"}},
244 PullRequest{locator3, []string{"f4", "f5"}},
245 PullRequest{locator4, []string{"f1", "f5"}},
248 PullRequest{locator2, []string{"f3", "f4"}},
249 PullRequest{locator3, []string{"f4", "f5"}},
250 PullRequest{locator4, []string{"f1", "f5"}},
253 PullRequest{locator3, []string{"f4", "f5"}},
254 PullRequest{locator4, []string{"f1", "f5"}},
257 PullRequest{locator4, []string{"f1", "f5"}},
262 func (s *MySuite) TestRemoveProtocolPrefix(c *C) {
263 c.Check(RemoveProtocolPrefix("blah"), Equals, "blah")
264 c.Check(RemoveProtocolPrefix("bl/ah"), Equals, "ah")
265 c.Check(RemoveProtocolPrefix("http://blah.com"), Equals, "blah.com")
266 c.Check(RemoveProtocolPrefix("https://blah.com:8900"), Equals, "blah.com:8900")