Skip to main content

assert_ok

Macro assert_ok 

Source
macro_rules! assert_ok {
    ($conn:expr_2021) => { ... };
    ($conn:expr_2021, $body:expr_2021) => { ... };
    ($conn:expr_2021, $body:expr_2021, $($header_name:literal => $header_value:expr_2021,)+) => { ... };
    ($conn:expr_2021, $body:expr_2021, $($header_name:literal => $header_value:expr_2021),*) => { ... };
}
Expand description

assert_ok is like assert_response! except it always asserts a status of 200 Ok.

it can be used to assert: just that the response was successful, that the response was successful and a response body, or that the response was successful, a response body, and any number of headers

use trillium_testing::prelude::*;
async fn handler(conn: Conn) -> Conn {
conn.ok("body")
.with_response_header("server", "special-custom-server")
.with_response_header("request-id", "10")
}

assert_ok!(get("/").on(&handler));
assert_ok!(get("/").on(&handler), "body");
assert_ok!(get("/").on(&handler), "body");
assert_ok!(get("/").on(&handler), "body", "server" => "special-custom-server");

assert_ok!(
get("/").on(&handler),
"body",
"server" => "special-custom-server",
"request-id" => "10",
"content-length" => "4"
);