4 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
10 func Test(t *testing.T) {
16 var _ = Suite(&MySuite{})
18 // This captures the result we expect from
19 // ReadCollections.Summarize(). Because CollectionUuidToIndex is
20 // indeterminate, we replace BlockToCollectionIndices with
21 // BlockToCollectionUuids.
22 type ExpectedSummary struct {
23 OwnerToCollectionSize map[string]int
24 BlockToDesiredReplication map[blockdigest.DigestWithSize]int
25 BlockToCollectionUuids map[blockdigest.DigestWithSize][]string
28 func CompareSummarizedReadCollections(c *C,
29 summarized ReadCollections,
30 expected ExpectedSummary) {
32 c.Assert(summarized.OwnerToCollectionSize, DeepEquals,
33 expected.OwnerToCollectionSize)
35 c.Assert(summarized.BlockToDesiredReplication, DeepEquals,
36 expected.BlockToDesiredReplication)
38 summarizedBlockToCollectionUuids :=
39 make(map[blockdigest.DigestWithSize]map[string]struct{})
40 for digest, indices := range summarized.BlockToCollectionIndices {
41 uuidSet := make(map[string]struct{})
42 summarizedBlockToCollectionUuids[digest] = uuidSet
43 for _, index := range indices {
44 uuidSet[summarized.CollectionIndexToUuid[index]] = struct{}{}
48 expectedBlockToCollectionUuids :=
49 make(map[blockdigest.DigestWithSize]map[string]struct{})
50 for digest, uuidSlice := range expected.BlockToCollectionUuids {
51 uuidSet := make(map[string]struct{})
52 expectedBlockToCollectionUuids[digest] = uuidSet
53 for _, uuid := range uuidSlice {
54 uuidSet[uuid] = struct{}{}
58 c.Assert(summarizedBlockToCollectionUuids, DeepEquals,
59 expectedBlockToCollectionUuids)
62 func (s *MySuite) TestSummarizeSimple(checker *C) {
63 rc := MakeTestReadCollections([]TestCollectionSpec{TestCollectionSpec{
70 c := rc.UuidToCollection["col0"]
72 blockDigest1 := blockdigest.MakeTestDigestWithSize(1)
73 blockDigest2 := blockdigest.MakeTestDigestWithSize(2)
75 expected := ExpectedSummary{
76 OwnerToCollectionSize: map[string]int{c.OwnerUuid: c.TotalSize},
77 BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{blockDigest1: 5, blockDigest2: 5},
78 BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{blockDigest1: []string{c.Uuid}, blockDigest2: []string{c.Uuid}},
81 CompareSummarizedReadCollections(checker, rc, expected)
84 func (s *MySuite) TestSummarizeOverlapping(checker *C) {
85 rc := MakeTestReadCollections([]TestCollectionSpec{
98 c0 := rc.UuidToCollection["col0"]
99 c1 := rc.UuidToCollection["col1"]
101 blockDigest1 := blockdigest.MakeTestDigestWithSize(1)
102 blockDigest2 := blockdigest.MakeTestDigestWithSize(2)
103 blockDigest3 := blockdigest.MakeTestDigestWithSize(3)
105 expected := ExpectedSummary{
106 OwnerToCollectionSize: map[string]int{
107 c0.OwnerUuid: c0.TotalSize,
108 c1.OwnerUuid: c1.TotalSize,
110 BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{
115 BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{
116 blockDigest1: []string{c0.Uuid},
117 blockDigest2: []string{c0.Uuid, c1.Uuid},
118 blockDigest3: []string{c1.Uuid},
122 CompareSummarizedReadCollections(checker, rc, expected)