// Creates a ReadCollections object for testing based on the give // specs. Only the ReadAllCollections and UuidToCollection fields are // populated. To populate other fields call rc.Summarize(). func MakeTestReadCollections(specs []TestCollectionSpec) (rc ReadCollections) { rc = ReadCollections{ ReadAllCollections: true, UuidToCollection: map[string]Collection{}, } for i, spec := range specs { c := Collection{ Uuid: fmt.Sprintf("col%d", i), OwnerUuid: fmt.Sprintf("owner%d", i), ReplicationLevel: spec.ReplicationLevel, BlockDigestToSize: map[blockdigest.BlockDigest]int{}, } rc.UuidToCollection[c.Uuid] = c for _, j := range spec.Blocks { c.BlockDigestToSize[blockdigest.MakeTestBlockDigest(j)] = j } // We compute the size in a separate loop because the value // computed in the above loop would be invalid if c.Blocks // contained duplicates. for _, size := range c.BlockDigestToSize { c.TotalSize += size } } return }
func (s *PullSuite) TestBuildPullLists(c *C) { c.Check( BuildPullLists(map[Locator]PullServers{}), PullListMapEquals, map[string]PullList{}) locator1 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xBadBeef)} c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{To: []string{}, From: []string{}}}), PullListMapEquals, map[string]PullList{}) c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{To: []string{}, From: []string{"f1", "f2"}}}), PullListMapEquals, map[string]PullList{}) c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}}}), PullListMapEquals, 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{locator1, []string{}}}}) c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{ To: []string{"t1", "t2"}, From: []string{"f1", "f2"}, }}), PullListMapEquals, map[string]PullList{ "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}, "t2": PullList{PullRequest{locator1, []string{"f1", "f2"}}}, }) locator2 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xCabbed)} c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{To: []string{"t1"}, From: []string{"f1", "f2"}}, locator2: PullServers{To: []string{"t2"}, From: []string{"f3", "f4"}}}), PullListMapEquals, map[string]PullList{ "t1": PullList{PullRequest{locator1, []string{"f1", "f2"}}}, "t2": PullList{PullRequest{locator2, []string{"f3", "f4"}}}, }) c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{ To: []string{"t1"}, From: []string{"f1", "f2"}}, locator2: PullServers{ To: []string{"t2", "t1"}, From: []string{"f3", "f4"}}, }), PullListMapEquals, map[string]PullList{ "t1": PullList{ PullRequest{locator1, []string{"f1", "f2"}}, PullRequest{locator2, []string{"f3", "f4"}}, }, "t2": PullList{ PullRequest{locator2, []string{"f3", "f4"}}, }, }) locator3 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xDeadBeef)} locator4 := Locator{Digest: blockdigest.MakeTestBlockDigest(0xFedBeef)} c.Check( BuildPullLists(map[Locator]PullServers{ locator1: PullServers{ To: []string{"t1"}, From: []string{"f1", "f2"}}, locator2: PullServers{ To: []string{"t2", "t1"}, From: []string{"f3", "f4"}}, locator3: PullServers{ To: []string{"t3", "t2", "t1"}, From: []string{"f4", "f5"}}, locator4: PullServers{ To: []string{"t4", "t3", "t2", "t1"}, From: []string{"f1", "f5"}}, }), PullListMapEquals, map[string]PullList{ "t1": PullList{ PullRequest{locator1, []string{"f1", "f2"}}, PullRequest{locator2, []string{"f3", "f4"}}, PullRequest{locator3, []string{"f4", "f5"}}, PullRequest{locator4, []string{"f1", "f5"}}, }, "t2": PullList{ PullRequest{locator2, []string{"f3", "f4"}}, PullRequest{locator3, []string{"f4", "f5"}}, PullRequest{locator4, []string{"f1", "f5"}}, }, "t3": PullList{ PullRequest{locator3, []string{"f4", "f5"}}, PullRequest{locator4, []string{"f1", "f5"}}, }, "t4": PullList{ PullRequest{locator4, []string{"f1", "f5"}}, }, }) }