1use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8
9use crate::lifecycle::{HealthStatus, ServiceStatus};
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct HealthReport {
14 pub status: HealthStatus,
15 pub services: Vec<ServiceHealth>,
16 pub timestamp: DateTime<Utc>,
17}
18
19impl Default for HealthReport {
20 fn default() -> Self {
21 Self {
22 status: HealthStatus::Healthy,
23 services: Vec::new(),
24 timestamp: Utc::now(),
25 }
26 }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31pub struct ServiceHealth {
32 pub name: String,
33 pub status: ServiceStatus,
34}
35
36#[cfg(test)]
37mod tests {
38 use super::*;
39
40 #[test]
41 fn test_health_report_serialization() {
42 let report = HealthReport {
43 status: HealthStatus::Healthy,
44 services: vec![ServiceHealth {
45 name: "prometheus".to_string(),
46 status: ServiceStatus::Started,
47 }],
48 timestamp: chrono::Utc::now(),
49 };
50
51 let json = serde_json::to_string(&report).unwrap();
52 assert!(json.contains("Healthy"));
53 assert!(json.contains("prometheus"));
54 assert!(json.contains("Started"));
55 assert!(json.contains("timestamp"));
56 }
57
58 #[test]
59 fn test_health_report_default() {
60 let report = HealthReport::default();
61 assert_eq!(report.status, HealthStatus::Healthy);
62 assert!(report.services.is_empty());
63 assert!(report.timestamp <= chrono::Utc::now());
64 }
65}