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
52 PullServers{To: []string{}, From: []string{}})
56 stringSet("keep0:25107", "keep1:25108"),
60 PullServers{To: []string{}, From: []string{}})
64 stringSet("keep0:25107", "keep1:25108"),
65 []string{"keep0:25107"},
68 PullServers{To: []string{}, From: []string{"keep0:25107"}})
72 stringSet("keep0:25107", "keep1:25108"),
73 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
76 PullServers{To: []string{"keep3:25110", "keep2:25109"},
77 From: []string{"keep1:25108", "keep0:25107"}})
81 stringSet("keep0:25107", "keep1:25108"),
82 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
85 PullServers{To: []string{"keep3:25110"},
86 From: []string{"keep1:25108", "keep0:25107"}})
90 stringSet("keep0:25107", "keep1:25108"),
91 []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"},
94 PullServers{To: []string{},
95 From: []string{"keep1:25108", "keep0:25107"}})
98 // Checks whether two pull list maps are equal. Since pull lists are
99 // ordered arbitrarily, we need to sort them by digest before
100 // comparing them for deep equality.
101 type pullListMapEqualsChecker struct {
105 func (c *pullListMapEqualsChecker) Check(params []interface{}, names []string) (result bool, error string) {
106 obtained, ok := params[0].(map[string]PullList)
108 return false, "First parameter is not a PullList map"
110 expected, ok := params[1].(map[string]PullList)
112 return false, "Second parameter is not a PullList map"
115 for _, v := range obtained {
116 sort.Sort(PullListByDigest(v))
118 for _, v := range expected {
119 sort.Sort(PullListByDigest(v))
122 return DeepEquals.Check(params, names)
125 var PullListMapEquals Checker = &pullListMapEqualsChecker{&CheckerInfo{
126 Name: "PullListMapEquals",
127 Params: []string{"obtained", "expected"},
130 func (s *MySuite) TestBuildPullLists(c *C) {
132 BuildPullLists(map[Locator]PullServers{}),
134 map[string]PullList{})
136 locator1 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)}
138 BuildPullLists(map[Locator]PullServers{
139 locator1: PullServers{To: []string{}, From: []string{}}}),
141 map[string]PullList{})
144 BuildPullLists(map[Locator]PullServers{
145 locator1: PullServers{To: []string{}, From: []string{"f1", "f2"}}}),
147 map[string]PullList{})
150 BuildPullLists(map[Locator]PullServers{
151 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}}}),
154 "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}})
157 BuildPullLists(map[Locator]PullServers{
158 locator1: PullServers{To: []string{"t1"}, From: []string{}}}),
160 map[string]PullList{"t1": PullList{
161 PullRequest{locator1, []string{}}}})
164 BuildPullLists(map[Locator]PullServers{
165 locator1: PullServers{
166 To: []string{"t1", "t2"},
167 From: []string{"f1", "f2"},
171 "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}},
172 "t2": PullList{PullRequest{locator1, []string{"f1", "f2"}}},
175 locator2 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xCabbed)}
177 BuildPullLists(map[Locator]PullServers{
178 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}},
179 locator2: PullServers{To: []string{"t2"}, From: []string{"f3", "f4"}}}),
182 "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}},
183 "t2": PullList{PullRequest{locator2, []string{"f3", "f4"}}},
187 BuildPullLists(map[Locator]PullServers{
188 locator1: PullServers{
190 From: []string{"f1", "f2"}},
191 locator2: PullServers{
192 To: []string{"t2", "t1"},
193 From: []string{"f3", "f4"}},
198 PullRequest{locator1, []string{"f1", "f2"}},
199 PullRequest{locator2, []string{"f3", "f4"}},
202 PullRequest{locator2, []string{"f3", "f4"}},
206 locator3 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xDeadBeef)}
207 locator4 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xFedBeef)}
209 BuildPullLists(map[Locator]PullServers{
210 locator1: PullServers{
212 From: []string{"f1", "f2"}},
213 locator2: PullServers{
214 To: []string{"t2", "t1"},
215 From: []string{"f3", "f4"}},
216 locator3: PullServers{
217 To: []string{"t3", "t2", "t1"},
218 From: []string{"f4", "f5"}},
219 locator4: PullServers{
220 To: []string{"t4", "t3", "t2", "t1"},
221 From: []string{"f1", "f5"}},
226 PullRequest{locator1, []string{"f1", "f2"}},
227 PullRequest{locator2, []string{"f3", "f4"}},
228 PullRequest{locator3, []string{"f4", "f5"}},
229 PullRequest{locator4, []string{"f1", "f5"}},
232 PullRequest{locator2, []string{"f3", "f4"}},
233 PullRequest{locator3, []string{"f4", "f5"}},
234 PullRequest{locator4, []string{"f1", "f5"}},
237 PullRequest{locator3, []string{"f4", "f5"}},
238 PullRequest{locator4, []string{"f1", "f5"}},
241 PullRequest{locator4, []string{"f1", "f5"}},
246 func (s *MySuite) TestRemoveProtocolPrefix(c *C) {
247 c.Check(RemoveProtocolPrefix("blah"), Equals, "blah")
248 c.Check(RemoveProtocolPrefix("bl/ah"), Equals, "ah")
249 c.Check(RemoveProtocolPrefix("http://blah.com"), Equals, "blah.com")
250 c.Check(RemoveProtocolPrefix("https://blah.com:8900"), Equals, "blah.com:8900")