5 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
11 // Gocheck boilerplate
12 func TestPullLists(t *testing.T) {
16 type PullSuite struct{}
18 var _ = Suite(&PullSuite{})
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 *PullSuite) TestPullListPrintsJSONCorrectly(c *C) {
31 pl := PullList{PullRequest{
32 Locator: Locator(blockdigest.MakeTestDigestSpecifySize(0xBadBeef, 56789)),
33 Servers: []string{"keep0.qr1hi.arvadosapi.com:25107",
34 "keep1.qr1hi.arvadosapi.com:25108"}}}
36 b, err := json.Marshal(pl)
38 expectedOutput := `[{"locator":"0000000000000000000000000badbeef+56789",` +
39 `"servers":["keep0.qr1hi.arvadosapi.com:25107",` +
40 `"keep1.qr1hi.arvadosapi.com:25108"]}]`
41 c.Check(string(b), Equals, expectedOutput)
44 func (s *PullSuite) TestCreatePullServers(c *C) {
45 var cs CanonicalString
53 PullServers{To: []string{}, From: []string{}})
57 stringSet("https://keep0:25107", "https://keep1:25108"),
62 PullServers{To: []string{}, From: []string{}})
66 stringSet("https://keep0:25107", "https://keep1:25108"),
67 stringSet("https://keep0:25107"),
68 []string{"https://keep0:25107"},
71 PullServers{To: []string{}, From: []string{"https://keep0:25107"}})
75 stringSet("https://keep0:25107", "https://keep1:25108"),
76 stringSet("https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"),
77 []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"},
80 PullServers{To: []string{"https://keep3:25110", "https://keep2:25109"},
81 From: []string{"https://keep1:25108", "https://keep0:25107"}})
85 stringSet("https://keep0:25107", "https://keep1:25108"),
86 stringSet("https://keep3:25110", "https://keep1:25108", "https://keep0:25107"),
87 []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"},
90 PullServers{To: []string{"https://keep3:25110"},
91 From: []string{"https://keep1:25108", "https://keep0:25107"}})
95 stringSet("https://keep0:25107", "https://keep1:25108"),
96 stringSet("https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"),
97 []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"},
100 PullServers{To: []string{"https://keep3:25110"},
101 From: []string{"https://keep1:25108", "https://keep0:25107"}})
104 CreatePullServers(cs,
105 stringSet("https://keep0:25107", "https://keep1:25108"),
106 stringSet("https://keep3:25110", "https://keep2:25109",
107 "https://keep1:25108", "https://keep0:25107"),
108 []string{"https://keep3:25110", "https://keep2:25109",
109 "https://keep1:25108", "https://keep0:25107"},
112 PullServers{To: []string{"https://keep3:25110"},
113 From: []string{"https://keep1:25108", "https://keep0:25107"}})
116 CreatePullServers(cs,
117 stringSet("https://keep0:25107", "https://keep1:25108"),
118 stringSet("https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"),
119 []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"},
122 PullServers{To: []string{},
123 From: []string{"https://keep1:25108", "https://keep0:25107"}})
126 // Checks whether two pull list maps are equal. Since pull lists are
127 // ordered arbitrarily, we need to sort them by digest before
128 // comparing them for deep equality.
129 type pullListMapEqualsChecker struct {
133 func (c *pullListMapEqualsChecker) Check(params []interface{}, names []string) (result bool, error string) {
134 obtained, ok := params[0].(map[string]PullList)
136 return false, "First parameter is not a PullList map"
138 expected, ok := params[1].(map[string]PullList)
140 return false, "Second parameter is not a PullList map"
143 for _, v := range obtained {
144 sort.Sort(PullListByLocator(v))
146 for _, v := range expected {
147 sort.Sort(PullListByLocator(v))
150 return DeepEquals.Check(params, names)
153 var PullListMapEquals Checker = &pullListMapEqualsChecker{&CheckerInfo{
154 Name: "PullListMapEquals",
155 Params: []string{"obtained", "expected"},
158 func (s *PullSuite) TestBuildPullLists(c *C) {
160 BuildPullLists(map[Locator]PullServers{}),
162 map[string]PullList{})
164 locator1 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)}
166 BuildPullLists(map[Locator]PullServers{
167 locator1: {To: []string{}, From: []string{}}}),
169 map[string]PullList{})
172 BuildPullLists(map[Locator]PullServers{
173 locator1: {To: []string{}, From: []string{"f1", "f2"}}}),
175 map[string]PullList{})
178 BuildPullLists(map[Locator]PullServers{
179 locator1: {To: []string{"t1"}, From: []string{"f1", "f2"}}}),
182 "t1": {PullRequest{locator1, []string{"f1", "f2"}}}})
185 BuildPullLists(map[Locator]PullServers{
186 locator1: {To: []string{"t1"}, From: []string{}}}),
188 map[string]PullList{"t1": {
189 PullRequest{locator1, []string{}}}})
192 BuildPullLists(map[Locator]PullServers{
194 To: []string{"t1", "t2"},
195 From: []string{"f1", "f2"},
199 "t1": {PullRequest{locator1, []string{"f1", "f2"}}},
200 "t2": {PullRequest{locator1, []string{"f1", "f2"}}},
203 locator2 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xCabbed)}
205 BuildPullLists(map[Locator]PullServers{
206 locator1: {To: []string{"t1"}, From: []string{"f1", "f2"}},
207 locator2: {To: []string{"t2"}, From: []string{"f3", "f4"}}}),
210 "t1": {PullRequest{locator1, []string{"f1", "f2"}}},
211 "t2": {PullRequest{locator2, []string{"f3", "f4"}}},
215 BuildPullLists(map[Locator]PullServers{
218 From: []string{"f1", "f2"}},
220 To: []string{"t2", "t1"},
221 From: []string{"f3", "f4"}},
226 PullRequest{locator1, []string{"f1", "f2"}},
227 PullRequest{locator2, []string{"f3", "f4"}},
230 PullRequest{locator2, []string{"f3", "f4"}},
234 locator3 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xDeadBeef)}
235 locator4 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xFedBeef)}
237 BuildPullLists(map[Locator]PullServers{
240 From: []string{"f1", "f2"}},
242 To: []string{"t2", "t1"},
243 From: []string{"f3", "f4"}},
245 To: []string{"t3", "t2", "t1"},
246 From: []string{"f4", "f5"}},
248 To: []string{"t4", "t3", "t2", "t1"},
249 From: []string{"f1", "f5"}},
254 PullRequest{locator1, []string{"f1", "f2"}},
255 PullRequest{locator2, []string{"f3", "f4"}},
256 PullRequest{locator3, []string{"f4", "f5"}},
257 PullRequest{locator4, []string{"f1", "f5"}},
260 PullRequest{locator2, []string{"f3", "f4"}},
261 PullRequest{locator3, []string{"f4", "f5"}},
262 PullRequest{locator4, []string{"f1", "f5"}},
265 PullRequest{locator3, []string{"f4", "f5"}},
266 PullRequest{locator4, []string{"f1", "f5"}},
269 PullRequest{locator4, []string{"f1", "f5"}},