9437: gofmt
[arvados.git] / services / datamanager / keep / keep_test.go
index 42559af624936cb8acbec5b2bca3ae006b59778c..66988498481bf848d0ace840abb6bf838e9f7cf9 100644 (file)
@@ -12,6 +12,7 @@ import (
        "testing"
 
        "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
+       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
        "git.curoverse.com/arvados.git/sdk/go/blockdigest"
        "git.curoverse.com/arvados.git/sdk/go/keepclient"
 
@@ -42,7 +43,7 @@ func (s *KeepSuite) TestSendTrashLists(c *C) {
        defer server.Close()
 
        tl := map[string]TrashList{
-               server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
+               server.URL: {TrashRequest{"000000000000000000000000deadbeef", 99}}}
 
        arv := arvadosclient.ArvadosClient{ApiToken: "abc123"}
        kc := keepclient.KeepClient{Arvados: &arv, Client: &http.Client{}}
@@ -50,7 +51,7 @@ func (s *KeepSuite) TestSendTrashLists(c *C) {
                map[string]string{"xxxx": server.URL},
                map[string]string{})
 
-       err := SendTrashLists(&kc, tl)
+       err := SendTrashLists(nil, &kc, tl, false)
 
        c.Check(err, IsNil)
 
@@ -69,7 +70,7 @@ func (tse *TestHandlerError) ServeHTTP(writer http.ResponseWriter, req *http.Req
 
 func sendTrashListError(c *C, server *httptest.Server) {
        tl := map[string]TrashList{
-               server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
+               server.URL: {TrashRequest{"000000000000000000000000deadbeef", 99}}}
 
        arv := arvadosclient.ArvadosClient{ApiToken: "abc123"}
        kc := keepclient.KeepClient{Arvados: &arv, Client: &http.Client{}}
@@ -77,7 +78,7 @@ func sendTrashListError(c *C, server *httptest.Server) {
                map[string]string{"xxxx": server.URL},
                map[string]string{})
 
-       err := SendTrashLists(&kc, tl)
+       err := SendTrashLists(nil, &kc, tl, false)
 
        c.Check(err, NotNil)
        c.Check(err[0], NotNil)
@@ -93,59 +94,6 @@ func (s *KeepSuite) TestSendTrashListUnreachable(c *C) {
        sendTrashListError(c, httptest.NewUnstartedServer(&TestHandler{}))
 }
 
-type StatusAndBody struct {
-       respStatus   int
-       responseBody string
-}
-
-type APIStub struct {
-       data map[string]StatusAndBody
-}
-
-func (stub *APIStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
-       if req.URL.Path == "/redirect-loop" {
-               http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
-               return
-       }
-
-       pathResponse := stub.data[req.URL.Path]
-       if pathResponse.responseBody != "" {
-               if pathResponse.respStatus == -1 {
-                       http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
-               } else {
-                       resp.WriteHeader(pathResponse.respStatus)
-                       resp.Write([]byte(pathResponse.responseBody))
-               }
-       } else {
-               resp.WriteHeader(500)
-               resp.Write([]byte(``))
-       }
-}
-
-type KeepServerStub struct {
-       data map[string]StatusAndBody
-}
-
-func (stub *KeepServerStub) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
-       if req.URL.Path == "/redirect-loop" {
-               http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
-               return
-       }
-
-       pathResponse := stub.data[req.URL.Path]
-       if pathResponse.responseBody != "" {
-               if pathResponse.respStatus == -1 {
-                       http.Redirect(resp, req, "/redirect-loop", http.StatusFound)
-               } else {
-                       resp.WriteHeader(pathResponse.respStatus)
-                       resp.Write([]byte(pathResponse.responseBody))
-               }
-       } else {
-               resp.WriteHeader(500)
-               resp.Write([]byte(``))
-       }
-}
-
 type APITestData struct {
        numServers int
        serverType string
@@ -153,7 +101,7 @@ type APITestData struct {
 }
 
 func (s *KeepSuite) TestGetKeepServers_UnsupportedServiceType(c *C) {
-       testGetKeepServersFromAPI(c, APITestData{1, "notadisk", 200}, "Unsupported service type")
+       testGetKeepServersFromAPI(c, APITestData{1, "notadisk", 200}, "Found no keepservices with the service type disk")
 }
 
 func (s *KeepSuite) TestGetKeepServers_ReceivedTooFewServers(c *C) {
@@ -177,9 +125,9 @@ func testGetKeepServersFromAPI(c *C, testData APITestData, expectedError string)
        }
 
        ksJSON, _ := json.Marshal(keepServers)
-       apiData := make(map[string]StatusAndBody)
-       apiData["/arvados/v1/keep_services"] = StatusAndBody{testData.statusCode, string(ksJSON)}
-       apiStub := APIStub{apiData}
+       apiStubResponses := make(map[string]arvadostest.StubResponse)
+       apiStubResponses["/arvados/v1/keep_services"] = arvadostest.StubResponse{testData.statusCode, string(ksJSON)}
+       apiStub := arvadostest.ServerStub{apiStubResponses}
 
        api := httptest.NewServer(&apiStub)
        defer api.Close()
@@ -254,10 +202,10 @@ func (s *KeepSuite) TestGetKeepServers_ReadServerResponseWithTwoBlocks(c *C) {
 }
 
 func testGetKeepServersAndSummarize(c *C, testData KeepServerTestData) {
-       ksData := make(map[string]StatusAndBody)
-       ksData["/status.json"] = StatusAndBody{testData.statusStatusCode, string(`{}`)}
-       ksData["/index"] = StatusAndBody{testData.indexStatusCode, testData.indexResponseBody}
-       ksStub := KeepServerStub{ksData}
+       ksStubResponses := make(map[string]arvadostest.StubResponse)
+       ksStubResponses["/status.json"] = arvadostest.StubResponse{testData.statusStatusCode, string(`{}`)}
+       ksStubResponses["/index"] = arvadostest.StubResponse{testData.indexStatusCode, testData.indexResponseBody}
+       ksStub := arvadostest.ServerStub{ksStubResponses}
        ks := httptest.NewServer(&ksStub)
        defer ks.Close()
 
@@ -278,9 +226,9 @@ func testGetKeepServersAndSummarize(c *C, testData KeepServerTestData) {
                }},
        }
        ksJSON, _ := json.Marshal(servers_list)
-       apiData := make(map[string]StatusAndBody)
-       apiData["/arvados/v1/keep_services"] = StatusAndBody{200, string(ksJSON)}
-       apiStub := APIStub{apiData}
+       apiStubResponses := make(map[string]arvadostest.StubResponse)
+       apiStubResponses["/arvados/v1/keep_services"] = arvadostest.StubResponse{200, string(ksJSON)}
+       apiStub := arvadostest.ServerStub{apiStubResponses}
 
        api := httptest.NewServer(&apiStub)
        defer api.Close()