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 data map[string]arvadostest.StatusAndBody
133 // expected error, if any
137 func (s *MySuite) TestGetCollectionsAndSummarize_DiscoveryError(c *C) {
138 testData := APITestData{}
139 testData.expectedError = "arvados API server error: 500.*"
140 testGetCollectionsAndSummarize(c, testData)
143 func (s *MySuite) TestGetCollectionsAndSummarize_ApiErrorGetCollections(c *C) {
144 dataMap := make(map[string]arvadostest.StatusAndBody)
145 dataMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StatusAndBody{200, `{"defaultCollectionReplication":2}`}
146 dataMap["/arvados/v1/collections"] = arvadostest.StatusAndBody{-1, ``}
148 testData := APITestData{}
149 testData.data = dataMap
150 testData.expectedError = "arvados API server error: 302.*"
152 testGetCollectionsAndSummarize(c, testData)
155 func (s *MySuite) TestGetCollectionsAndSummarize_GetCollectionsBadManifest(c *C) {
156 dataMap := make(map[string]arvadostest.StatusAndBody)
157 dataMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StatusAndBody{200, `{"defaultCollectionReplication":2}`}
158 dataMap["/arvados/v1/collections"] = arvadostest.StatusAndBody{200, `{"items_available":1,"items":[{"modified_at":"2015-11-24T15:04:05Z","manifest_text":"thisisnotavalidmanifest"}]}`}
160 testData := APITestData{}
161 testData.data = dataMap
162 testData.expectedError = ".*invalid manifest format.*"
164 testGetCollectionsAndSummarize(c, testData)
167 func testGetCollectionsAndSummarize(c *C, testData APITestData) {
168 apiStub := arvadostest.APIStub{testData.data}
170 api := httptest.NewServer(&apiStub)
173 arv := arvadosclient.ArvadosClient{
175 ApiServer: api.URL[7:],
177 Client: &http.Client{Transport: &http.Transport{}},
180 // GetCollectionsAndSummarize
181 results := GetCollectionsAndSummarize(GetCollectionsParams{arv, nil, 10})
183 if testData.expectedError == "" {
184 c.Assert(results.Err, IsNil)
185 c.Assert(results, NotNil)
187 c.Assert(results.Err, ErrorMatches, testData.expectedError)