X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/999c05af58ef1bb6f2b6804301f6ef8d02544a2b..9d7fe0af0a9c7cee773bfb8168f30790095e0389:/services/datamanager/summary/pull_list_test.go diff --git a/services/datamanager/summary/pull_list_test.go b/services/datamanager/summary/pull_list_test.go index 5638dc40f1..e2050c2b1e 100644 --- a/services/datamanager/summary/pull_list_test.go +++ b/services/datamanager/summary/pull_list_test.go @@ -9,13 +9,13 @@ import ( ) // Gocheck boilerplate -func Test(t *testing.T) { +func TestPullLists(t *testing.T) { TestingT(t) } -type MySuite struct{} +type PullSuite struct{} -var _ = Suite(&MySuite{}) +var _ = Suite(&PullSuite{}) // Helper method to declare string sets more succinctly // Could be placed somewhere more general. @@ -27,24 +27,25 @@ func stringSet(slice ...string) (m map[string]struct{}) { return } -func (s *MySuite) TestPullListPrintsJSONCorrectly(c *C) { +func (s *PullSuite) TestPullListPrintsJSONCorrectly(c *C) { pl := PullList{PullRequest{ - Locator: Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)}, + Locator: Locator(blockdigest.MakeTestDigestSpecifySize(0xBadBeef, 56789)), Servers: []string{"keep0.qr1hi.arvadosapi.com:25107", "keep1.qr1hi.arvadosapi.com:25108"}}} b, err := json.Marshal(pl) c.Assert(err, IsNil) - expectedOutput := `[{"locator":"0000000000000000000000000badbeef",` + + expectedOutput := `[{"locator":"0000000000000000000000000badbeef+56789",` + `"servers":["keep0.qr1hi.arvadosapi.com:25107",` + `"keep1.qr1hi.arvadosapi.com:25108"]}]` c.Check(string(b), Equals, expectedOutput) } -func (s *MySuite) TestCreatePullServers(c *C) { +func (s *PullSuite) TestCreatePullServers(c *C) { var cs CanonicalString c.Check( CreatePullServers(cs, + stringSet(), stringSet(), []string{}, 5), @@ -53,7 +54,8 @@ func (s *MySuite) TestCreatePullServers(c *C) { c.Check( CreatePullServers(cs, - stringSet("keep0:25107", "keep1:25108"), + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet(), []string{}, 5), DeepEquals, @@ -61,38 +63,64 @@ func (s *MySuite) TestCreatePullServers(c *C) { c.Check( CreatePullServers(cs, - stringSet("keep0:25107", "keep1:25108"), - []string{"keep0:25107"}, + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet("https://keep0:25107"), + []string{"https://keep0:25107"}, + 5), + DeepEquals, + PullServers{To: []string{}, From: []string{"https://keep0:25107"}}) + + c.Check( + CreatePullServers(cs, + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet("https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"), + []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"}, 5), DeepEquals, - PullServers{To: []string{}, From: []string{"keep0:25107"}}) + PullServers{To: []string{"https://keep3:25110", "https://keep2:25109"}, + From: []string{"https://keep1:25108", "https://keep0:25107"}}) c.Check( CreatePullServers(cs, - stringSet("keep0:25107", "keep1:25108"), - []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"}, + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet("https://keep3:25110", "https://keep1:25108", "https://keep0:25107"), + []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"}, 5), DeepEquals, - PullServers{To: []string{"keep3:25110", "keep2:25109"}, - From: []string{"keep1:25108", "keep0:25107"}}) + PullServers{To: []string{"https://keep3:25110"}, + From: []string{"https://keep1:25108", "https://keep0:25107"}}) + + c.Check( + CreatePullServers(cs, + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet("https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"), + []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"}, + 1), + DeepEquals, + PullServers{To: []string{"https://keep3:25110"}, + From: []string{"https://keep1:25108", "https://keep0:25107"}}) c.Check( CreatePullServers(cs, - stringSet("keep0:25107", "keep1:25108"), - []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"}, + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet("https://keep3:25110", "https://keep2:25109", + "https://keep1:25108", "https://keep0:25107"), + []string{"https://keep3:25110", "https://keep2:25109", + "https://keep1:25108", "https://keep0:25107"}, 1), DeepEquals, - PullServers{To: []string{"keep3:25110"}, - From: []string{"keep1:25108", "keep0:25107"}}) + PullServers{To: []string{"https://keep3:25110"}, + From: []string{"https://keep1:25108", "https://keep0:25107"}}) c.Check( CreatePullServers(cs, - stringSet("keep0:25107", "keep1:25108"), - []string{"keep3:25110", "keep2:25109", "keep1:25108", "keep0:25107"}, + stringSet("https://keep0:25107", "https://keep1:25108"), + stringSet("https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"), + []string{"https://keep3:25110", "https://keep2:25109", "https://keep1:25108", "https://keep0:25107"}, 0), DeepEquals, PullServers{To: []string{}, - From: []string{"keep1:25108", "keep0:25107"}}) + From: []string{"https://keep1:25108", "https://keep0:25107"}}) } // Checks whether two pull list maps are equal. Since pull lists are @@ -113,10 +141,10 @@ func (c *pullListMapEqualsChecker) Check(params []interface{}, names []string) ( } for _, v := range obtained { - sort.Sort(PullListByDigest(v)) + sort.Sort(PullListByLocator(v)) } for _, v := range expected { - sort.Sort(PullListByDigest(v)) + sort.Sort(PullListByLocator(v)) } return DeepEquals.Check(params, names) @@ -127,7 +155,7 @@ var PullListMapEquals Checker = &pullListMapEqualsChecker{&CheckerInfo{ Params: []string{"obtained", "expected"}, }} -func (s *MySuite) TestBuildPullLists(c *C) { +func (s *PullSuite) TestBuildPullLists(c *C) { c.Check( BuildPullLists(map[Locator]PullServers{}), PullListMapEquals, @@ -150,15 +178,15 @@ func (s *MySuite) TestBuildPullLists(c *C) { BuildPullLists(map[Locator]PullServers{ locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}}}), PullListMapEquals, - map[string]PullList{"t1": PullList{ - PullRequest{Locator: locator1, Servers: []string{"f1", "f2"}}}}) + map[string]PullList{ + "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}}) c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{To: []string{"t1"}, From: []string{}}}), PullListMapEquals, map[string]PullList{"t1": PullList{ - PullRequest{Locator: locator1, Servers: []string{}}}}) + PullRequest{locator1, []string{}}}}) c.Check( BuildPullLists(map[Locator]PullServers{ @@ -168,10 +196,8 @@ func (s *MySuite) TestBuildPullLists(c *C) { }}), PullListMapEquals, map[string]PullList{ - "t1": PullList{ - PullRequest{Locator: locator1, Servers: []string{"f1", "f2"}}}, - "t2": PullList{ - PullRequest{Locator: locator1, Servers: []string{"f1", "f2"}}}, + "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}, + "t2": PullList{PullRequest{locator1, []string{"f1", "f2"}}}, }) locator2 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xCabbed)} @@ -181,10 +207,8 @@ func (s *MySuite) TestBuildPullLists(c *C) { locator2: PullServers{To: []string{"t2"}, From: []string{"f3", "f4"}}}), PullListMapEquals, map[string]PullList{ - "t1": PullList{ - PullRequest{Locator: locator1, Servers: []string{"f1", "f2"}}}, - "t2": PullList{ - PullRequest{Locator: locator2, Servers: []string{"f3", "f4"}}}, + "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}, + "t2": PullList{PullRequest{locator2, []string{"f3", "f4"}}}, }) c.Check( @@ -199,11 +223,11 @@ func (s *MySuite) TestBuildPullLists(c *C) { PullListMapEquals, map[string]PullList{ "t1": PullList{ - PullRequest{Locator: locator1, Servers: []string{"f1", "f2"}}, - PullRequest{Locator: locator2, Servers: []string{"f3", "f4"}}, + PullRequest{locator1, []string{"f1", "f2"}}, + PullRequest{locator2, []string{"f3", "f4"}}, }, "t2": PullList{ - PullRequest{Locator: locator2, Servers: []string{"f3", "f4"}}, + PullRequest{locator2, []string{"f3", "f4"}}, }, }) @@ -227,29 +251,22 @@ func (s *MySuite) TestBuildPullLists(c *C) { PullListMapEquals, map[string]PullList{ "t1": PullList{ - PullRequest{Locator: locator1, Servers: []string{"f1", "f2"}}, - PullRequest{Locator: locator2, Servers: []string{"f3", "f4"}}, - PullRequest{Locator: locator3, Servers: []string{"f4", "f5"}}, - PullRequest{Locator: locator4, Servers: []string{"f1", "f5"}}, + PullRequest{locator1, []string{"f1", "f2"}}, + PullRequest{locator2, []string{"f3", "f4"}}, + PullRequest{locator3, []string{"f4", "f5"}}, + PullRequest{locator4, []string{"f1", "f5"}}, }, "t2": PullList{ - PullRequest{Locator: locator2, Servers: []string{"f3", "f4"}}, - PullRequest{Locator: locator3, Servers: []string{"f4", "f5"}}, - PullRequest{Locator: locator4, Servers: []string{"f1", "f5"}}, + PullRequest{locator2, []string{"f3", "f4"}}, + PullRequest{locator3, []string{"f4", "f5"}}, + PullRequest{locator4, []string{"f1", "f5"}}, }, "t3": PullList{ - PullRequest{Locator: locator3, Servers: []string{"f4", "f5"}}, - PullRequest{Locator: locator4, Servers: []string{"f1", "f5"}}, + PullRequest{locator3, []string{"f4", "f5"}}, + PullRequest{locator4, []string{"f1", "f5"}}, }, "t4": PullList{ - PullRequest{Locator: locator4, Servers: []string{"f1", "f5"}}, + PullRequest{locator4, []string{"f1", "f5"}}, }, }) } - -func (s *MySuite) TestRemoveProtocolPrefix(c *C) { - c.Check(RemoveProtocolPrefix("blah"), Equals, "blah") - c.Check(RemoveProtocolPrefix("bl/ah"), Equals, "ah") - c.Check(RemoveProtocolPrefix("http://blah.com"), Equals, "blah.com") - c.Check(RemoveProtocolPrefix("https://blah.com:8900"), Equals, "blah.com:8900") -}