Struct gotham::test::TestServer
source · 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§
source§impl 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
pub fn client(&self) -> TestClient
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.
sourcepub fn client_with_address(&self, client_addr: SocketAddr) -> TestClient
pub fn client_with_address(&self, client_addr: SocketAddr) -> TestClient
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§
source§impl Clone for TestServer
impl Clone for TestServer
source§fn clone(&self) -> TestServer
fn clone(&self) -> TestServer
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more