pub struct TestServer { /* private fields */ }
Expand description
The TestServer
type, which is used as a harness when writing test cases for Hyper services
(which Gotham’s Router
is). An instance of TestServer
is run asynchronously within the
current thread, and is only accessible by a client returned from the TestServer
.
Examples
use gotham::test::TestServer;
let test_server = TestServer::new(|| Ok(my_handler)).unwrap();
let response = test_server.client().get("http://localhost/").perform().unwrap();
assert_eq!(response.status(), StatusCode::ACCEPTED);
Implementations
sourceimpl TestServer
impl TestServer
sourcepub fn new<NH: NewHandler + 'static>(new_handler: NH) -> Result<TestServer>
pub fn new<NH: NewHandler + 'static>(new_handler: NH) -> Result<TestServer>
Creates a TestServer
instance for the Handler
spawned by new_handler
. This server has
the same guarantee given by hyper::server::Http::bind
, that a new service will be spawned
for each connection.
Timeout will be set to 10 seconds.
sourcepub fn with_timeout<NH: NewHandler + 'static>(
new_handler: NH,
timeout: u64
) -> Result<TestServer>
pub fn with_timeout<NH: NewHandler + 'static>(
new_handler: NH,
timeout: u64
) -> Result<TestServer>
Sets the request timeout to timeout
seconds and returns a new TestServer
.
sourcepub fn client(&self) -> TestClient<Self, TestConnect>
pub fn client(&self) -> TestClient<Self, TestConnect>
Returns a client connected to the TestServer
. The transport is handled internally.
Trait Implementations
sourceimpl Clone for TestServer
impl Clone for TestServer
sourcefn clone(&self) -> TestServer
fn clone(&self) -> TestServer
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
sourceimpl Server for TestServer
impl Server for TestServer
sourcefn run_future<F, O>(&self, future: F) -> O where
F: Future<Output = O>,
fn run_future<F, O>(&self, future: F) -> O where
F: Future<Output = O>,
Runs a Future until it resolves.
sourcefn request_expiry(&self) -> Sleep
fn request_expiry(&self) -> Sleep
Returns a Delay that will expire when a request should.
Auto Trait Implementations
impl RefUnwindSafe for TestServer
impl Send for TestServer
impl Sync for TestServer
impl Unpin for TestServer
impl UnwindSafe for TestServer
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