Expand description
Terse assertions for DomainError values.
Error tests otherwise repeat assert_eq!(err.category(), ...) and
assert_eq!(err.code().as_str(), ...). These helpers — both free functions
and a DomainErrorExt extension trait — make the intent obvious and the
panic messages descriptive.
use klauthed_testing::assertions::{assert_category, assert_code, DomainErrorExt};
use klauthed_error::{DomainError, ErrorCategory, ErrorCode};
#[derive(Debug)]
struct NotThere;
impl std::fmt::Display for NotThere {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("missing")
}
}
impl std::error::Error for NotThere {}
impl DomainError for NotThere {
fn category(&self) -> ErrorCategory { ErrorCategory::NotFound }
fn code(&self) -> ErrorCode { ErrorCode::new("thing.not_found") }
}
let err = NotThere;
// Free functions:
assert_category(&err, ErrorCategory::NotFound);
assert_code(&err, "thing.not_found");
// Or the fluent extension trait:
err.assert_category(ErrorCategory::NotFound)
.assert_code("thing.not_found")
.assert_http_status(404);Traits§
- Domain
Error Ext - Fluent assertions on any
DomainError, each returning&selfso they chain.
Functions§
- assert_
category - Assert that
err’scategoryequalsexpected. - assert_
code - Assert that
err’scodestring equalsexpected. - assert_
http_ status - Assert that
err’shttp_statusequalsexpected. - assert_
retryable - Assert that
err’sis_retryableequalsexpected.