entrenar/storage/preflight/
check_result.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
7pub enum CheckResult {
8 Passed { message: String },
10 Failed { message: String, details: Option<String> },
12 Skipped { reason: String },
14 Warning { message: String },
16}
17
18impl CheckResult {
19 pub fn passed(message: impl Into<String>) -> Self {
21 Self::Passed { message: message.into() }
22 }
23
24 pub fn failed(message: impl Into<String>) -> Self {
26 Self::Failed { message: message.into(), details: None }
27 }
28
29 pub fn failed_with_details(message: impl Into<String>, details: impl Into<String>) -> Self {
31 Self::Failed { message: message.into(), details: Some(details.into()) }
32 }
33
34 pub fn skipped(reason: impl Into<String>) -> Self {
36 Self::Skipped { reason: reason.into() }
37 }
38
39 pub fn warning(message: impl Into<String>) -> Self {
41 Self::Warning { message: message.into() }
42 }
43
44 pub fn is_passed(&self) -> bool {
46 matches!(self, Self::Passed { .. })
47 }
48
49 pub fn is_failed(&self) -> bool {
51 matches!(self, Self::Failed { .. })
52 }
53
54 pub fn is_warning(&self) -> bool {
56 matches!(self, Self::Warning { .. })
57 }
58
59 pub fn is_skipped(&self) -> bool {
61 matches!(self, Self::Skipped { .. })
62 }
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 #[test]
74 fn test_check_result_passed() {
75 let result = CheckResult::passed("test passed");
76 assert!(result.is_passed());
77 assert!(!result.is_failed());
78 }
79
80 #[test]
81 fn test_check_result_failed() {
82 let result = CheckResult::failed("test failed");
83 assert!(result.is_failed());
84 assert!(!result.is_passed());
85 }
86
87 #[test]
88 fn test_check_result_failed_with_details() {
89 let result = CheckResult::failed_with_details("failed", "some details");
90 assert!(result.is_failed());
91 if let CheckResult::Failed { details, .. } = result {
92 assert_eq!(details, Some("some details".to_string()));
93 }
94 }
95
96 #[test]
97 fn test_check_result_warning() {
98 let result = CheckResult::warning("warning message");
99 assert!(result.is_warning());
100 assert!(!result.is_failed());
101 }
102
103 #[test]
104 fn test_check_result_skipped() {
105 let result = CheckResult::skipped("skipped reason");
106 assert!(result.is_skipped());
107 }
108}