4 "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
5 "git.curoverse.com/arvados.git/sdk/go/arvadostest"
6 "git.curoverse.com/arvados.git/sdk/go/blockdigest"
13 // Gocheck boilerplate
14 func Test(t *testing.T) {
20 var _ = Suite(&MySuite{})
22 // This captures the result we expect from
23 // ReadCollections.Summarize(). Because CollectionUUIDToIndex is
24 // indeterminate, we replace BlockToCollectionIndices with
25 // BlockToCollectionUuids.
26 type ExpectedSummary struct {
27 OwnerToCollectionSize map[string]int
28 BlockToDesiredReplication map[blockdigest.DigestWithSize]int
29 BlockToCollectionUuids map[blockdigest.DigestWithSize][]string
32 func CompareSummarizedReadCollections(c *C,
33 summarized ReadCollections,
34 expected ExpectedSummary) {
36 c.Assert(summarized.OwnerToCollectionSize, DeepEquals,
37 expected.OwnerToCollectionSize)
39 c.Assert(summarized.BlockToDesiredReplication, DeepEquals,
40 expected.BlockToDesiredReplication)
42 summarizedBlockToCollectionUuids :=
43 make(map[blockdigest.DigestWithSize]map[string]struct{})
44 for digest, indices := range summarized.BlockToCollectionIndices {
45 uuidSet := make(map[string]struct{})
46 summarizedBlockToCollectionUuids[digest] = uuidSet
47 for _, index := range indices {
48 uuidSet[summarized.CollectionIndexToUUID[index]] = struct{}{}
52 expectedBlockToCollectionUuids :=
53 make(map[blockdigest.DigestWithSize]map[string]struct{})
54 for digest, uuidSlice := range expected.BlockToCollectionUuids {
55 uuidSet := make(map[string]struct{})
56 expectedBlockToCollectionUuids[digest] = uuidSet
57 for _, uuid := range uuidSlice {
58 uuidSet[uuid] = struct{}{}
62 c.Assert(summarizedBlockToCollectionUuids, DeepEquals,
63 expectedBlockToCollectionUuids)
66 func (s *MySuite) TestSummarizeSimple(checker *C) {
67 rc := MakeTestReadCollections([]TestCollectionSpec{TestCollectionSpec{
74 c := rc.UUIDToCollection["col0"]
76 blockDigest1 := blockdigest.MakeTestDigestWithSize(1)
77 blockDigest2 := blockdigest.MakeTestDigestWithSize(2)
79 expected := ExpectedSummary{
80 OwnerToCollectionSize: map[string]int{c.OwnerUUID: c.TotalSize},
81 BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{blockDigest1: 5, blockDigest2: 5},
82 BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{blockDigest1: []string{c.UUID}, blockDigest2: []string{c.UUID}},
85 CompareSummarizedReadCollections(checker, rc, expected)
88 func (s *MySuite) TestSummarizeOverlapping(checker *C) {
89 rc := MakeTestReadCollections([]TestCollectionSpec{
102 c0 := rc.UUIDToCollection["col0"]
103 c1 := rc.UUIDToCollection["col1"]
105 blockDigest1 := blockdigest.MakeTestDigestWithSize(1)
106 blockDigest2 := blockdigest.MakeTestDigestWithSize(2)
107 blockDigest3 := blockdigest.MakeTestDigestWithSize(3)
109 expected := ExpectedSummary{
110 OwnerToCollectionSize: map[string]int{
111 c0.OwnerUUID: c0.TotalSize,
112 c1.OwnerUUID: c1.TotalSize,
114 BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{
119 BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{
120 blockDigest1: []string{c0.UUID},
121 blockDigest2: []string{c0.UUID, c1.UUID},
122 blockDigest3: []string{c1.UUID},
126 CompareSummarizedReadCollections(checker, rc, expected)
129 type APITestData struct {
130 // path and response map
131 responses map[string]arvadostest.StubResponse
133 // expected error, if any
137 func (s *MySuite) TestGetCollectionsAndSummarize_DiscoveryError(c *C) {
138 testGetCollectionsAndSummarize(c,
140 responses: make(map[string]arvadostest.StubResponse),
141 expectedError: "arvados API server error: 500.*",
145 func (s *MySuite) TestGetCollectionsAndSummarize_ApiErrorGetCollections(c *C) {
146 respMap := make(map[string]arvadostest.StubResponse)
147 respMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StubResponse{200, `{"defaultCollectionReplication":2}`}
148 respMap["/arvados/v1/collections"] = arvadostest.StubResponse{-1, ``}
150 testGetCollectionsAndSummarize(c,
153 expectedError: "arvados API server error: 302.*",
157 func (s *MySuite) TestGetCollectionsAndSummarize_GetCollectionsBadStreamName(c *C) {
158 respMap := make(map[string]arvadostest.StubResponse)
159 respMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StubResponse{200, `{"defaultCollectionReplication":2}`}
160 respMap["/arvados/v1/collections"] = arvadostest.StubResponse{200, `{"items_available":1,"items":[{"modified_at":"2015-11-24T15:04:05Z","manifest_text":"badstreamname"}]}`}
162 testGetCollectionsAndSummarize(c,
165 expectedError: "Invalid stream name: badstreamname",
169 func (s *MySuite) TestGetCollectionsAndSummarize_GetCollectionsBadFileToken(c *C) {
170 respMap := make(map[string]arvadostest.StubResponse)
171 respMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StubResponse{200, `{"defaultCollectionReplication":2}`}
172 respMap["/arvados/v1/collections"] = arvadostest.StubResponse{200, `{"items_available":1,"items":[{"modified_at":"2015-11-24T15:04:05Z","manifest_text":"./goodstream acbd18db4cc2f85cedef654fccc4a4d8+3 0:1:file1.txt file2.txt"}]}`}
174 testGetCollectionsAndSummarize(c,
177 expectedError: "Invalid file token: file2.txt",
181 func testGetCollectionsAndSummarize(c *C, testData APITestData) {
182 apiStub := arvadostest.ServerStub{testData.responses}
184 api := httptest.NewServer(&apiStub)
187 arv := arvadosclient.ArvadosClient{
189 ApiServer: api.URL[7:],
191 Client: &http.Client{Transport: &http.Transport{}},
194 // GetCollectionsAndSummarize
195 _, err := GetCollectionsAndSummarize(GetCollectionsParams{arv, nil, 10})
197 if testData.expectedError == "" {
200 c.Assert(err, ErrorMatches, testData.expectedError)