[−][src]Struct gotham::plain::test::TestServer
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
impl TestServer
[src]
pub fn new<NH: NewHandler + 'static>(new_handler: NH) -> Result<TestServer> where
NH::Instance: UnwindSafe,
[src]
NH::Instance: UnwindSafe,
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.
pub fn with_timeout<NH: NewHandler + 'static>(
new_handler: NH,
timeout: u64
) -> Result<TestServer> where
NH::Instance: UnwindSafe,
[src]
new_handler: NH,
timeout: u64
) -> Result<TestServer> where
NH::Instance: UnwindSafe,
Sets the request timeout to timeout
seconds and returns a new TestServer
.
pub fn client(&self) -> TestClient<Self, TestConnect>
[src]
Returns a client connected to the TestServer
. The transport is handled internally, and
the server will see a default socket address of 127.0.0.1:10000
as the source address for
the connection.
pub fn spawn<F>(&self, fut: F) where
F: Future<Output = ()> + Send + 'static,
[src]
F: Future<Output = ()> + Send + 'static,
Spawns the given future on the TestServer
's internal runtime.
This allows you to spawn more futures ontop of the TestServer
in your
tests.
pub fn client_with_address(
&self,
client_addr: SocketAddr
) -> TestClient<Self, TestConnect>
[src]
&self,
client_addr: SocketAddr
) -> TestClient<Self, TestConnect>
Returns a client connected to the TestServer
. The transport is handled internally, and
the server will see client_addr
as the source address for the connection. The
client_addr
can be any valid SocketAddr
, and need not be contactable.
Trait Implementations
impl Clone for TestServer
[src]
fn clone(&self) -> TestServer
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Server for TestServer
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,