fixed message
This commit is contained in:
+10
-8
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"authorization/db"
|
||||
"authorization/helper"
|
||||
"authorization/models"
|
||||
"authorization/redisclient"
|
||||
"context"
|
||||
@@ -18,11 +19,10 @@ import (
|
||||
// @Success 200 {object} HealthResponse
|
||||
// @Router /health [get]
|
||||
func HealthHandler(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(models.HealthResponse{
|
||||
response := models.HealthResponse{
|
||||
Status: "ok",
|
||||
})
|
||||
}
|
||||
helper.RespondWithJSON(w, http.StatusOK, response)
|
||||
}
|
||||
|
||||
// ReadyHandler checks if the service is ready to handle requests
|
||||
@@ -69,16 +69,18 @@ func ReadyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
allHealthy = false
|
||||
}
|
||||
|
||||
status := "ready"
|
||||
status := "AuthZ Capy!"
|
||||
statusCode := http.StatusOK
|
||||
if !allHealthy {
|
||||
status = "not_ready"
|
||||
status = "AuthZ not Capy!"
|
||||
statusCode = http.StatusServiceUnavailable
|
||||
}
|
||||
|
||||
w.WriteHeader(statusCode)
|
||||
json.NewEncoder(w).Encode(models.HealthResponse{
|
||||
if err := json.NewEncoder(w).Encode(models.HealthResponse{
|
||||
Status: status,
|
||||
Services: services,
|
||||
})
|
||||
}); err != nil {
|
||||
helper.LogError(err, "Error encoding health response")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +141,8 @@ func TestReadyHandlerDBUnhealthy(t *testing.T) {
|
||||
t.Fatalf(FailedToDecodeResponseMessage, err)
|
||||
}
|
||||
|
||||
if healthResp.Status != "not_ready" {
|
||||
t.Errorf("status = %v, want not_ready", healthResp.Status)
|
||||
if healthResp.Status != "AuthZ not Capy!" {
|
||||
t.Errorf("status = %v, want 'AuthZ not Capy!'", healthResp.Status)
|
||||
}
|
||||
|
||||
if healthResp.Services["database"] != "unhealthy" {
|
||||
@@ -181,8 +181,8 @@ func TestReadyHandlerDBNotInitialized(t *testing.T) {
|
||||
t.Fatalf(FailedToDecodeResponseMessage, err)
|
||||
}
|
||||
|
||||
if healthResp.Status != "not_ready" {
|
||||
t.Errorf("status = %v, want not_ready", healthResp.Status)
|
||||
if healthResp.Status != "AuthZ not Capy!" {
|
||||
t.Errorf("status = %v, want 'AuthZ not Capy!'", healthResp.Status)
|
||||
}
|
||||
|
||||
if healthResp.Services["database"] != "not_initialized" {
|
||||
@@ -348,8 +348,8 @@ func TestReadyHandlerBothServicesHealthy(t *testing.T) {
|
||||
var response models.HealthResponse
|
||||
json.NewDecoder(w.Body).Decode(&response)
|
||||
|
||||
if response.Status != "ready" {
|
||||
t.Errorf("Expected status 'ready', got '%s'", response.Status)
|
||||
if response.Status != "AuthZ Capy!" {
|
||||
t.Errorf("Expected status 'AuthZ Capy!', got '%s'", response.Status)
|
||||
}
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
@@ -380,9 +380,9 @@ func TestReadyHandlerNilDatabaseAndRedis(t *testing.T) {
|
||||
t.Fatalf(FailedToDecodeResponseMessage, err)
|
||||
}
|
||||
|
||||
// The handler returns "not_ready" when services are down
|
||||
if response.Status != "not_ready" && response.Status != "unhealthy" && response.Status != "degraded" {
|
||||
t.Errorf("Expected status 'not_ready', 'unhealthy', or 'degraded', got '%s'", response.Status)
|
||||
// The handler returns "AuthZ not Capy!" when services are down
|
||||
if response.Status != "AuthZ not Capy!" {
|
||||
t.Errorf("Expected status 'AuthZ not Capy!', got '%s'", response.Status)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user