1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-11 01:39:33 +00:00

simplify macros feature

This commit is contained in:
Rob Ede 2022-02-01 14:15:30 +00:00
parent e9279dfbb8
commit c84c1f0f15
No known key found for this signature in database
GPG key ID: 97C636207D3EF933
5 changed files with 58 additions and 59 deletions

View file

@ -66,7 +66,7 @@ fn tls_config() -> SslAcceptor {
}
#[actix_rt::test]
async fn test_h2() -> io::Result<()> {
async fn h2() -> io::Result<()> {
let srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Error>(Response::ok()))
@ -81,7 +81,7 @@ async fn test_h2() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2_1() -> io::Result<()> {
async fn h2_1() -> io::Result<()> {
let srv = test_server(move || {
HttpService::build()
.finish(|req: Request| {
@ -100,7 +100,7 @@ async fn test_h2_1() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2_body() -> io::Result<()> {
async fn h2_body() -> io::Result<()> {
let data = "HELLOWORLD".to_owned().repeat(64 * 1024); // 640 KiB
let mut srv = test_server(move || {
HttpService::build()
@ -122,7 +122,7 @@ async fn test_h2_body() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2_content_length() {
async fn h2_content_length() {
let srv = test_server(move || {
HttpService::build()
.h2(|req: Request| {
@ -164,7 +164,7 @@ async fn test_h2_content_length() {
}
#[actix_rt::test]
async fn test_h2_headers() {
async fn h2_headers() {
let data = STR.repeat(10);
let data2 = data.clone();
@ -229,7 +229,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World";
#[actix_rt::test]
async fn test_h2_body2() {
async fn h2_body2() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -247,7 +247,7 @@ async fn test_h2_body2() {
}
#[actix_rt::test]
async fn test_h2_head_empty() {
async fn h2_head_empty() {
let mut srv = test_server(move || {
HttpService::build()
.finish(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -271,7 +271,7 @@ async fn test_h2_head_empty() {
}
#[actix_rt::test]
async fn test_h2_head_binary() {
async fn h2_head_binary() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -294,7 +294,7 @@ async fn test_h2_head_binary() {
}
#[actix_rt::test]
async fn test_h2_head_binary2() {
async fn h2_head_binary2() {
let srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -313,7 +313,7 @@ async fn test_h2_head_binary2() {
}
#[actix_rt::test]
async fn test_h2_body_length() {
async fn h2_body_length() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| async {
@ -338,7 +338,7 @@ async fn test_h2_body_length() {
}
#[actix_rt::test]
async fn test_h2_body_chunked_explicit() {
async fn h2_body_chunked_explicit() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
@ -366,7 +366,7 @@ async fn test_h2_body_chunked_explicit() {
}
#[actix_rt::test]
async fn test_h2_response_http_error_handling() {
async fn h2_response_http_error_handling() {
let mut srv = test_server(move || {
HttpService::build()
.h2(fn_service(|_| {
@ -406,7 +406,7 @@ impl From<BadRequest> for Response<BoxBody> {
}
#[actix_rt::test]
async fn test_h2_service_error() {
async fn h2_service_error() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| err::<Response<BoxBody>, _>(BadRequest))
@ -424,7 +424,7 @@ async fn test_h2_service_error() {
}
#[actix_rt::test]
async fn test_h2_on_connect() {
async fn h2_on_connect() {
let srv = test_server(move || {
HttpService::build()
.on_connect_ext(|_, data| {

View file

@ -106,7 +106,7 @@ pub fn get_negotiated_alpn_protocol(
}
#[actix_rt::test]
async fn test_h1() -> io::Result<()> {
async fn h1() -> io::Result<()> {
let srv = test_server(move || {
HttpService::build()
.h1(|_| ok::<_, Error>(Response::ok()))
@ -120,7 +120,7 @@ async fn test_h1() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2() -> io::Result<()> {
async fn h2() -> io::Result<()> {
let srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Error>(Response::ok()))
@ -134,7 +134,7 @@ async fn test_h2() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h1_1() -> io::Result<()> {
async fn h1_1() -> io::Result<()> {
let srv = test_server(move || {
HttpService::build()
.h1(|req: Request| {
@ -152,7 +152,7 @@ async fn test_h1_1() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2_1() -> io::Result<()> {
async fn h2_1() -> io::Result<()> {
let srv = test_server(move || {
HttpService::build()
.finish(|req: Request| {
@ -170,7 +170,7 @@ async fn test_h2_1() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2_body1() -> io::Result<()> {
async fn h2_body1() -> io::Result<()> {
let data = "HELLOWORLD".to_owned().repeat(64 * 1024);
let mut srv = test_server(move || {
HttpService::build()
@ -191,7 +191,7 @@ async fn test_h2_body1() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_h2_content_length() {
async fn h2_content_length() {
let srv = test_server(move || {
HttpService::build()
.h2(|req: Request| {
@ -245,7 +245,7 @@ async fn test_h2_content_length() {
}
#[actix_rt::test]
async fn test_h2_headers() {
async fn h2_headers() {
let data = STR.repeat(10);
let data2 = data.clone();
@ -309,7 +309,7 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
Hello World Hello World Hello World Hello World Hello World";
#[actix_rt::test]
async fn test_h2_body2() {
async fn h2_body2() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -326,7 +326,7 @@ async fn test_h2_body2() {
}
#[actix_rt::test]
async fn test_h2_head_empty() {
async fn h2_head_empty() {
let mut srv = test_server(move || {
HttpService::build()
.finish(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -352,7 +352,7 @@ async fn test_h2_head_empty() {
}
#[actix_rt::test]
async fn test_h2_head_binary() {
async fn h2_head_binary() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -377,7 +377,7 @@ async fn test_h2_head_binary() {
}
#[actix_rt::test]
async fn test_h2_head_binary2() {
async fn h2_head_binary2() {
let srv = test_server(move || {
HttpService::build()
.h2(|_| ok::<_, Infallible>(Response::ok().set_body(STR)))
@ -398,7 +398,7 @@ async fn test_h2_head_binary2() {
}
#[actix_rt::test]
async fn test_h2_body_length() {
async fn h2_body_length() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
@ -420,7 +420,7 @@ async fn test_h2_body_length() {
}
#[actix_rt::test]
async fn test_h2_body_chunked_explicit() {
async fn h2_body_chunked_explicit() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| {
@ -447,7 +447,7 @@ async fn test_h2_body_chunked_explicit() {
}
#[actix_rt::test]
async fn test_h2_response_http_error_handling() {
async fn h2_response_http_error_handling() {
let mut srv = test_server(move || {
HttpService::build()
.h2(fn_factory_with_config(|_: ()| {
@ -486,7 +486,7 @@ impl From<BadRequest> for Response<BoxBody> {
}
#[actix_rt::test]
async fn test_h2_service_error() {
async fn h2_service_error() {
let mut srv = test_server(move || {
HttpService::build()
.h2(|_| err::<Response<BoxBody>, _>(BadRequest))
@ -503,7 +503,7 @@ async fn test_h2_service_error() {
}
#[actix_rt::test]
async fn test_h1_service_error() {
async fn h1_service_error() {
let mut srv = test_server(move || {
HttpService::build()
.h1(|_| err::<Response<BoxBody>, _>(BadRequest))
@ -524,7 +524,7 @@ const HTTP1_1_ALPN_PROTOCOL: &[u8] = b"http/1.1";
const CUSTOM_ALPN_PROTOCOL: &[u8] = b"custom";
#[actix_rt::test]
async fn test_alpn_h1() -> io::Result<()> {
async fn alpn_h1() -> io::Result<()> {
let srv = test_server(move || {
let mut config = tls_config();
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
@ -546,7 +546,7 @@ async fn test_alpn_h1() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_alpn_h2() -> io::Result<()> {
async fn alpn_h2() -> io::Result<()> {
let srv = test_server(move || {
let mut config = tls_config();
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());
@ -572,7 +572,7 @@ async fn test_alpn_h2() -> io::Result<()> {
}
#[actix_rt::test]
async fn test_alpn_h2_1() -> io::Result<()> {
async fn alpn_h2_1() -> io::Result<()> {
let srv = test_server(move || {
let mut config = tls_config();
config.alpn_protocols.push(CUSTOM_ALPN_PROTOCOL.to_vec());

View file

@ -39,7 +39,6 @@ compress-zstd = ["actix-http/compress-zstd", "__compress"]
# Routing and runtime proc macros
macros = [
"actix-rt/macros",
"actix-macros",
"actix-web-codegen",
]

View file

@ -35,4 +35,4 @@ pub use actix_rt::{net, pin, signal, spawn, task, time, Runtime, System, SystemR
#[cfg(feature = "macros")]
#[doc(hidden)]
pub use actix_rt::{main, test};
pub use actix_macros::{main, test};

View file

@ -28,7 +28,7 @@ const S: &str = "Hello World ";
const STR: &str = const_str::repeat!(S, 100);
#[actix_rt::test]
async fn test_simple() {
async fn simple() {
let srv = actix_test::start(|| {
App::new().service(
web::resource("/").route(web::to(|| async { HttpResponse::Ok().body(STR) })),
@ -56,7 +56,7 @@ async fn test_simple() {
}
#[actix_rt::test]
async fn test_json() {
async fn json() {
let srv = actix_test::start(|| {
App::new().service(
web::resource("/").route(web::to(|_: web::Json<String>| HttpResponse::Ok())),
@ -72,7 +72,7 @@ async fn test_json() {
}
#[actix_rt::test]
async fn test_form() {
async fn form() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(
|_: web::Form<HashMap<String, String>>| HttpResponse::Ok(),
@ -91,7 +91,7 @@ async fn test_form() {
}
#[actix_rt::test]
async fn test_timeout() {
async fn timeout() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| async {
actix_rt::time::sleep(Duration::from_millis(200)).await;
@ -116,7 +116,7 @@ async fn test_timeout() {
}
#[actix_rt::test]
async fn test_timeout_override() {
async fn timeout_override() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| async {
actix_rt::time::sleep(Duration::from_millis(200)).await;
@ -138,7 +138,7 @@ async fn test_timeout_override() {
}
#[actix_rt::test]
async fn test_response_timeout() {
async fn response_timeout() {
use futures_util::stream::{once, StreamExt as _};
let srv = actix_test::start(|| {
@ -211,7 +211,7 @@ async fn test_response_timeout() {
}
#[actix_rt::test]
async fn test_connection_reuse() {
async fn connection_reuse() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();
@ -248,7 +248,7 @@ async fn test_connection_reuse() {
}
#[actix_rt::test]
async fn test_connection_force_close() {
async fn connection_force_close() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();
@ -285,7 +285,7 @@ async fn test_connection_force_close() {
}
#[actix_rt::test]
async fn test_connection_server_close() {
async fn connection_server_close() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();
@ -324,7 +324,7 @@ async fn test_connection_server_close() {
}
#[actix_rt::test]
async fn test_connection_wait_queue() {
async fn connection_wait_queue() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();
@ -373,7 +373,7 @@ async fn test_connection_wait_queue() {
}
#[actix_rt::test]
async fn test_connection_wait_queue_force_close() {
async fn connection_wait_queue_force_close() {
let num = Arc::new(AtomicUsize::new(0));
let num2 = num.clone();
@ -421,7 +421,7 @@ async fn test_connection_wait_queue_force_close() {
}
#[actix_rt::test]
async fn test_with_query_parameter() {
async fn with_query_parameter() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").to(|req: HttpRequest| {
if req.query_string().contains("qp") {
@ -442,7 +442,7 @@ async fn test_with_query_parameter() {
#[cfg(feature = "compress-gzip")]
#[actix_rt::test]
async fn test_no_decompress() {
async fn no_decompress() {
let srv = actix_test::start(|| {
App::new()
.wrap(actix_web::middleware::Compress::default())
@ -480,7 +480,7 @@ async fn test_no_decompress() {
#[cfg(feature = "compress-gzip")]
#[actix_rt::test]
async fn test_client_gzip_encoding() {
async fn client_gzip_encoding() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| async {
HttpResponse::Ok()
@ -500,7 +500,7 @@ async fn test_client_gzip_encoding() {
#[cfg(feature = "compress-gzip")]
#[actix_rt::test]
async fn test_client_gzip_encoding_large() {
async fn client_gzip_encoding_large() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|| async {
HttpResponse::Ok()
@ -520,7 +520,7 @@ async fn test_client_gzip_encoding_large() {
#[cfg(feature = "compress-gzip")]
#[actix_rt::test]
async fn test_client_gzip_encoding_large_random() {
async fn client_gzip_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(100_000)
@ -546,7 +546,7 @@ async fn test_client_gzip_encoding_large_random() {
#[cfg(feature = "compress-brotli")]
#[actix_rt::test]
async fn test_client_brotli_encoding() {
async fn client_brotli_encoding() {
let srv = actix_test::start(|| {
App::new().service(web::resource("/").route(web::to(|data: Bytes| async {
HttpResponse::Ok()
@ -566,7 +566,7 @@ async fn test_client_brotli_encoding() {
#[cfg(feature = "compress-brotli")]
#[actix_rt::test]
async fn test_client_brotli_encoding_large_random() {
async fn client_brotli_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(&rand::distributions::Alphanumeric)
.take(70_000)
@ -591,7 +591,7 @@ async fn test_client_brotli_encoding_large_random() {
}
#[actix_rt::test]
async fn test_client_deflate_encoding() {
async fn client_deflate_encoding() {
let srv = actix_test::start(|| {
App::new().default_service(web::to(|body: Bytes| async {
HttpResponse::Ok().body(body)
@ -611,7 +611,7 @@ async fn test_client_deflate_encoding() {
}
#[actix_rt::test]
async fn test_client_deflate_encoding_large_random() {
async fn client_deflate_encoding_large_random() {
let data = rand::thread_rng()
.sample_iter(rand::distributions::Alphanumeric)
.map(char::from)
@ -637,7 +637,7 @@ async fn test_client_deflate_encoding_large_random() {
}
#[actix_rt::test]
async fn test_client_streaming_explicit() {
async fn client_streaming_explicit() {
let srv = actix_test::start(|| {
App::new().default_service(web::to(|body: web::Payload| async {
HttpResponse::Ok().streaming(body)
@ -659,7 +659,7 @@ async fn test_client_streaming_explicit() {
}
#[actix_rt::test]
async fn test_body_streaming_implicit() {
async fn body_streaming_implicit() {
let srv = actix_test::start(|| {
App::new().default_service(web::to(|| async {
let body =
@ -681,7 +681,7 @@ async fn test_body_streaming_implicit() {
}
#[actix_rt::test]
async fn test_client_cookie_handling() {
async fn client_cookie_handling() {
use std::io::{Error as IoError, ErrorKind};
let cookie1 = Cookie::build("cookie1", "value1").finish();
@ -833,7 +833,7 @@ async fn client_bearer_auth() {
}
#[actix_rt::test]
async fn test_local_address() {
async fn local_address() {
let ip = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
let srv = actix_test::start(move || {