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>) -> Self
pub fn new(app: IntoMakeService<Router>) -> 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.
This function is for quick use. It will panic if it cannot create the webserver.
Sourcepub fn new_with_address(
app: IntoMakeService<Router>,
socket_address: SocketAddr,
) -> Result<Self>
pub fn new_with_address( app: IntoMakeService<Router>, socket_address: SocketAddr, ) -> Result<Self>
Creates a TestServer
running your app on the address given.
Sourcepub async fn get(&self, path: &str) -> TestResponse
pub async fn get(&self, path: &str) -> TestResponse
Performs a GET request to the path.
This will presume the response is successful (a 200 status code). If a different status code is returned, then this will panic.
Sourcepub async fn get_fail(&self, path: &str) -> TestResponse
pub async fn get_fail(&self, path: &str) -> TestResponse
Performs a GET request to the path.
This will panic if the response is successful. It presumes the response would have failed.
Sourcepub async fn post(&self, path: &str, body: &str) -> TestResponse
pub async fn post(&self, path: &str, body: &str) -> TestResponse
Performs a POST request to the path.
This will presume the response is successful (a 200 status code). If a different status code is returned, then this will panic.
Sourcepub async fn post_fail(&self, path: &str, body: &str) -> TestResponse
pub async fn post_fail(&self, path: &str, body: &str) -> TestResponse
Performs a POST request to the path.
This will panic if the response is successful. It presumes the response would have failed.
Sourcepub async fn patch(&self, path: &str, body: &str) -> TestResponse
pub async fn patch(&self, path: &str, body: &str) -> TestResponse
Performs a PATCH request to the path.
This will panic if the response is successful. It presumes the response would have failed.
Sourcepub async fn patch_fail(&self, path: &str, body: &str) -> TestResponse
pub async fn patch_fail(&self, path: &str, body: &str) -> TestResponse
Performs a PATCH request to the path.
This will panic if the response is successful. It presumes the response would have failed.
Sourcepub async fn put(&self, path: &str, body: &str) -> TestResponse
pub async fn put(&self, path: &str, body: &str) -> TestResponse
Performs a PUT request to the path.
This will presume the response is successful (a 200 status code). If a different status code is returned, then this will panic.
Sourcepub async fn put_fail(&self, path: &str, body: &str) -> TestResponse
pub async fn put_fail(&self, path: &str, body: &str) -> TestResponse
Performs a PUT request to the path.
This will panic if the response is successful. It presumes the response would have failed.
Sourcepub async fn delete(&self, path: &str) -> TestResponse
pub async fn delete(&self, path: &str) -> TestResponse
Performs a DELETE request to the path.
This will presume the response is successful (a 200 status code). If a different status code is returned, then this will panic.
Sourcepub async fn delete_fail(&self, path: &str) -> TestResponse
pub async fn delete_fail(&self, path: &str) -> TestResponse
Performs a DELETE request to the path.
This will panic if the response is successful. It presumes the response would have failed.