mirror of
https://github.com/actix/actix-web.git
synced 2024-11-25 11:01:14 +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
|
/// ```no_run
|
||||||
/// use actix_http::HttpService;
|
/// use actix_http::HttpService;
|
||||||
/// use actix_http_test::test_server;
|
/// 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> {
|
/// async fn my_handler() -> Result<HttpResponse, Error> {
|
||||||
/// Ok(HttpResponse::Ok().into())
|
/// Ok(HttpResponse::Ok().into())
|
||||||
|
@ -42,14 +44,19 @@ use tokio::sync::mpsc;
|
||||||
///
|
///
|
||||||
/// #[actix_web::test]
|
/// #[actix_web::test]
|
||||||
/// async fn test_example() {
|
/// async fn test_example() {
|
||||||
/// let mut srv = TestServer::start(||
|
/// let srv = test_server(|| {
|
||||||
/// HttpService::new(
|
/// let app = App::new().service(web::resource("/").to(my_handler));
|
||||||
/// 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 req = srv.get("/");
|
||||||
/// let response = req.send().await.unwrap();
|
/// let response = req.send().await.unwrap();
|
||||||
|
///
|
||||||
/// assert!(response.status().is_success());
|
/// assert!(response.status().is_success());
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
|
|
Loading…
Reference in a new issue