mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-26 15:07:42 +02:00
revive commented out tests (#1912)
This commit is contained in:
@ -9,17 +9,20 @@ use bytes::Bytes;
|
||||
use flate2::read::GzDecoder;
|
||||
use flate2::write::GzEncoder;
|
||||
use flate2::Compression;
|
||||
use futures_util::future::ok;
|
||||
use futures_util::{future::ok, stream};
|
||||
use rand::Rng;
|
||||
|
||||
use actix_http::HttpService;
|
||||
use actix_http::{
|
||||
http::{self, StatusCode},
|
||||
HttpService,
|
||||
};
|
||||
use actix_http_test::test_server;
|
||||
use actix_service::{map_config, pipeline_factory};
|
||||
use actix_web::dev::{AppConfig, BodyEncoding};
|
||||
use actix_web::http::Cookie;
|
||||
use actix_web::middleware::Compress;
|
||||
use actix_web::{
|
||||
http::header, test, web, App, Error, HttpMessage, HttpRequest, HttpResponse,
|
||||
dev::{AppConfig, BodyEncoding},
|
||||
http::{header, Cookie},
|
||||
middleware::Compress,
|
||||
test, web, App, Error, HttpMessage, HttpRequest, HttpResponse,
|
||||
};
|
||||
use awc::error::SendRequestError;
|
||||
|
||||
@ -557,117 +560,94 @@ async fn test_client_brotli_encoding_large_random() {
|
||||
assert_eq!(bytes, Bytes::from(data));
|
||||
}
|
||||
|
||||
// TODO: why is test ignored
|
||||
// #[actix_rt::test]
|
||||
// async fn test_client_deflate_encoding() {
|
||||
// let srv = test::TestServer::start(|app| {
|
||||
// app.handler(|req: &HttpRequest| {
|
||||
// req.body()
|
||||
// .and_then(|bytes: Bytes| {
|
||||
// Ok(HttpResponse::Ok()
|
||||
// .content_encoding(http::ContentEncoding::Br)
|
||||
// .body(bytes))
|
||||
// })
|
||||
// .responder()
|
||||
// })
|
||||
// });
|
||||
#[actix_rt::test]
|
||||
async fn test_client_deflate_encoding() {
|
||||
let srv = test::start(|| {
|
||||
App::new().default_service(web::to(|body: Bytes| {
|
||||
HttpResponse::Ok()
|
||||
.encoding(http::ContentEncoding::Br)
|
||||
.body(body)
|
||||
}))
|
||||
});
|
||||
|
||||
// // client request
|
||||
// let request = srv
|
||||
// .post()
|
||||
// .content_encoding(http::ContentEncoding::Deflate)
|
||||
// .body(STR)
|
||||
// .unwrap();
|
||||
// let response = srv.execute(request.send()).unwrap();
|
||||
// assert!(response.status().is_success());
|
||||
let req = srv.post("/").send_body(STR);
|
||||
|
||||
// // read response
|
||||
// let bytes = srv.execute(response.body()).unwrap();
|
||||
// assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
// }
|
||||
let mut res = req.await.unwrap();
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
|
||||
// TODO: why is test ignored
|
||||
// #[actix_rt::test]
|
||||
// async fn test_client_deflate_encoding_large_random() {
|
||||
// let data = rand::thread_rng()
|
||||
// .sample_iter(&rand::distributions::Alphanumeric)
|
||||
// .take(70_000)
|
||||
// .collect::<String>();
|
||||
let bytes = res.body().await.unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
// let srv = test::TestServer::start(|app| {
|
||||
// app.handler(|req: &HttpRequest| {
|
||||
// req.body()
|
||||
// .and_then(|bytes: Bytes| {
|
||||
// Ok(HttpResponse::Ok()
|
||||
// .content_encoding(http::ContentEncoding::Br)
|
||||
// .body(bytes))
|
||||
// })
|
||||
// .responder()
|
||||
// })
|
||||
// });
|
||||
#[actix_rt::test]
|
||||
async fn test_client_deflate_encoding_large_random() {
|
||||
let data = rand::thread_rng()
|
||||
.sample_iter(rand::distributions::Alphanumeric)
|
||||
.map(char::from)
|
||||
.take(70_000)
|
||||
.collect::<String>();
|
||||
|
||||
// // client request
|
||||
// let request = srv
|
||||
// .post()
|
||||
// .content_encoding(http::ContentEncoding::Deflate)
|
||||
// .body(data.clone())
|
||||
// .unwrap();
|
||||
// let response = srv.execute(request.send()).unwrap();
|
||||
// assert!(response.status().is_success());
|
||||
let srv = test::start(|| {
|
||||
App::new().default_service(web::to(|body: Bytes| {
|
||||
HttpResponse::Ok()
|
||||
.encoding(http::ContentEncoding::Br)
|
||||
.body(body)
|
||||
}))
|
||||
});
|
||||
|
||||
// // read response
|
||||
// let bytes = srv.execute(response.body()).unwrap();
|
||||
// assert_eq!(bytes, Bytes::from(data));
|
||||
// }
|
||||
let req = srv.post("/").send_body(data.clone());
|
||||
|
||||
// TODO: why is test ignored
|
||||
// #[actix_rt::test]
|
||||
// async fn test_client_streaming_explicit() {
|
||||
// let srv = test::TestServer::start(|app| {
|
||||
// app.handler(|req: &HttpRequest| {
|
||||
// req.body()
|
||||
// .map_err(Error::from)
|
||||
// .and_then(|body| {
|
||||
// Ok(HttpResponse::Ok()
|
||||
// .chunked()
|
||||
// .content_encoding(http::ContentEncoding::Identity)
|
||||
// .body(body))
|
||||
// })
|
||||
// .responder()
|
||||
// })
|
||||
// });
|
||||
let mut res = req.await.unwrap();
|
||||
let bytes = res.body().await.unwrap();
|
||||
|
||||
// let body = once(Ok(Bytes::from_static(STR.as_ref())));
|
||||
assert_eq!(res.status(), StatusCode::OK);
|
||||
assert_eq!(bytes, Bytes::from(data));
|
||||
}
|
||||
|
||||
// let request = srv.get("/").body(Body::Streaming(Box::new(body))).unwrap();
|
||||
// let response = srv.execute(request.send()).unwrap();
|
||||
// assert!(response.status().is_success());
|
||||
#[actix_rt::test]
|
||||
async fn test_client_streaming_explicit() {
|
||||
let srv = test::start(|| {
|
||||
App::new().default_service(web::to(|body: web::Payload| {
|
||||
HttpResponse::Ok()
|
||||
.encoding(http::ContentEncoding::Identity)
|
||||
.streaming(body)
|
||||
}))
|
||||
});
|
||||
|
||||
// // read response
|
||||
// let bytes = srv.execute(response.body()).unwrap();
|
||||
// assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
// }
|
||||
let body = stream::once(async {
|
||||
Ok::<_, actix_http::Error>(Bytes::from_static(STR.as_bytes()))
|
||||
});
|
||||
let req = srv.post("/").send_stream(Box::pin(body));
|
||||
|
||||
// TODO: why is test ignored
|
||||
// #[actix_rt::test]
|
||||
// async fn test_body_streaming_implicit() {
|
||||
// let srv = test::TestServer::start(|app| {
|
||||
// app.handler(|_| {
|
||||
// let body = once(Ok(Bytes::from_static(STR.as_ref())));
|
||||
// HttpResponse::Ok()
|
||||
// .content_encoding(http::ContentEncoding::Gzip)
|
||||
// .body(Body::Streaming(Box::new(body)))
|
||||
// })
|
||||
// });
|
||||
let mut res = req.await.unwrap();
|
||||
assert!(res.status().is_success());
|
||||
|
||||
// let request = srv.get("/").finish().unwrap();
|
||||
// let response = srv.execute(request.send()).unwrap();
|
||||
// assert!(response.status().is_success());
|
||||
let bytes = res.body().await.unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
// // read response
|
||||
// let bytes = srv.execute(response.body()).unwrap();
|
||||
// assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
// }
|
||||
#[actix_rt::test]
|
||||
async fn test_body_streaming_implicit() {
|
||||
let srv = test::start(|| {
|
||||
App::new().default_service(web::to(|| {
|
||||
let body = stream::once(async {
|
||||
Ok::<_, actix_http::Error>(Bytes::from_static(STR.as_bytes()))
|
||||
});
|
||||
|
||||
HttpResponse::Ok()
|
||||
.encoding(http::ContentEncoding::Gzip)
|
||||
.streaming(Box::pin(body))
|
||||
}))
|
||||
});
|
||||
|
||||
let req = srv.get("/").send();
|
||||
|
||||
let mut res = req.await.unwrap();
|
||||
assert!(res.status().is_success());
|
||||
|
||||
let bytes = res.body().await.unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn test_client_cookie_handling() {
|
||||
@ -738,36 +718,35 @@ async fn test_client_cookie_handling() {
|
||||
assert_eq!(c2, cookie2);
|
||||
}
|
||||
|
||||
// TODO: why is test ignored
|
||||
// #[actix_rt::test]
|
||||
// fn client_read_until_eof() {
|
||||
// let addr = test::TestServer::unused_addr();
|
||||
#[actix_rt::test]
|
||||
async fn client_unread_response() {
|
||||
let addr = test::unused_addr();
|
||||
|
||||
// thread::spawn(move || {
|
||||
// let lst = net::TcpListener::bind(addr).unwrap();
|
||||
std::thread::spawn(move || {
|
||||
let lst = std::net::TcpListener::bind(addr).unwrap();
|
||||
|
||||
// for stream in lst.incoming() {
|
||||
// let mut stream = stream.unwrap();
|
||||
// let mut b = [0; 1000];
|
||||
// let _ = stream.read(&mut b).unwrap();
|
||||
// let _ = stream
|
||||
// .write_all(b"HTTP/1.1 200 OK\r\nconnection: close\r\n\r\nwelcome!");
|
||||
// }
|
||||
// });
|
||||
for stream in lst.incoming() {
|
||||
let mut stream = stream.unwrap();
|
||||
let mut b = [0; 1000];
|
||||
let _ = stream.read(&mut b).unwrap();
|
||||
let _ = stream.write_all(
|
||||
b"HTTP/1.1 200 OK\r\n\
|
||||
connection: close\r\n\
|
||||
\r\n\
|
||||
welcome!",
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// let mut sys = actix::System::new("test");
|
||||
// client request
|
||||
let req = awc::Client::new().get(format!("http://{}/", addr).as_str());
|
||||
let mut res = req.send().await.unwrap();
|
||||
assert!(res.status().is_success());
|
||||
|
||||
// // client request
|
||||
// let req = client::ClientRequest::get(format!("http://{}/", addr).as_str())
|
||||
// .finish()
|
||||
// .unwrap();
|
||||
// let response = req.send().await.unwrap();
|
||||
// assert!(response.status().is_success());
|
||||
|
||||
// // read response
|
||||
// let bytes = response.body().await.unwrap();
|
||||
// assert_eq!(bytes, Bytes::from_static(b"welcome!"));
|
||||
// }
|
||||
// awc does not read all bytes unless content-length is specified
|
||||
let bytes = res.body().await.unwrap();
|
||||
assert_eq!(bytes, Bytes::from_static(b""));
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn client_basic_auth() {
|
||||
|
Reference in New Issue
Block a user