tty_web/web/
health.rs

1//! Health-check endpoint (`GET /api/v1/ping`).
2
3use axum::Json;
4use serde::Serialize;
5
6/// Response body for the health-check endpoint.
7#[derive(Serialize)]
8pub struct HealthResponse {
9    status: &'static str,
10    version: &'static str,
11}
12
13pub async fn ping() -> Json<HealthResponse> {
14    Json(HealthResponse {
15        status: "ok",
16        version: env!("CARGO_PKG_VERSION"),
17    })
18}
19
20#[cfg(test)]
21mod tests {
22    use super::*;
23
24    #[tokio::test]
25    async fn test_ping() {
26        let Json(resp) = ping().await;
27        assert_eq!(resp.status, "ok");
28        assert_eq!(resp.version, env!("CARGO_PKG_VERSION"));
29    }
30}