meta_srv/service/admin/
health.rs1use std::collections::HashMap;
16
17use tonic::codegen::http;
18
19use crate::error::Result;
20use crate::service::admin::HttpHandler;
21
22const HTTP_OK: &str = "OK\n";
23
24pub struct HealthHandler;
25
26#[async_trait::async_trait]
27impl HttpHandler for HealthHandler {
28 async fn handle(
29 &self,
30 _: &str,
31 _: http::Method,
32 _: &HashMap<String, String>,
33 ) -> Result<http::Response<String>> {
34 Ok(http::Response::builder()
35 .status(http::StatusCode::OK)
36 .body(HTTP_OK.to_owned())
37 .unwrap())
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use super::*;
44
45 #[tokio::test]
46 async fn test_health_handle() {
47 let health_handler = HealthHandler {};
48 let path = "any";
49 let params = HashMap::default();
50 let res = health_handler
51 .handle(path, http::Method::GET, ¶ms)
52 .await
53 .unwrap();
54
55 assert!(res.status().is_success());
56 assert_eq!(HTTP_OK.to_owned(), res.body().clone());
57 }
58}