test: assert that errors are Send
All checks were successful
Test / build (map[name:stable]) (push) Successful in 4m57s
Test / build (map[name:nightly]) (push) Successful in 5m37s
Release Please / Release-plz (push) Successful in 10s

Closes kemitix/kxio#65
This commit is contained in:
Paul Campbell 2025-01-24 18:37:43 +00:00
parent 43fa1c68f3
commit 4d9ba931ee
4 changed files with 61 additions and 2 deletions

View file

@ -47,6 +47,12 @@ impl Clone for Error {
}
}
impl From<Error> for Box<dyn std::error::Error + Send> {
fn from(value: Error) -> Self {
Box::new(value)
}
}
/// Represents a success or a failure.
///
/// Any failure is related to `std::io`, a Path Traversal

View file

@ -55,6 +55,12 @@ impl Clone for Error {
}
}
impl From<Error> for Box<dyn std::error::Error + Send> {
fn from(value: Error) -> Self {
Box::new(value)
}
}
/// Represents a success or a failure within [kxio::net][crate::net].
///
/// Any failure is related to `std::io`, a Path Traversal

View file

@ -89,7 +89,18 @@ impl Display for Plan {
for m in &self.match_request {
write!(f, "{m} ")?;
}
writeln!(f, "=> {:?}", self.response)
writeln!(
f,
"=> Response {{ url: \"{}\", status: {}, headers: {{{}}} }}",
self.response.url(),
self.response.status(),
self.response
.headers()
.iter()
.map(|(k, v)| format!("{k:?}: {v:?}"))
.collect::<Vec<_>>()
.join(", ")
)
}
}
@ -1104,7 +1115,7 @@ mod tests {
"=>",
"Response {",
"url: \"http://no.url.provided.local/\",",
"status: 204,",
"status: 204 No Content,",
"headers: {\"foo\": \"bar\", \"baz\": \"buck\"}",
"}\n",
]

View file

@ -10,5 +10,41 @@ pub enum Error {
}
impl std::error::Error for Error {}
impl From<Error> for Box<dyn std::error::Error + Send> {
fn from(value: Error) -> Self {
Box::new(value)
}
}
/// Represents a success or a failure using `fs` or `net`.
pub type Result<T> = core::result::Result<T, Error>;
#[cfg(test)]
mod tests {
// all errors should be Send
fn is_send<T: Send>() {}
#[test]
fn error_is_send() {
is_send::<crate::Error>();
}
#[test]
fn base_error_can_be_boxed_send() {
let e = crate::Error::Fs(crate::fs::Error::IoString("test".to_string()));
let _box: Box<dyn std::error::Error + Send> = e.into();
}
#[test]
fn fs_error_can_be_boxed_send() {
let e = crate::fs::Error::IoString("test".to_string());
let _box: Box<dyn std::error::Error + Send> = e.into();
}
#[test]
fn net_error_can_be_boxed_send() {
let e = crate::net::Error::NetIsNotAMock;
let _box: Box<dyn std::error::Error + Send> = e.into();
}
}