Crate charted_testkit

Crate charted_testkit 

Source
Expand description
Noel (Trans Heart)

Β§πŸ“¦πŸ¦‹ charted TestKit

charted TestKit is a testing library for Axum, which extends libtest with its own test macro. The library can also be used for only Testcontainers as well.

TestKit was built to make integration testing easier for Axum services with Testcontainers support and additional macros to help build assertions based off Responses.

Β§Example

use charted_testkit::{test, TestContext, assert_successful, consume_body};
use axum::{body::Bytes, routing, Router};
use hyper::Method;

async fn hello() -> &'static str {
    "Hello, world!"
}

fn router() -> Router {
    Router::new().route("/", routing::get(hello))
}

#[test(router)]
async fn mytest(ctx: TestContext) {
    let res = ctx
        .request("/", Method::GET, None::<axum::body::Bytes>, |_| {})
        .await
        .expect("unable to send request");

    assert_successful!(res);

    let body = consume_body!(res);
    assert_eq!(body, Bytes::from_static(b"Hello, world!"));
}

Β§License

TestKit is released under the MIT License with love and care by Noelware, LLC.! πŸ»β€β„οΈπŸ¦‹

Please read the LICENSE file in the canonical repository for more information on what you can do with the source code.

MacrosΒ§

assert_doesnt_have_header
Assertion macro to indicate that a Response doesn’t have the header it needs.
assert_failure
Checks whenever if a Response failed.
assert_has_header
Assertion macro to indicate that a Response has the header it needs.
assert_status_code
Macro to easily assert if a given response’s status code is the same as one you provide.
assert_successful
Checks whenever if a Response is successful or not.
consume_body
Macro to consume the full body of a response and returns a Bytes container.

StructsΒ§

TestContext

FunctionsΒ§

noop_request
A empty function that can be used with TestContext::request.

Attribute MacrosΒ§

test
Represents a procedural attribute macro that does the heavy lifting of charted_testkit for you. This macro also manages: