X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/372a67d4364d4776aaa8a5ae9a4dd0ac16a0c524..6c56f80642aae0ec0ff0bfc939ae33dd49e0ca6b:/services/keepstore/handler_test.go diff --git a/services/keepstore/handler_test.go b/services/keepstore/handler_test.go index 40b4839e06..f012ea3902 100644 --- a/services/keepstore/handler_test.go +++ b/services/keepstore/handler_test.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + // Tests for Keep HTTP handlers: // // GetBlockHandler @@ -23,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 @@ -823,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( @@ -958,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{}{} }() @@ -1090,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 @@ -1136,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()) + } +}