6260: datamanager integration testing - WIP
[arvados.git] / services / datamanager / keep / keep_test.go
index 85f704c8a299d13048863c6d5d71ca35498b66e6..f39463ed6233169a9c9509133a729d7bed1fbeb6 100644 (file)
@@ -39,9 +39,11 @@ func (s *KeepSuite) TestSendTrashLists(c *C) {
                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])
@@ -52,15 +54,10 @@ type TestHandlerError struct {
 }
 
 func (this *TestHandlerError) ServeHTTP(writer http.ResponseWriter, req *http.Request) {
-       http.Error(writer, "I'm a teapot", 405)
+       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}}}
 
@@ -69,24 +66,16 @@ func (s *KeepSuite) TestSendTrashListError(c *C) {
                map[string]string{"xxxx": server.URL},
                map[string]string{})
 
-       SendTrashLists("", &kc, tl)
-       server.Close()
-}
-
-func (s *KeepSuite) TestSendTrashListError2(c *C) {
-       // Server is not reachable
+       err := SendTrashLists("", &kc, tl)
 
-       th := TestHandler{}
-       server := httptest.NewServer(&th)
-       server.Close()
-
-       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) {
+       sendTrashListError(c, httptest.NewServer(&TestHandlerError{}))
+}
 
-       SendTrashLists("", &kc, tl)
+func (s *KeepSuite) TestSendTrashListUnreachable(c *C) {
+       sendTrashListError(c, httptest.NewUnstartedServer(&TestHandler{}))
 }