1 // Code used for testing only.
7 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
10 type TestCollectionSpec struct {
11 // The desired replication level
13 // Blocks this contains, represented by ints. Ints repeated will
14 // still only represent one block
18 // Creates a ReadCollections object for testing based on the give
19 // specs. Only the ReadAllCollections and UuidToCollection fields are
20 // populated. To populate other fields call rc.Summarize().
21 func MakeTestReadCollections(specs []TestCollectionSpec) (rc ReadCollections) {
23 ReadAllCollections: true,
24 UuidToCollection: map[string]Collection{},
27 for i, spec := range specs {
29 Uuid: fmt.Sprintf("col%d", i),
30 OwnerUuid: fmt.Sprintf("owner%d", i),
31 ReplicationLevel: spec.ReplicationLevel,
32 BlockDigestToSize: map[blockdigest.BlockDigest]int{},
34 rc.UuidToCollection[c.Uuid] = c
35 for _, j := range spec.Blocks {
36 c.BlockDigestToSize[blockdigest.MakeTestBlockDigest(j)] = j
38 // We compute the size in a separate loop because the value
39 // computed in the above loop would be invalid if c.Blocks
40 // contained duplicates.
41 for _, size := range c.BlockDigestToSize {
48 // Returns a slice giving the collection index of each collection that
49 // was passed in to MakeTestReadCollections. rc.Summarize() must be
50 // called before this method, since Summarize() assigns an index to
52 func (rc ReadCollections) CollectionIndicesForTesting() (indices []int) {
53 // TODO(misha): Assert that rc.Summarize() has been called.
54 numCollections := len(rc.CollectionIndexToUuid)
55 indices = make([]int, numCollections)
56 for i := 0; i < numCollections; i++ {
57 indices[i] = rc.CollectionUuidToIndex[fmt.Sprintf("col%d", i)]