Skip to main content

server_with_config

Function server_with_config 

Source
pub fn server_with_config<F, S, I>(
    f: F,
    cfg: impl Into<SharedCfg>,
) -> TestServer
where F: AsyncFn(&()) -> I + Send + Clone + 'static, S: Service<(), Io> + 'static, I: IntoService<S, (), Io> + 'static,
Expand description

Start test server with custom configuration

Same as server(), but the server uses the provided shared configuration.

ยงExamples

use ntex::http::{self, Method, Response};
use ntex::{SharedCfg, io::IoConfig, time::Seconds};

#[ntex::test]
async fn test_example() {
    let srv = http::test::server_with_config(
        async |_| {
            http::HttpService::h1(async |_| {
                Ok::<_, std::io::Error>(Response::Ok().build())
            })
        },
        SharedCfg::new("TEST-SRV")
            .add(IoConfig::new().set_shutdown_timeout(Seconds(1))),
    );

    let req = srv.request(Method::GET, "/");
    let response = req.send().await.unwrap();
    assert!(response.status().is_success());
}