Struct gotham::tls::test::AsyncTestServer
source · 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::tls::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§
source§impl AsyncTestServer
impl AsyncTestServer
sourcepub async fn new<NH: NewHandler + 'static>(
new_handler: NH
) -> Result<AsyncTestServer>
pub async fn new<NH: NewHandler + 'static>( new_handler: NH ) -> Result<AsyncTestServer>
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.
sourcepub async fn new_with_timeout<NH: NewHandler + 'static>(
new_handler: NH,
timeout: Duration
) -> Result<AsyncTestServer>
pub async fn new_with_timeout<NH: NewHandler + 'static>( new_handler: NH, timeout: Duration ) -> Result<AsyncTestServer>
Sets the request timeout to timeout
seconds and returns a new AsyncTestServer
.
sourcepub fn client(&self) -> AsyncTestClient<TestConnect>
pub fn client(&self) -> AsyncTestClient<TestConnect>
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§
source§impl Clone for AsyncTestServer
impl Clone for AsyncTestServer
source§fn clone(&self) -> AsyncTestServer
fn clone(&self) -> AsyncTestServer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more