2025-11-04 16:27:54 +01:00
|
|
|
//! Health check endpoint for monitoring service availability.
|
|
|
|
|
|
2025-11-04 09:17:18 +01:00
|
|
|
use poem_openapi::{ApiResponse, OpenApi};
|
|
|
|
|
|
|
|
|
|
use super::ApiCategory;
|
|
|
|
|
|
|
|
|
|
#[derive(ApiResponse)]
|
|
|
|
|
enum HealthResponse {
|
|
|
|
|
#[oai(status = 200)]
|
|
|
|
|
Ok,
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-04 16:27:54 +01:00
|
|
|
/// Health check API for monitoring service availability.
|
|
|
|
|
#[derive(Default, Clone)]
|
2025-11-04 09:17:18 +01:00
|
|
|
pub struct HealthApi;
|
|
|
|
|
|
2025-11-04 16:27:54 +01:00
|
|
|
#[OpenApi(tag = "ApiCategory::Health")]
|
2025-11-04 09:17:18 +01:00
|
|
|
impl HealthApi {
|
2025-11-04 16:27:54 +01:00
|
|
|
#[oai(path = "/health", method = "get")]
|
2025-11-04 09:17:18 +01:00
|
|
|
async fn ping(&self) -> HealthResponse {
|
2025-11-04 16:27:54 +01:00
|
|
|
tracing::event!(target: "backend::health", tracing::Level::DEBUG, "Accessing health-check endpoint");
|
2025-11-04 09:17:18 +01:00
|
|
|
HealthResponse::Ok
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
|
async fn health_check_works() {
|
|
|
|
|
let app = crate::get_test_app();
|
|
|
|
|
let cli = poem::test::TestClient::new(app);
|
2025-11-04 16:27:54 +01:00
|
|
|
let resp = cli.get("/api/health").send().await;
|
2025-11-04 09:17:18 +01:00
|
|
|
resp.assert_status_is_ok();
|
|
|
|
|
resp.assert_text("").await;
|
|
|
|
|
}
|