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{Entries: []PullListEntry{PullListEntry{
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 := `{"blocks":[{"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(EntriesByDigest(v.Entries))
118 for _, v := range expected {
119 sort.Sort(EntriesByDigest(v.Entries))
122 return DeepEquals.Check(params, names)
125 var PullListMapEquals Checker = &pullListMapEqualsChecker{
126 &CheckerInfo{Name: "PullListMapEquals", Params: []string{"obtained", "expected"}},
129 func (s *MySuite) TestBuildPullLists(c *C) {
131 BuildPullLists(map[Locator]PullServers{}),
133 map[string]PullList{})
135 locator1 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)}
137 BuildPullLists(map[Locator]PullServers{
138 locator1: PullServers{To: []string{}, From: []string{}}}),
140 map[string]PullList{})
143 BuildPullLists(map[Locator]PullServers{
144 locator1: PullServers{To: []string{}, From: []string{"f1", "f2"}}}),
146 map[string]PullList{})
149 BuildPullLists(map[Locator]PullServers{
150 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}}}),
152 map[string]PullList{"t1": PullList{Entries: []PullListEntry{PullListEntry{
154 Servers: []string{"f1", "f2"}}}}})
157 BuildPullLists(map[Locator]PullServers{
158 locator1: PullServers{To: []string{"t1"}, From: []string{}}}),
160 map[string]PullList{"t1": PullList{Entries: []PullListEntry{PullListEntry{
162 Servers: []string{}}}}})
165 BuildPullLists(map[Locator]PullServers{
166 locator1: PullServers{To: []string{"t1", "t2"}, From: []string{"f1", "f2"}}}),
169 "t1": PullList{Entries: []PullListEntry{PullListEntry{
171 Servers: []string{"f1", "f2"}}}},
172 "t2": PullList{Entries: []PullListEntry{PullListEntry{
174 Servers: []string{"f1", "f2"}}}},
177 locator2 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xCabbed)}
179 BuildPullLists(map[Locator]PullServers{
180 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}},
181 locator2: PullServers{To: []string{"t2"}, From: []string{"f3", "f4"}}}),
184 "t1": PullList{Entries: []PullListEntry{PullListEntry{
186 Servers: []string{"f1", "f2"}}}},
187 "t2": PullList{Entries: []PullListEntry{PullListEntry{
189 Servers: []string{"f3", "f4"}}}},
193 BuildPullLists(map[Locator]PullServers{
194 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}},
195 locator2: PullServers{To: []string{"t2", "t1"}, From: []string{"f3", "f4"}}}),
198 "t1": PullList{Entries: []PullListEntry{
201 Servers: []string{"f1", "f2"}},
204 Servers: []string{"f3", "f4"}}}},
205 "t2": PullList{Entries: []PullListEntry{PullListEntry{
207 Servers: []string{"f3", "f4"}}}},
210 locator3 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xDeadBeef)}
211 locator4 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xFedBeef)}
213 BuildPullLists(map[Locator]PullServers{
214 locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}},
215 locator2: PullServers{To: []string{"t2", "t1"}, From: []string{"f3", "f4"}},
216 locator3: PullServers{To: []string{"t3", "t2", "t1"}, From: []string{"f4", "f5"}},
217 locator4: PullServers{To: []string{"t4", "t3", "t2", "t1"}, From: []string{"f1", "f5"}},
221 "t1": PullList{Entries: []PullListEntry{
224 Servers: []string{"f1", "f2"}},
227 Servers: []string{"f3", "f4"}},
230 Servers: []string{"f4", "f5"}},
233 Servers: []string{"f1", "f5"}},
235 "t2": PullList{Entries: []PullListEntry{
238 Servers: []string{"f3", "f4"}},
241 Servers: []string{"f4", "f5"}},
244 Servers: []string{"f1", "f5"}},
246 "t3": PullList{Entries: []PullListEntry{
249 Servers: []string{"f4", "f5"}},
252 Servers: []string{"f1", "f5"}},
254 "t4": PullList{Entries: []PullListEntry{
257 Servers: []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")