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§

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.

Sets the request timeout to timeout seconds and returns a new TestServer.

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.

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.