Macro trillium_testing::prelude::assert_ok

source ยท
macro_rules! assert_ok {
    ($conn:expr) => { ... };
    ($conn:expr, $body:expr) => { ... };
    ($conn:expr, $body:expr, $($header_name:literal => $header_value:expr,)+) => { ... };
    ($conn:expr, $body:expr, $($header_name:literal => $header_value:expr),*) => { ... };
}
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"
);