Struct axum_test_server::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>) -> 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.