Skip to main content

rust_serv/management/
mod.rs

1//! Management API module
2//!
3//! This module provides management API endpoints for health checks,
4//! readiness checks, and runtime statistics.
5
6mod config;
7mod handler;
8mod stats;
9
10pub use config::ManagementConfig;
11pub use handler::{ManagementHandler, ManagementResponse};
12pub use stats::{ServerStats, StatsCollector};
13
14use http_body_util::Full;
15use hyper::body::Bytes;
16use hyper::Response;
17
18/// Create a JSON response with the given status and body
19pub fn json_response(status: u16, body: &str) -> Response<Full<Bytes>> {
20    Response::builder()
21        .status(status)
22        .header("Content-Type", "application/json")
23        .body(Full::new(Bytes::from(body.to_string())))
24        .unwrap()
25}
26
27#[cfg(test)]
28mod tests {
29    use super::*;
30
31    #[test]
32    fn test_json_response_creation() {
33        let response = json_response(200, r#"{"test":"value"}"#);
34        assert_eq!(response.status(), 200);
35        assert_eq!(
36            response.headers().get("Content-Type").unwrap(),
37            "application/json"
38        );
39    }
40
41    #[test]
42    fn test_json_response_500() {
43        let response = json_response(500, r#"{"error":"internal"}"#);
44        assert_eq!(response.status(), 500);
45    }
46
47    #[test]
48    fn test_json_response_503() {
49        let response = json_response(503, r#"{"status":"not_ready"}"#);
50        assert_eq!(response.status(), 503);
51    }
52}