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.

Spawns the given future on the TestServer’s internal runtime. This allows you to spawn more futures ontop of the TestServer in your tests.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Runs a Future until it resolves.

Returns a Delay that will expire when a request should.

Runs the event loop until the response future is completed. 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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more