From de90519b219cd4033fb379e26868b84778595201 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Tue, 2 Dec 2025 02:09:04 +0000 Subject: [PATCH] test: Add handleHealth method tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add 2 tests for health endpoint: - POST/PUT/DELETE/PATCH return 405 Method Not Allowed - HEAD is allowed (same as GET) Coverage: 50% → 83.3% --- internal/api/router_integration_test.go | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/internal/api/router_integration_test.go b/internal/api/router_integration_test.go index 9921f35..6bb5514 100644 --- a/internal/api/router_integration_test.go +++ b/internal/api/router_integration_test.go @@ -350,6 +350,46 @@ func TestServerInfoEndpointMethodNotAllowed(t *testing.T) { } } +func TestHealthEndpointMethodNotAllowed(t *testing.T) { + srv := newIntegrationServer(t) + + for _, method := range []string{http.MethodPost, http.MethodPut, http.MethodDelete, http.MethodPatch} { + req, err := http.NewRequest(method, srv.server.URL+"/api/health", nil) + if err != nil { + t.Fatalf("create request failed: %v", err) + } + + res, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatalf("health %s request failed: %v", method, err) + } + res.Body.Close() + + if res.StatusCode != http.StatusMethodNotAllowed { + t.Errorf("%s: unexpected status: got %d want %d", method, res.StatusCode, http.StatusMethodNotAllowed) + } + } +} + +func TestHealthEndpointHeadAllowed(t *testing.T) { + srv := newIntegrationServer(t) + + req, err := http.NewRequest(http.MethodHead, srv.server.URL+"/api/health", nil) + if err != nil { + t.Fatalf("create request failed: %v", err) + } + + res, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatalf("health HEAD request failed: %v", err) + } + res.Body.Close() + + if res.StatusCode != http.StatusOK { + t.Fatalf("HEAD: unexpected status: got %d want %d", res.StatusCode, http.StatusOK) + } +} + func TestConfigNodesUsesMockTopology(t *testing.T) { srv := newIntegrationServer(t)