12475: Add TestManyFailedPuts with a short timeout.
[arvados.git] / services / keepstore / handler_test.go
index 751a4a77e3c8ba66431ca30d1d58f3cde2208f5d..424910dfa8b2af4a0d22ad9e91bd4eab20076af7 100644 (file)
@@ -27,6 +27,7 @@ import (
        "time"
 
        "git.curoverse.com/arvados.git/sdk/go/arvados"
+       "git.curoverse.com/arvados.git/sdk/go/arvadostest"
 )
 
 // A RequestTester represents the parameters for an HTTP request to
@@ -827,6 +828,18 @@ func IssueRequest(rt *RequestTester) *httptest.ResponseRecorder {
        return response
 }
 
+func IssueHealthCheckRequest(rt *RequestTester) *httptest.ResponseRecorder {
+       response := httptest.NewRecorder()
+       body := bytes.NewReader(rt.requestBody)
+       req, _ := http.NewRequest(rt.method, rt.uri, body)
+       if rt.apiToken != "" {
+               req.Header.Set("Authorization", "Bearer "+rt.apiToken)
+       }
+       loggingRouter := MakeRESTRouter()
+       loggingRouter.ServeHTTP(response, req)
+       return response
+}
+
 // ExpectStatusCode checks whether a response has the specified status code,
 // and reports a test failure if not.
 func ExpectStatusCode(
@@ -1140,3 +1153,21 @@ func TestUntrashHandlerWithNoWritableVolumes(t *testing.T) {
                http.StatusNotFound,
                response)
 }
+
+func TestHealthCheckPing(t *testing.T) {
+       theConfig.ManagementToken = arvadostest.ManagementToken
+       pingReq := &RequestTester{
+               method:   "GET",
+               uri:      "/_health/ping",
+               apiToken: arvadostest.ManagementToken,
+       }
+       response := IssueHealthCheckRequest(pingReq)
+       ExpectStatusCode(t,
+               "",
+               http.StatusOK,
+               response)
+       want := `{"health":"OK"}`
+       if !strings.Contains(response.Body.String(), want) {
+               t.Errorf("expected response to include %s: got %s", want, response.Body.String())
+       }
+}