7490: Update the previously failing keep_test.go; no new tests added. We can now...
[arvados.git] / services / datamanager / keep / keep_test.go
index 85f704c8a299d13048863c6d5d71ca35498b66e6..272fad296d32aea49cddfaeba9b145e71f0fc1e7 100644 (file)
@@ -2,11 +2,14 @@ package keep
 
 import (
        "encoding/json"
-       "git.curoverse.com/arvados.git/sdk/go/keepclient"
-       . "gopkg.in/check.v1"
        "net/http"
        "net/http/httptest"
        "testing"
+
+       "git.curoverse.com/arvados.git/sdk/go/arvadosclient"
+       "git.curoverse.com/arvados.git/sdk/go/keepclient"
+
+       . "gopkg.in/check.v1"
 )
 
 // Gocheck boilerplate
@@ -22,26 +25,30 @@ type TestHandler struct {
        request TrashList
 }
 
-func (this *TestHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
+func (ts *TestHandler) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
        r := json.NewDecoder(req.Body)
-       r.Decode(&this.request)
+       r.Decode(&ts.request)
 }
 
 func (s *KeepSuite) TestSendTrashLists(c *C) {
        th := TestHandler{}
        server := httptest.NewServer(&th)
+       defer server.Close()
 
        tl := map[string]TrashList{
                server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
 
-       kc := keepclient.KeepClient{Client: &http.Client{}}
+       arv := arvadosclient.ArvadosClient{ApiToken: "abc123"}
+       kc := keepclient.KeepClient{Arvados: &arv, Client: &http.Client{}}
        kc.SetServiceRoots(map[string]string{"xxxx": server.URL},
                map[string]string{"xxxx": server.URL},
                map[string]string{})
 
-       SendTrashLists("", &kc, tl)
+       err := SendTrashLists(&kc, tl)
        server.Close()
 
+       c.Check(err, IsNil)
+
        c.Check(th.request,
                DeepEquals,
                tl[server.URL])
@@ -51,42 +58,32 @@ func (s *KeepSuite) TestSendTrashLists(c *C) {
 type TestHandlerError struct {
 }
 
-func (this *TestHandlerError) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
-       http.Error(writer, "I'm a teapot", 405)
+func (tse *TestHandlerError) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
+       http.Error(writer, "I'm a teapot", 418)
 }
 
-func (s *KeepSuite) TestSendTrashListError(c *C) {
-       // Server responds with an error
-
-       th := TestHandlerError{}
-       server := httptest.NewServer(&th)
-
+func sendTrashListError(c *C, server *httptest.Server) {
        tl := map[string]TrashList{
                server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
 
-       kc := keepclient.KeepClient{Client: &http.Client{}}
+       arv := arvadosclient.ArvadosClient{ApiToken: "abc123"}
+       kc := keepclient.KeepClient{Arvados: &arv, Client: &http.Client{}}
        kc.SetServiceRoots(map[string]string{"xxxx": server.URL},
                map[string]string{"xxxx": server.URL},
                map[string]string{})
 
-       SendTrashLists("", &kc, tl)
-       server.Close()
-}
-
-func (s *KeepSuite) TestSendTrashListError2(c *C) {
-       // Server is not reachable
-
-       th := TestHandler{}
-       server := httptest.NewServer(&th)
-       server.Close()
+       err := SendTrashLists(&kc, tl)
 
-       tl := map[string]TrashList{
-               server.URL: TrashList{TrashRequest{"000000000000000000000000deadbeef", 99}}}
+       c.Check(err, NotNil)
+       c.Check(err[0], NotNil)
+}
 
-       kc := keepclient.KeepClient{Client: &http.Client{}}
-       kc.SetServiceRoots(map[string]string{"xxxx": server.URL},
-               map[string]string{"xxxx": server.URL},
-               map[string]string{})
+func (s *KeepSuite) TestSendTrashListErrorResponse(c *C) {
+       server := httptest.NewServer(&TestHandlerError{})
+       sendTrashListError(c, server)
+       defer server.Close()
+}
 
-       SendTrashLists("", &kc, tl)
+func (s *KeepSuite) TestSendTrashListUnreachable(c *C) {
+       sendTrashListError(c, httptest.NewUnstartedServer(&TestHandler{}))
 }