Function actix_web::test::init_service

source ·
pub async fn init_service<R, S, B, E>(
    app: R
) -> impl Service<Request, Response = ServiceResponse<B>, Error = E>
where R: IntoServiceFactory<S, Request>, S: ServiceFactory<Request, Config = AppConfig, Response = ServiceResponse<B>, Error = E>, S::InitError: Debug,
Expand description

Initialize service from application builder instance.

§Examples

use actix_service::Service;
use actix_web::{test, web, App, HttpResponse, http::StatusCode};

#[actix_web::test]
async fn test_init_service() {
    let app = test::init_service(
        App::new()
            .service(web::resource("/test").to(|| async { "OK" }))
    ).await;

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

    // Execute application
    let res = app.call(req).await.unwrap();
    assert_eq!(res.status(), StatusCode::OK);
}

§Panics

Panics if service initialization returns an error.