1pub type Result<T> = std::result::Result<T, TestError>;
5
6#[derive(Debug, thiserror::Error)]
8pub enum TestError {
9 #[error("harness error: {0}")]
11 Harness(String),
12
13 #[error("chaos injection error: {0}")]
15 Chaos(String),
16
17 #[error("load test error: {0}")]
19 LoadTest(String),
20
21 #[error("assertion failed: {0}")]
23 Assertion(String),
24
25 #[error("timeout after {0:?}")]
27 Timeout(std::time::Duration),
28
29 #[error("shutdown error: {0}")]
31 Shutdown(String),
32
33 #[error("daemon error: {0}")]
35 Daemon(#[from] duende_core::DaemonError),
36
37 #[error("platform error: {0}")]
39 Platform(#[from] duende_platform::PlatformError),
40
41 #[error("I/O error: {0}")]
43 Io(#[from] std::io::Error),
44}
45
46impl TestError {
47 #[must_use]
49 pub fn harness(msg: impl Into<String>) -> Self {
50 Self::Harness(msg.into())
51 }
52
53 #[must_use]
55 pub fn assertion(msg: impl Into<String>) -> Self {
56 Self::Assertion(msg.into())
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63 use std::time::Duration;
64
65 #[test]
66 fn test_harness_error() {
67 let err = TestError::harness("setup failed");
68 assert!(err.to_string().contains("harness error"));
69 assert!(err.to_string().contains("setup failed"));
70 }
71
72 #[test]
73 fn test_assertion_error() {
74 let err = TestError::assertion("expected 5, got 10");
75 assert!(err.to_string().contains("assertion failed"));
76 assert!(err.to_string().contains("expected 5"));
77 }
78
79 #[test]
80 fn test_chaos_error() {
81 let err = TestError::Chaos("injection failed".into());
82 assert!(err.to_string().contains("chaos injection"));
83 }
84
85 #[test]
86 fn test_load_test_error() {
87 let err = TestError::LoadTest("connection pool exhausted".into());
88 assert!(err.to_string().contains("load test error"));
89 }
90
91 #[test]
92 fn test_timeout_error() {
93 let err = TestError::Timeout(Duration::from_secs(30));
94 assert!(err.to_string().contains("timeout"));
95 assert!(err.to_string().contains("30"));
96 }
97
98 #[test]
99 fn test_shutdown_error() {
100 let err = TestError::Shutdown("daemon failed to terminate".into());
101 assert!(err.to_string().contains("shutdown error"));
102 assert!(err.to_string().contains("failed to terminate"));
103 }
104
105 #[test]
106 fn test_io_error_conversion() {
107 let io_err = std::io::Error::new(std::io::ErrorKind::TimedOut, "timed out");
108 let err: TestError = io_err.into();
109 assert!(err.to_string().contains("I/O error"));
110 }
111}