chore: convert check_status into macro to satisfy borrow checker

This commit is contained in:
Aravinth Manivannan 2022-04-27 13:47:46 +05:30
parent a787a48d41
commit 101234e300
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
2 changed files with 19 additions and 10 deletions

View File

@ -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);
}
}

View File

@ -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;
eprintln!("[error] Body:\n{:#?}", response);
}
status == expected
#[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!()
}
{
assert_eq!(status, $expected);
}
};
}