Struct axum_test::TestServer
source · pub struct TestServer { /* private fields */ }Expand description
A means to run Axum applications within a server that you can query. This is for writing tests.
Implementations§
source§impl TestServer
impl TestServer
sourcepub fn new(app: IntoMakeService<Router>) -> Result<Self>
pub fn new(app: IntoMakeService<Router>) -> Result<Self>
This will take the given app, and run it. It will be run on a randomly picked port.
The webserver is then wrapped within a TestServer,
and returned.
sourcepub fn new_with_config(
app: IntoMakeService<Router>,
options: TestServerConfig
) -> Result<Self>
pub fn new_with_config( app: IntoMakeService<Router>, options: TestServerConfig ) -> Result<Self>
Creates a TestServer running your app on the address given.
Adds the given cookies. They will be included on all future requests.
They will be stored over the top of the existing cookies.
Adds the given cookie. It will be included on all future requests.
It will be stored over the top of the existing cookies.
sourcepub fn get(&self, path: &str) -> TestRequest
pub fn get(&self, path: &str) -> TestRequest
Creates a GET request to the path.
sourcepub fn post(&self, path: &str) -> TestRequest
pub fn post(&self, path: &str) -> TestRequest
Creates a POST request to the given path.
sourcepub fn patch(&self, path: &str) -> TestRequest
pub fn patch(&self, path: &str) -> TestRequest
Creates a PATCH request to the path.
sourcepub fn put(&self, path: &str) -> TestRequest
pub fn put(&self, path: &str) -> TestRequest
Creates a PUT request to the path.
sourcepub fn delete(&self, path: &str) -> TestRequest
pub fn delete(&self, path: &str) -> TestRequest
Creates a DELETE request to the path.
sourcepub fn method(&self, method: Method, path: &str) -> TestRequest
pub fn method(&self, method: Method, path: &str) -> TestRequest
Creates a request to the path, using the method you provided.