1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-22 09:31:10 +00:00

refactor: remove web dev dep from http-test

This commit is contained in:
Rob Ede 2023-07-22 01:57:44 +01:00
parent 146011018e
commit 8cdbab3416
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
2 changed files with 11 additions and 15 deletions

View file

@ -50,5 +50,4 @@ tls-openssl = { version = "0.10.55", package = "openssl", optional = true }
tokio = { version = "1.24.2", features = ["sync"] }
[dev-dependencies]
actix-web = { version = "4", default-features = false, features = ["cookies"] }
actix-http = "3"

View file

@ -31,24 +31,20 @@ use tokio::sync::mpsc;
/// for HTTP applications.
///
/// # Examples
/// ```no_run
/// use actix_http::HttpService;
///
/// ```
/// use actix_http::{HttpService, Response, Error, StatusCode};
/// use actix_http_test::test_server;
/// use actix_service::map_config;
/// use actix_service::ServiceFactoryExt;
/// use actix_web::{dev::AppConfig, web, App, Error, HttpResponse};
/// use actix_service::{fn_service, map_config, ServiceFactoryExt as _};
///
/// async fn my_handler() -> Result<HttpResponse, Error> {
/// Ok(HttpResponse::Ok().into())
/// }
///
/// #[actix_web::test]
/// #[actix_rt::test]
/// # async fn hidden_test() {}
/// async fn test_example() {
/// let srv = test_server(|| {
/// let app = App::new().service(web::resource("/").to(my_handler));
///
/// HttpService::build()
/// .h1(map_config(app, |_| AppConfig::default()))
/// .h1(fn_service(|req| async move {
/// Ok::<_, Error>(Response::ok())
/// }))
/// .tcp()
/// .map_err(|_| ())
/// })
@ -57,8 +53,9 @@ use tokio::sync::mpsc;
/// let req = srv.get("/");
/// 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 {
let tcp = net::TcpListener::bind("127.0.0.1:0").unwrap();