chore: convert check_status into macro to satisfy borrow checker
This commit is contained in:
parent
a787a48d41
commit
101234e300
2 changed files with 19 additions and 10 deletions
|
@ -70,6 +70,6 @@ mod tests {
|
|||
let app = get_app!(ctx).await;
|
||||
|
||||
let resp = get_request!(app, V1_API_ROUTES.meta.build_details);
|
||||
assert!(tests::check_status(resp, StatusCode::OK).await);
|
||||
check_status!(resp, StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
|
23
src/tests.rs
23
src/tests.rs
|
@ -130,13 +130,22 @@ macro_rules! get_app {
|
|||
|
||||
/// Utility function to check for status of a test response, attempt response payload serialization
|
||||
/// and print payload if response status doesn't match expected status
|
||||
pub async fn check_status(resp: ServiceResponse, expected: StatusCode) -> bool {
|
||||
let status = resp.status();
|
||||
if status != expected {
|
||||
eprintln!("[error] Expected status code: {expected} received: {status}");
|
||||
let response: serde_json::Value = actix_web::test::read_body_json(resp).await;
|
||||
#[macro_export]
|
||||
macro_rules! check_status {
|
||||
($resp:expr, $expected:expr) => {
|
||||
let status = $resp.status();
|
||||
if status != $expected {
|
||||
eprintln!(
|
||||
"[error] Expected status code: {} received: {status}",
|
||||
$expected
|
||||
);
|
||||
let response: serde_json::Value = actix_web::test::read_body_json($resp).await;
|
||||
eprintln!("[error] Body:\n{:#?}", response);
|
||||
assert_eq!(status, $expected);
|
||||
panic!()
|
||||
}
|
||||
|
||||
status == expected
|
||||
{
|
||||
assert_eq!(status, $expected);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue