Re-enable the entire test suite:

* Disable compression tests
* Finish migrating all other examples and tests
This commit is contained in:
Jeb Rosen 2019-08-28 19:56:33 -07:00 committed by Sergio Benitez
parent 047b1620f9
commit facc00454c
8 changed files with 58 additions and 57 deletions

View File

@ -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::*;

View File

@ -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};

View File

@ -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/<name> 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/");

View File

@ -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);
});
}

View File

@ -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/<name> 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/");

View File

@ -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