mirror of
https://github.com/actix/actix-web.git
synced 2024-11-22 17:41:11 +00:00
refactor: remove web dev dep from http-test
This commit is contained in:
parent
146011018e
commit
8cdbab3416
2 changed files with 11 additions and 15 deletions
|
@ -50,5 +50,4 @@ tls-openssl = { version = "0.10.55", package = "openssl", optional = true }
|
||||||
tokio = { version = "1.24.2", features = ["sync"] }
|
tokio = { version = "1.24.2", features = ["sync"] }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-web = { version = "4", default-features = false, features = ["cookies"] }
|
|
||||||
actix-http = "3"
|
actix-http = "3"
|
||||||
|
|
|
@ -31,24 +31,20 @@ use tokio::sync::mpsc;
|
||||||
/// for HTTP applications.
|
/// for HTTP applications.
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```no_run
|
///
|
||||||
/// use actix_http::HttpService;
|
/// ```
|
||||||
|
/// use actix_http::{HttpService, Response, Error, StatusCode};
|
||||||
/// use actix_http_test::test_server;
|
/// use actix_http_test::test_server;
|
||||||
/// use actix_service::map_config;
|
/// use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
|
||||||
/// use actix_service::ServiceFactoryExt;
|
|
||||||
/// use actix_web::{dev::AppConfig, web, App, Error, HttpResponse};
|
|
||||||
///
|
///
|
||||||
/// async fn my_handler() -> Result<HttpResponse, Error> {
|
/// #[actix_rt::test]
|
||||||
/// Ok(HttpResponse::Ok().into())
|
/// # async fn hidden_test() {}
|
||||||
/// }
|
|
||||||
///
|
|
||||||
/// #[actix_web::test]
|
|
||||||
/// async fn test_example() {
|
/// async fn test_example() {
|
||||||
/// let srv = test_server(|| {
|
/// let srv = test_server(|| {
|
||||||
/// let app = App::new().service(web::resource("/").to(my_handler));
|
|
||||||
///
|
|
||||||
/// HttpService::build()
|
/// HttpService::build()
|
||||||
/// .h1(map_config(app, |_| AppConfig::default()))
|
/// .h1(fn_service(|req| async move {
|
||||||
|
/// Ok::<_, Error>(Response::ok())
|
||||||
|
/// }))
|
||||||
/// .tcp()
|
/// .tcp()
|
||||||
/// .map_err(|_| ())
|
/// .map_err(|_| ())
|
||||||
/// })
|
/// })
|
||||||
|
@ -57,8 +53,9 @@ use tokio::sync::mpsc;
|
||||||
/// 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_eq!(response.status(), StatusCode::OK);
|
||||||
/// }
|
/// }
|
||||||
|
/// # actix_rt::System::new().block_on(test_example());
|
||||||
/// ```
|
/// ```
|
||||||
pub async fn test_server<F: ServerServiceFactory<TcpStream>>(factory: F) -> TestServer {
|
pub async fn test_server<F: ServerServiceFactory<TcpStream>>(factory: F) -> TestServer {
|
||||||
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();
|
||||||
|
|
Loading…
Reference in a new issue