logo
pub struct TestClient<E> { /* private fields */ }
This is supported on crate feature test only.
Expand description

A client for testing.

Implementations

Create a new client for the specified endpoint.

Sets the default header for each requests.

Examples
use poem::{handler, http::HeaderMap, test::TestClient, Route};

#[handler]
fn index(headers: &HeaderMap) -> String {
    headers
        .get("X-Custom-Header")
        .and_then(|value| value.to_str().ok())
        .unwrap_or_default()
        .to_string()
}

let app = Route::new().at("/", index);
let cli = TestClient::new(app).default_header("X-Custom-Header", "test");

let resp = cli.get("/").send().await;
resp.assert_status_is_ok();
resp.assert_text("test").await;

Sets the default content type for each requests.

Create a TestRequestBuilder with GET method.

Create a TestRequestBuilder with POST method.

Create a TestRequestBuilder with PUT method.

Create a TestRequestBuilder with DELETE method.

Create a TestRequestBuilder with HEAD method.

Create a TestRequestBuilder with OPTIONS method.

Create a TestRequestBuilder with CONNECT method.

Create a TestRequestBuilder with PATCH method.

Create a TestRequestBuilder with TRACE method.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more