mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 09:31:10 +00:00
docs(actix-http-test): update test server example (#3007)
This commit is contained in:
parent
e68f87f84f
commit
8dee8a1426
1 changed files with 13 additions and 6 deletions
|
@ -34,7 +34,9 @@ use tokio::sync::mpsc;
|
|||
/// ```no_run
|
||||
/// use actix_http::HttpService;
|
||||
/// use actix_http_test::test_server;
|
||||
/// use actix_web::{web, App, HttpResponse, Error};
|
||||
/// use actix_service::map_config;
|
||||
/// use actix_service::ServiceFactoryExt;
|
||||
/// use actix_web::{dev::AppConfig, web, App, Error, HttpResponse};
|
||||
///
|
||||
/// async fn my_handler() -> Result<HttpResponse, Error> {
|
||||
/// Ok(HttpResponse::Ok().into())
|
||||
|
@ -42,14 +44,19 @@ use tokio::sync::mpsc;
|
|||
///
|
||||
/// #[actix_web::test]
|
||||
/// async fn test_example() {
|
||||
/// let mut srv = TestServer::start(||
|
||||
/// HttpService::new(
|
||||
/// App::new().service(web::resource("/").to(my_handler))
|
||||
/// )
|
||||
/// );
|
||||
/// let srv = test_server(|| {
|
||||
/// let app = App::new().service(web::resource("/").to(my_handler));
|
||||
///
|
||||
/// HttpService::build()
|
||||
/// .h1(map_config(app, |_| AppConfig::default()))
|
||||
/// .tcp()
|
||||
/// .map_err(|_| ())
|
||||
/// })
|
||||
/// .await;
|
||||
///
|
||||
/// let req = srv.get("/");
|
||||
/// let response = req.send().await.unwrap();
|
||||
///
|
||||
/// assert!(response.status().is_success());
|
||||
/// }
|
||||
/// ```
|
||||
|
|
Loading…
Reference in a new issue