Struct axum_test::TestServer
source · pub struct TestServer { /* private fields */ }Expand description
The TestServer represents your application, running as a web server,
and you can make web requests to your application.
For most people’s needs, this is where to start when writing a test. This allows you Allowing you to create new requests that will go to this server.
You can make a request against the TestServer by calling the
get, post, put, delete, and patch methods (you can also use method).
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 use a randomly selected port for running.
This is the same as creating a new TestServer with a configuration,
and passing TestServerConfig::default().
sourcepub fn new_with_config(
app: IntoMakeService<Router>,
options: TestServerConfig
) -> Result<Self>
pub fn new_with_config( app: IntoMakeService<Router>, options: TestServerConfig ) -> Result<Self>
This very similar to TestServer::new(),
however you can customise some of the configuration.
This includes which port to run on, or default settings.
See the TestServerConfig for more information on each configuration setting.
Clears all of the cookies stored internally.
Adds extra cookies to be used on all future requests.
Any cookies which have the same name as the new cookies, will get replaced.
Adds a cookie to be included on all future requests.
If a cookie with the same name already exists, then it will be replaced.
sourcepub fn get(&self, path: &str) -> TestRequest
pub fn get(&self, path: &str) -> TestRequest
Creates a HTTP GET request to the path.
sourcepub fn post(&self, path: &str) -> TestRequest
pub fn post(&self, path: &str) -> TestRequest
Creates a HTTP POST request to the given path.
sourcepub fn patch(&self, path: &str) -> TestRequest
pub fn patch(&self, path: &str) -> TestRequest
Creates a HTTP PATCH request to the path.
sourcepub fn put(&self, path: &str) -> TestRequest
pub fn put(&self, path: &str) -> TestRequest
Creates a HTTP PUT request to the path.
sourcepub fn delete(&self, path: &str) -> TestRequest
pub fn delete(&self, path: &str) -> TestRequest
Creates a HTTP 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 HTTP request, to the path given, using the given method.