Rocket/core/lib/tests/route_guard.rs
Jeb Rosen 560f0977d3 Revamp testing system for async.
* body_string_wait and body_bytes_wait are removed; use `.await` instead
* `dispatch()` is now an async fn and must be .await-ed
* Add `#[rocket::async_test]` macro, similar in purpose to `tokio::test`
* Tests now use either `rocket::async_test(async { })` or
  `#[rocket::async_test]` in order to `.await` the futures returned
  from `dispatch()` and `body_{string,bytes}()`
* Update 'test.sh' to reflect the tests that should be passing.

Broken:

* Cloned dispatch and mut_dispatch() with a live previous response now both fail, due to a (partial) check for mutable aliasing in LocalRequest.
* Some tests are still failing and need example-specific changes.
2020-07-11 09:24:28 -07:00

36 lines
1.0 KiB
Rust

#![feature(proc_macro_hygiene)]
#[macro_use] extern crate rocket;
use std::path::{Path, PathBuf};
use rocket::http::ext::Normalize;
use rocket::Route;
#[get("/<path..>")]
fn files(route: &Route, path: PathBuf) -> String {
Path::new(route.base()).join(path).normalized_str().to_string()
}
mod route_guard_tests {
use super::*;
use rocket::local::Client;
async fn assert_path(client: &Client, path: &str) {
let mut res = client.get(path).dispatch().await;
assert_eq!(res.body_string().await, Some(path.into()));
}
#[rocket::async_test]
async fn check_mount_path() {
let rocket = rocket::ignite()
.mount("/first", routes![files])
.mount("/second", routes![files]);
let client = Client::new(rocket).unwrap();
assert_path(&client, "/first/some/path").await;
assert_path(&client, "/second/some/path").await;
assert_path(&client, "/first/second/b/c").await;
assert_path(&client, "/second/a/b/c").await;
}
}