From facc00454c58b32a7b7479c6e69a149c0db0a451 Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Wed, 28 Aug 2019 19:56:33 -0700 Subject: [PATCH] Re-enable the entire test suite: * Disable compression tests * Finish migrating all other examples and tests --- contrib/lib/src/lib.rs | 3 +- ...nder.rs => compress_responder.rs.disabled} | 0 ...ing.rs => compression_fairing.rs.disabled} | 0 contrib/lib/tests/static_files.rs | 10 ++-- examples/handlebars_templates/src/tests.rs | 17 +++--- examples/query_params/src/tests.rs | 52 ++++++++++--------- examples/tera_templates/src/tests.rs | 17 +++--- scripts/test.sh | 16 +++--- 8 files changed, 58 insertions(+), 57 deletions(-) rename contrib/lib/tests/{compress_responder.rs => compress_responder.rs.disabled} (100%) rename contrib/lib/tests/{compression_fairing.rs => compression_fairing.rs.disabled} (100%) diff --git a/contrib/lib/src/lib.rs b/contrib/lib/src/lib.rs index dba2846d..58a02112 100644 --- a/contrib/lib/src/lib.rs +++ b/contrib/lib/src/lib.rs @@ -51,6 +51,7 @@ #[cfg(feature="uuid")] pub mod uuid; #[cfg(feature="databases")] pub mod databases; #[cfg(feature = "helmet")] pub mod helmet; -#[cfg(any(feature="brotli_compression", feature="gzip_compression"))] pub mod compression; +// TODO.async: Migrate compression, reenable this and tests +//#[cfg(any(feature="brotli_compression", feature="gzip_compression"))] pub mod compression; #[cfg(feature="databases")] #[doc(hidden)] pub use rocket_contrib_codegen::*; diff --git a/contrib/lib/tests/compress_responder.rs b/contrib/lib/tests/compress_responder.rs.disabled similarity index 100% rename from contrib/lib/tests/compress_responder.rs rename to contrib/lib/tests/compress_responder.rs.disabled diff --git a/contrib/lib/tests/compression_fairing.rs b/contrib/lib/tests/compression_fairing.rs.disabled similarity index 100% rename from contrib/lib/tests/compression_fairing.rs rename to contrib/lib/tests/compression_fairing.rs.disabled diff --git a/contrib/lib/tests/static_files.rs b/contrib/lib/tests/static_files.rs index 05cd5409..7a13e609 100644 --- a/contrib/lib/tests/static_files.rs +++ b/contrib/lib/tests/static_files.rs @@ -72,7 +72,7 @@ mod static_tests { } #[rocket::async_test] - fn test_static_no_index() { + async fn test_static_no_index() { let client = Client::new(rocket()).expect("valid rocket"); assert_all(&client, "no_index", REGULAR_FILES, true).await; assert_all(&client, "no_index", HIDDEN_FILES, false).await; @@ -80,7 +80,7 @@ mod static_tests { } #[rocket::async_test] - fn test_static_hidden() { + async fn test_static_hidden() { let client = Client::new(rocket()).expect("valid rocket"); assert_all(&client, "dots", REGULAR_FILES, true).await; assert_all(&client, "dots", HIDDEN_FILES, true).await; @@ -88,7 +88,7 @@ mod static_tests { } #[rocket::async_test] - fn test_static_index() { + async fn test_static_index() { let client = Client::new(rocket()).expect("valid rocket"); assert_all(&client, "index", REGULAR_FILES, true).await; assert_all(&client, "index", HIDDEN_FILES, false).await; @@ -100,7 +100,7 @@ mod static_tests { } #[rocket::async_test] - fn test_static_all() { + async fn test_static_all() { let client = Client::new(rocket()).expect("valid rocket"); assert_all(&client, "both", REGULAR_FILES, true).await; assert_all(&client, "both", HIDDEN_FILES, true).await; @@ -122,7 +122,7 @@ mod static_tests { } #[rocket::async_test] - fn test_forwarding() { + async fn test_forwarding() { use rocket::http::RawStr; use rocket::{get, routes}; diff --git a/examples/handlebars_templates/src/tests.rs b/examples/handlebars_templates/src/tests.rs index 19354d6a..04500c14 100644 --- a/examples/handlebars_templates/src/tests.rs +++ b/examples/handlebars_templates/src/tests.rs @@ -1,14 +1,15 @@ use super::{rocket, TemplateContext}; -use rocket::local::{Client, LocalResponse}; +use rocket::local::Client; use rocket::http::Method::*; use rocket::http::Status; use rocket_contrib::templates::Template; macro_rules! dispatch { - ($method:expr, $path:expr, $test_fn:expr) => ({ - let client = Client::new(rocket()).unwrap(); - $test_fn(&client, client.req($method, $path).dispatch().await); + ($method:expr, $path:expr, |$client:ident, $response:ident| $body:expr) => ({ + let $client = Client::new(rocket()).unwrap(); + let mut $response = $client.req($method, $path).dispatch().await; + $body }) } @@ -16,7 +17,7 @@ macro_rules! dispatch { async fn test_root() { // Check that the redirect works. for method in &[Get, Head] { - dispatch!(*method, "/", |_: &Client, mut response: LocalResponse<'_>| { + dispatch!(*method, "/", |client, response| { assert_eq!(response.status(), Status::SeeOther); assert!(response.body().is_none()); @@ -27,7 +28,7 @@ async fn test_root() { // Check that other request methods are not accepted (and instead caught). for method in &[Post, Put, Delete, Options, Trace, Connect, Patch] { - dispatch!(*method, "/", |client: &Client, mut response: LocalResponse<'_>| { + dispatch!(*method, "/", |client, response| { let mut map = std::collections::HashMap::new(); map.insert("path", "/"); let expected = Template::show(client.rocket(), "error/404", &map).unwrap(); @@ -41,7 +42,7 @@ async fn test_root() { #[rocket::async_test] async fn test_name() { // Check that the /hello/ route works. - dispatch!(Get, "/hello/Jack%20Daniels", |client: &Client, mut response: LocalResponse<'_>| { + dispatch!(Get, "/hello/Jack%20Daniels", |client, response| { let context = TemplateContext { title: "Hello", name: Some("Jack Daniels".into()), @@ -58,7 +59,7 @@ async fn test_name() { #[rocket::async_test] async fn test_404() { // Check that the error catcher works. - dispatch!(Get, "/hello/", |client: &Client, mut response: LocalResponse<'_>| { + dispatch!(Get, "/hello/", |client, response| { let mut map = std::collections::HashMap::new(); map.insert("path", "/hello/"); diff --git a/examples/query_params/src/tests.rs b/examples/query_params/src/tests.rs index 56d61197..5d5bf362 100644 --- a/examples/query_params/src/tests.rs +++ b/examples/query_params/src/tests.rs @@ -1,76 +1,78 @@ use super::rocket; -use rocket::local::{Client, LocalResponse as Response}; +use rocket::local::Client; use rocket::http::Status; macro_rules! run_test { - ($query:expr, $test_fn:expr) => ({ + ($query:expr, |$response:ident| $body:expr) => ({ let client = Client::new(rocket()).unwrap(); - $test_fn(client.get(format!("/hello{}", $query)).dispatch().await); + #[allow(unused_mut)] + let mut $response = client.get(format!("/hello{}", $query)).dispatch().await; + $body }) } -#[test] -fn age_and_name_params() { - run_test!("?age=10&first-name=john", |mut response: Response<'_>| { +#[rocket::async_test] +async fn age_and_name_params() { + run_test!("?age=10&first-name=john", |response| { assert_eq!(response.body_string().await, Some("Hello, 10 year old named john!".into())); }); - run_test!("?age=20&first-name=john", |mut response: Response<'_>| { + run_test!("?age=20&first-name=john", |response| { assert_eq!(response.body_string().await, Some("20 years old? Hi, john!".into())); }); } -#[test] -fn age_param_only() { - run_test!("?age=10", |mut response: Response<'_>| { +#[rocket::async_test] +async fn age_param_only() { + run_test!("?age=10", |response| { assert_eq!(response.body_string().await, Some("We're gonna need a name, and only a name.".into())); }); - run_test!("?age=20", |mut response: Response<'_>| { + run_test!("?age=20", |response| { assert_eq!(response.body_string().await, Some("We're gonna need a name, and only a name.".into())); }); } -#[test] -fn name_param_only() { - run_test!("?first-name=John", |mut response: Response<'_>| { +#[rocket::async_test] +async fn name_param_only() { + run_test!("?first-name=John", |response| { assert_eq!(response.body_string().await, Some("Hello John!".into())); }); } -#[test] -fn no_params() { - run_test!("", |mut response: Response<'_>| { +#[rocket::async_test] +async fn no_params() { + run_test!("", |response| { assert_eq!(response.body_string().await, Some("We're gonna need a name, and only a name.".into())); }); - run_test!("?", |mut response: Response<'_>| { + run_test!("?", |response| { assert_eq!(response.body_string().await, Some("We're gonna need a name, and only a name.".into())); }); } -#[test] -fn extra_params() { - run_test!("?age=20&first-name=Bob&extra", |mut response: Response<'_>| { +#[rocket::async_test] +async fn extra_params() { + run_test!("?age=20&first-name=Bob&extra", |response| { assert_eq!(response.body_string().await, Some("20 years old? Hi, Bob!".into())); }); - run_test!("?age=30&first-name=Bob&extra", |mut response: Response<'_>| { + run_test!("?age=30&first-name=Bob&extra", |response| { assert_eq!(response.body_string().await, Some("We're gonna need a name, and only a name.".into())); }); } -#[test] -fn wrong_path() { - run_test!("/other?age=20&first-name=Bob", |response: Response<'_>| { +#[rocket::async_test] +async fn wrong_path() { + run_test!("/other?age=20&first-name=Bob", |response| { assert_eq!(response.status(), Status::NotFound); }); } diff --git a/examples/tera_templates/src/tests.rs b/examples/tera_templates/src/tests.rs index 182d463d..46d4bb45 100644 --- a/examples/tera_templates/src/tests.rs +++ b/examples/tera_templates/src/tests.rs @@ -1,13 +1,14 @@ use super::rocket; -use rocket::local::{Client, LocalResponse}; +use rocket::local::Client; use rocket::http::Method::*; use rocket::http::Status; use rocket_contrib::templates::Template; macro_rules! dispatch { - ($method:expr, $path:expr, $test_fn:expr) => ({ - let client = Client::new(rocket()).unwrap(); - $test_fn(&client, client.req($method, $path).dispatch().await); + ($method:expr, $path:expr, |$client:ident, $response:ident| $body:expr) => ({ + let $client = Client::new(rocket()).unwrap(); + let mut $response = $client.req($method, $path).dispatch().await; + $body }) } @@ -15,7 +16,7 @@ macro_rules! dispatch { async fn test_root() { // Check that the redirect works. for method in &[Get, Head] { - dispatch!(*method, "/", |_: &Client, mut response: LocalResponse<'_>| { + dispatch!(*method, "/", |client, response| { assert_eq!(response.status(), Status::SeeOther); assert!(response.body().is_none()); @@ -26,7 +27,7 @@ async fn test_root() { // Check that other request methods are not accepted (and instead caught). for method in &[Post, Put, Delete, Options, Trace, Connect, Patch] { - dispatch!(*method, "/", |client: &Client, mut response: LocalResponse<'_>| { + dispatch!(*method, "/", |client, response| { let mut map = std::collections::HashMap::new(); map.insert("path", "/"); let expected = Template::show(client.rocket(), "error/404", &map).unwrap(); @@ -40,7 +41,7 @@ async fn test_root() { #[rocket::async_test] async fn test_name() { // Check that the /hello/ route works. - dispatch!(Get, "/hello/Jack", |client: &Client, mut response: LocalResponse<'_>| { + dispatch!(Get, "/hello/Jack", |client, response| { let context = super::TemplateContext { name: "Jack".into(), items: vec!["One", "Two", "Three"] @@ -55,7 +56,7 @@ async fn test_name() { #[rocket::async_test] async fn test_404() { // Check that the error catcher works. - dispatch!(Get, "/hello/", |client: &Client, mut response: LocalResponse<'_>| { + dispatch!(Get, "/hello/", |client, response| { let mut map = std::collections::HashMap::new(); map.insert("path", "/hello/"); diff --git a/scripts/test.sh b/scripts/test.sh index 3ed6060a..45c66fd9 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -67,8 +67,7 @@ if [ "$1" = "--contrib" ]; then msgpack tera_templates handlebars_templates -# TODO.async: tokio-rs/tokio#1356 -# serve + serve helmet diesel_postgres_pool diesel_sqlite_pool @@ -80,16 +79,14 @@ if [ "$1" = "--contrib" ]; then redis_pool mongodb_pool memcache_pool -# TODO.async: compression not yet ported to async -# brotli_compression -# gzip_compression + brotli_compression + gzip_compression ) pushd "${CONTRIB_LIB_ROOT}" > /dev/null 2>&1 -# TODO.async: 'serve' (broken) is a default feature -# echo ":: Building and testing contrib [default]..." -# CARGO_INCREMENTAL=0 cargo test + echo ":: Building and testing contrib [default]..." + CARGO_INCREMENTAL=0 cargo test for feature in "${FEATURES[@]}"; do echo ":: Building and testing contrib [${feature}]..." @@ -117,6 +114,5 @@ elif [ "$1" = "--core" ]; then popd > /dev/null 2>&1 else echo ":: Building and testing libraries..." -# TODO.async: see other failures above -# CARGO_INCREMENTAL=0 cargo test --all-features --all $@ + CARGO_INCREMENTAL=0 cargo test --all-features --all $@ fi