pub struct AsyncTestServer { /* private fields */ }
Expand description

An AsyncTestServer, that can be used for testing requests against a server in asynchronous contexts. The AsyncTestServer runs in the runtime where it is created and an AsyncTestClient can be created to make asynchronous requests to it.

This differs from crate::plain::test::TestServer in that it doesn’t come with it’s own runtime and therefore doesn’t crash when used inside of another runtime.

Example

use gotham::plain::test::AsyncTestServer;

let test_server = AsyncTestServer::new(|| Ok(my_handler)).await.unwrap();

let response = test_server.client().get("http://localhost/").perform().await.unwrap();
assert_eq!(response.status(), StatusCode::ACCEPTED);

Implementations

Creates an AsyncTestServer instance for the crate::handler::Handler spawned by new_handler. This server has the same guarantee given by hyper::server::Server::bind, that a new service will be spawned for each connection.

Requests will time out after 10 seconds by default. Use [AsyncTestServer::with_timeout] for a different timeout.

Sets the request timeout to timeout seconds and returns a new AsyncTestServer.

Returns a client connected to the AsyncTestServer. It can be used to make requests against the test server. The transport is handled internally.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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.

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.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

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