From 44e5e390ebec80eeac194905a10b1d48cc63fa41 Mon Sep 17 00:00:00 2001 From: cschen Date: Sun, 3 Nov 2024 17:19:38 +0100 Subject: [PATCH] chore: implement from ConnectionError and from RemoteError for AssertionError --- src/tests/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/tests/mod.rs b/src/tests/mod.rs index a1907ca..b699b4f 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -5,6 +5,7 @@ mod client; mod server; pub mod fixtures; +use crate::errors::{ConnectionError, RemoteError}; #[derive(Debug)] pub struct AssertionError(String); @@ -23,6 +24,27 @@ impl std::fmt::Display for AssertionError { impl std::error::Error for AssertionError {} +impl From for AssertionError { + fn from(value: ConnectionError) -> Self { + match value { + ConnectionError::Transport(error) => AssertionError::new(&format!( + "Connection::Transport error during setup of a test: {}", + error, + )), + ConnectionError::Remote(remote_error) => AssertionError::new(&format!( + "Connection::Remote error during setup of a test: {}", + remote_error, + )), + } + } +} + +impl From for AssertionError { + fn from(value: RemoteError) -> Self { + AssertionError::new(&format!("Remote error during setup of a test: {}", value,)) + } +} + #[macro_export] macro_rules! assert_or_err { ($s:expr) => {