[][src]Function ntex::web::test::call_service

pub async fn call_service<'_, S, R, E>(app: &'_ S, req: R) -> S::Response where
    S: Service<Request = R, Response = WebResponse, Error = E>,
    E: Debug

Calls service and waits for response future completion.

use ntex::http::StatusCode;
use ntex::web::{self, test, App, HttpResponse};

#[ntex::test]
async fn test_response() {
    let mut app = test::init_service(
        App::new()
            .service(web::resource("/test").to(|| async {
                HttpResponse::Ok()
            }))
    ).await;

    // Create request object
    let req = test::TestRequest::with_uri("/test").to_request();

    // Call application
    let resp = test::call_service(&mut app, req).await;
    assert_eq!(resp.status(), StatusCode::OK);
}