X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c5f1d667aed3a993296374de3d53f3a2745c4ff4..7314917d65573b0e9d55f7b6522463c470356fba:/services/datamanager/collection/collection_test.go?ds=sidebyside diff --git a/services/datamanager/collection/collection_test.go b/services/datamanager/collection/collection_test.go index 6bb7ae5ede..1bf6a89f5a 100644 --- a/services/datamanager/collection/collection_test.go +++ b/services/datamanager/collection/collection_test.go @@ -64,7 +64,7 @@ func CompareSummarizedReadCollections(c *C, } func (s *MySuite) TestSummarizeSimple(checker *C) { - rc := MakeTestReadCollections([]TestCollectionSpec{TestCollectionSpec{ + rc := MakeTestReadCollections([]TestCollectionSpec{{ ReplicationLevel: 5, Blocks: []int{1, 2}, }}) @@ -79,7 +79,7 @@ func (s *MySuite) TestSummarizeSimple(checker *C) { expected := ExpectedSummary{ OwnerToCollectionSize: map[string]int{c.OwnerUUID: c.TotalSize}, BlockToDesiredReplication: map[blockdigest.DigestWithSize]int{blockDigest1: 5, blockDigest2: 5}, - BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{blockDigest1: []string{c.UUID}, blockDigest2: []string{c.UUID}}, + BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{blockDigest1: {c.UUID}, blockDigest2: {c.UUID}}, } CompareSummarizedReadCollections(checker, rc, expected) @@ -87,11 +87,11 @@ func (s *MySuite) TestSummarizeSimple(checker *C) { func (s *MySuite) TestSummarizeOverlapping(checker *C) { rc := MakeTestReadCollections([]TestCollectionSpec{ - TestCollectionSpec{ + { ReplicationLevel: 5, Blocks: []int{1, 2}, }, - TestCollectionSpec{ + { ReplicationLevel: 8, Blocks: []int{2, 3}, }, @@ -117,9 +117,9 @@ func (s *MySuite) TestSummarizeOverlapping(checker *C) { blockDigest3: 8, }, BlockToCollectionUuids: map[blockdigest.DigestWithSize][]string{ - blockDigest1: []string{c0.UUID}, - blockDigest2: []string{c0.UUID, c1.UUID}, - blockDigest3: []string{c1.UUID}, + blockDigest1: {c0.UUID}, + blockDigest2: {c0.UUID, c1.UUID}, + blockDigest3: {c1.UUID}, }, } @@ -128,61 +128,63 @@ func (s *MySuite) TestSummarizeOverlapping(checker *C) { type APITestData struct { // path and response map - data map[string]arvadostest.StatusAndBody + responses map[string]arvadostest.StubResponse // expected error, if any expectedError string } func (s *MySuite) TestGetCollectionsAndSummarize_DiscoveryError(c *C) { - testData := APITestData{} - testData.expectedError = "arvados API server error: 500.*" - testGetCollectionsAndSummarize(c, testData) + testGetCollectionsAndSummarize(c, + APITestData{ + responses: make(map[string]arvadostest.StubResponse), + expectedError: "arvados API server error: 500.*", + }) } func (s *MySuite) TestGetCollectionsAndSummarize_ApiErrorGetCollections(c *C) { - dataMap := make(map[string]arvadostest.StatusAndBody) - dataMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StatusAndBody{200, `{"defaultCollectionReplication":2}`} - dataMap["/arvados/v1/collections"] = arvadostest.StatusAndBody{-1, ``} - - testData := APITestData{} - testData.data = dataMap - testData.expectedError = "arvados API server error: 302.*" - - testGetCollectionsAndSummarize(c, testData) + respMap := make(map[string]arvadostest.StubResponse) + respMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StubResponse{200, `{"defaultCollectionReplication":2}`} + respMap["/arvados/v1/collections"] = arvadostest.StubResponse{-1, ``} + + testGetCollectionsAndSummarize(c, + APITestData{ + responses: respMap, + expectedError: "arvados API server error: 302.*", + }) } func (s *MySuite) TestGetCollectionsAndSummarize_GetCollectionsBadStreamName(c *C) { - dataMap := make(map[string]arvadostest.StatusAndBody) - dataMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StatusAndBody{200, `{"defaultCollectionReplication":2}`} - dataMap["/arvados/v1/collections"] = arvadostest.StatusAndBody{200, `{"items_available":1,"items":[{"modified_at":"2015-11-24T15:04:05Z","manifest_text":"badstreamname"}]}`} - - testData := APITestData{} - testData.data = dataMap - testData.expectedError = "Invalid stream name: badstreamname" - - testGetCollectionsAndSummarize(c, testData) + respMap := make(map[string]arvadostest.StubResponse) + respMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StubResponse{200, `{"defaultCollectionReplication":2}`} + respMap["/arvados/v1/collections"] = arvadostest.StubResponse{200, `{"items_available":1,"items":[{"modified_at":"2015-11-24T15:04:05Z","manifest_text":"badstreamname"}]}`} + + testGetCollectionsAndSummarize(c, + APITestData{ + responses: respMap, + expectedError: "Invalid stream name: badstreamname", + }) } func (s *MySuite) TestGetCollectionsAndSummarize_GetCollectionsBadFileToken(c *C) { - dataMap := make(map[string]arvadostest.StatusAndBody) - dataMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StatusAndBody{200, `{"defaultCollectionReplication":2}`} - dataMap["/arvados/v1/collections"] = arvadostest.StatusAndBody{200, `{"items_available":1,"items":[{"modified_at":"2015-11-24T15:04:05Z","manifest_text":"./goodstream acbd18db4cc2f85cedef654fccc4a4d8+3 0:1:file1.txt file2.txt"}]}`} - - testData := APITestData{} - testData.data = dataMap - testData.expectedError = "Invalid file token: file2.txt" - - testGetCollectionsAndSummarize(c, testData) + respMap := make(map[string]arvadostest.StubResponse) + respMap["/discovery/v1/apis/arvados/v1/rest"] = arvadostest.StubResponse{200, `{"defaultCollectionReplication":2}`} + 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"}]}`} + + testGetCollectionsAndSummarize(c, + APITestData{ + responses: respMap, + expectedError: "Invalid file token: file2.txt", + }) } func testGetCollectionsAndSummarize(c *C, testData APITestData) { - apiStub := arvadostest.APIStub{testData.data} + apiStub := arvadostest.ServerStub{testData.responses} api := httptest.NewServer(&apiStub) defer api.Close() - arv := arvadosclient.ArvadosClient{ + arv := &arvadosclient.ArvadosClient{ Scheme: "http", ApiServer: api.URL[7:], ApiToken: "abc123", @@ -190,12 +192,11 @@ func testGetCollectionsAndSummarize(c *C, testData APITestData) { } // GetCollectionsAndSummarize - results := GetCollectionsAndSummarize(GetCollectionsParams{arv, nil, 10}) + _, err := GetCollectionsAndSummarize(GetCollectionsParams{arv, nil, 10}) if testData.expectedError == "" { - c.Assert(results.Err, IsNil) - c.Assert(results, NotNil) + c.Assert(err, IsNil) } else { - c.Assert(results.Err, ErrorMatches, testData.expectedError) + c.Assert(err, ErrorMatches, testData.expectedError) } }