X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/55aafbb07904ca24390dd47ea960eae7cb2b909a..6346a7c4c0cb5d7e8c5f01392b6cc64d329b68ec:/services/keepstore/handler_test.go diff --git a/services/keepstore/handler_test.go b/services/keepstore/handler_test.go index 751a4a77e3..f012ea3902 100644 --- a/services/keepstore/handler_test.go +++ b/services/keepstore/handler_test.go @@ -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( @@ -962,7 +975,7 @@ func TestGetHandlerClientDisconnect(t *testing.T) { ok := make(chan struct{}) go func() { req, _ := http.NewRequest("GET", fmt.Sprintf("/%s+%d", TestHash, len(TestBlock)), nil) - (&LoggingRESTRouter{router: MakeRESTRouter()}).ServeHTTP(resp, req) + MakeRESTRouter().ServeHTTP(resp, req) ok <- struct{}{} }() @@ -1094,7 +1107,7 @@ func TestUntrashHandler(t *testing.T) { response = IssueRequest(datamanagerWrongMethodReq) ExpectStatusCode(t, "Only PUT method is supported for untrash", - http.StatusBadRequest, + http.StatusMethodNotAllowed, response) // datamanagerReq => StatusOK @@ -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()) + } +}