From d6321e775aeee95f55687017d8a963f968bffc46 Mon Sep 17 00:00:00 2001 From: Kharec Date: Fri, 6 Mar 2026 15:37:53 +0100 Subject: [PATCH] test(integration): update DB monitoring health assertion to match nested services payload --- .../integration/router_integration_test.go | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/internal/integration/router_integration_test.go b/internal/integration/router_integration_test.go index 6cf644a..8057ef8 100644 --- a/internal/integration/router_integration_test.go +++ b/internal/integration/router_integration_test.go @@ -2,7 +2,6 @@ package integration import ( "bytes" - "encoding/json" "net/http" "net/http/httptest" "strings" @@ -63,13 +62,33 @@ func TestIntegration_Router_FullMiddlewareChain(t *testing.T) { t.Run("DBMonitoring_Active", func(t *testing.T) { request := makeGetRequest(t, router, "/health") - var response map[string]any - if err := json.NewDecoder(request.Body).Decode(&response); err == nil { - if data, ok := response["data"].(map[string]any); ok { - if _, exists := data["database_stats"]; !exists { - t.Error("Expected database_stats in health response") - } - } + response := assertJSONResponse(t, request, http.StatusOK) + if response == nil { + return + } + + data, ok := getDataFromResponse(response) + if !ok { + t.Fatal("Expected data to be a map") + } + + services, ok := data["services"].(map[string]any) + if !ok { + t.Fatal("Expected services in health response") + } + + databaseService, ok := services["database"].(map[string]any) + if !ok { + t.Fatal("Expected database service in health response") + } + + details, ok := databaseService["details"].(map[string]any) + if !ok { + t.Fatal("Expected database details in health response") + } + + if _, exists := details["stats"]; !exists { + t.Error("Expected database stats in health response") } })