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
sourceimpl 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
sourceimpl Clone for AsyncTestServer
impl Clone for AsyncTestServer
sourcefn clone(&self) -> AsyncTestServer
fn clone(&self) -> AsyncTestServer
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl RefUnwindSafe for AsyncTestServer
impl Send for AsyncTestServer
impl Sync for AsyncTestServer
impl Unpin for AsyncTestServer
impl UnwindSafe for AsyncTestServer
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more