Skip to content

Commit

Permalink
Remove body from healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelin01 committed Sep 7, 2024
1 parent 54a1e1e commit d8bdf99
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/handler/health.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
use axum::extract::State;
use axum::http::StatusCode;
use axum::Json;
use axum::response::IntoResponse;
use serde::Serialize;
use crate::server::AppState;
use crate::service::KubernetesService;

pub async fn health<S: AppState>(State(app_state): State<S>) -> impl IntoResponse {
match app_state.kubernetes().healthy().await {
true => (StatusCode::OK, Json(HealthResponse { status: "ok".into() })),
false => (StatusCode::INTERNAL_SERVER_ERROR, Json(HealthResponse { status: "err".into() })),
true => StatusCode::OK,
false => StatusCode::INTERNAL_SERVER_ERROR,
}
}

#[derive(Serialize)]
struct HealthResponse {
status: String,
}

#[cfg(test)]
mod tests {
use axum::body::Body;
use axum::http::{Request, StatusCode};
use http_body_util::BodyExt;
use serde_json::{json, Value};
use tower::ServiceExt;

use crate::config::Config;
Expand All @@ -42,9 +33,6 @@ mod tests {
.unwrap();

assert_eq!(response.status(), StatusCode::OK);
let body_bytes = response.into_body().collect().await.unwrap().to_bytes();
let body: Value = serde_json::from_slice(&body_bytes).unwrap();
assert_eq!(body, json!({"status": "ok"}));
}

#[tokio::test]
Expand All @@ -61,8 +49,5 @@ mod tests {
.unwrap();

assert_eq!(response.status(), StatusCode::INTERNAL_SERVER_ERROR);
let body_bytes = response.into_body().collect().await.unwrap().to_bytes();
let body: Value = serde_json::from_slice(&body_bytes).unwrap();
assert_eq!(body, json!({"status": "err"}));
}
}

0 comments on commit d8bdf99

Please sign in to comment.