use axum::extract::State;
use axum::response::IntoResponse;
use axum::Json;
use serde::Serialize;
#[derive(Debug, Clone, Serialize)]
pub struct HealthResponse {
pub status: &'static str,
}
impl HealthResponse {
pub const fn ok() -> Self {
Self { status: "ok" }
}
}
#[tracing::instrument(skip_all)]
pub async fn handle(_state: State<super::RouterState>) -> impl IntoResponse {
Json(HealthResponse::ok())
}
pub fn register_routes(
router: axum::Router<super::RouterState>,
) -> axum::Router<super::RouterState> {
router.route("/healthz", axum::routing::get(handle))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_health_response_ok() {
let response = HealthResponse::ok();
assert_eq!(response.status, "ok");
}
#[test]
fn test_health_response_serialization() {
let response = HealthResponse::ok();
let json = serde_json::to_string(&response).expect("serialization should succeed");
assert_eq!(json, r#"{"status":"ok"}"#);
}
}