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_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 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.