rs_express/
testing.rs

1use crate::common::{collect_error_middleware, collect_middleware};
2use crate::core::run;
3use crate::App;
4use hyper::Body;
5
6pub struct TestApp<T> {
7    app: App<T>,
8}
9
10impl<T> TestApp<T> {
11    /// Receives an hyper Request, mimics the behavior of the App and returns an hyper Response.
12    pub async fn request(&mut self, _req: hyper::Request<Body>) -> hyper::Response<Body> {
13        let middleware = collect_middleware(&mut self.app);
14        let error_middleware = collect_error_middleware(&mut self.app);
15
16        run(_req, &middleware, &error_middleware, &self.app.locals).await
17    }
18}
19
20/// Returns a test-app
21pub fn testing<T>(app: App<T>) -> TestApp<T> {
22    TestApp { app }
23}