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 app = get_app!(ctx).await;
|
||||||
|
|
||||||
let resp = get_request!(app, V1_API_ROUTES.meta.build_details);
|
let resp = get_request!(app, V1_API_ROUTES.meta.build_details);
|
||||||
assert!(tests::check_status(resp, StatusCode::OK).await);
|
check_status!(resp, StatusCode::OK);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
27
src/tests.rs
27
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
|
/// 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
|
/// and print payload if response status doesn't match expected status
|
||||||
pub async fn check_status(resp: ServiceResponse, expected: StatusCode) -> bool {
|
#[macro_export]
|
||||||
let status = resp.status();
|
macro_rules! check_status {
|
||||||
if status != expected {
|
($resp:expr, $expected:expr) => {
|
||||||
eprintln!("[error] Expected status code: {expected} received: {status}");
|
let status = $resp.status();
|
||||||
let response: serde_json::Value = actix_web::test::read_body_json(resp).await;
|
if status != $expected {
|
||||||
eprintln!("[error] Body:\n{:#?}", response);
|
eprintln!(
|
||||||
}
|
"[error] Expected status code: {} received: {status}",
|
||||||
|
$expected
|
||||||
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!()
|
||||||
|
}
|
||||||
|
{
|
||||||
|
assert_eq!(status, $expected);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue