malbox_plugin_sdk/
health.rs1#[derive(Debug, Clone, PartialEq)]
12#[non_exhaustive]
13pub struct HealthStatus {
14 pub(crate) ready: bool,
15 pub(crate) reason: String,
16}
17
18impl HealthStatus {
19 pub fn ready() -> Self {
21 Self {
22 ready: true,
23 reason: String::new(),
24 }
25 }
26
27 pub fn not_ready(reason: impl Into<String>) -> Self {
29 Self {
30 ready: false,
31 reason: reason.into(),
32 }
33 }
34
35 pub fn is_ready(&self) -> bool {
37 self.ready
38 }
39
40 pub fn reason(&self) -> &str {
42 &self.reason
43 }
44}
45
46#[cfg(test)]
47mod tests {
48 use super::*;
49
50 #[test]
51 fn health_status_ready() {
52 let status = HealthStatus::ready();
53 assert!(status.is_ready());
54 assert!(status.reason().is_empty());
55 }
56
57 #[test]
58 fn health_status_not_ready() {
59 let status = HealthStatus::not_ready("loading rules");
60 assert!(!status.is_ready());
61 assert_eq!(status.reason(), "loading rules");
62 }
63
64 #[test]
65 fn health_status_exposes_getters() {
66 let ready = HealthStatus::ready();
67 assert!(ready.is_ready());
68 assert_eq!(ready.reason(), "");
69
70 let busy = HealthStatus::not_ready("loading rules");
71 assert!(!busy.is_ready());
72 assert_eq!(busy.reason(), "loading rules");
73 }
74}