duende_test/
error.rs

1//! Test error types.
2
3/// Result type alias for test operations.
4pub type Result<T> = std::result::Result<T, TestError>;
5
6/// Testing errors.
7#[derive(Debug, thiserror::Error)]
8pub enum TestError {
9    /// Harness error.
10    #[error("harness error: {0}")]
11    Harness(String),
12
13    /// Chaos injection error.
14    #[error("chaos injection error: {0}")]
15    Chaos(String),
16
17    /// Load test error.
18    #[error("load test error: {0}")]
19    LoadTest(String),
20
21    /// Assertion failed.
22    #[error("assertion failed: {0}")]
23    Assertion(String),
24
25    /// Timeout.
26    #[error("timeout after {0:?}")]
27    Timeout(std::time::Duration),
28
29    /// Shutdown error.
30    #[error("shutdown error: {0}")]
31    Shutdown(String),
32
33    /// Core daemon error.
34    #[error("daemon error: {0}")]
35    Daemon(#[from] duende_core::DaemonError),
36
37    /// Platform error.
38    #[error("platform error: {0}")]
39    Platform(#[from] duende_platform::PlatformError),
40
41    /// I/O error.
42    #[error("I/O error: {0}")]
43    Io(#[from] std::io::Error),
44}
45
46impl TestError {
47    /// Creates a harness error.
48    #[must_use]
49    pub fn harness(msg: impl Into<String>) -> Self {
50        Self::Harness(msg.into())
51    }
52
53    /// Creates an assertion error.
54    #[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}