Rocket/core/lib/tests/route_guard.rs
Sergio Benitez 03127f4dae Add blocking variant of 'local'.
This commit adds the 'local::blocking' module and moves the existing
asynchronous testing to 'local::asynchronous'. It also includes several
changes to improve the local API, bringing it to parity (and beyond)
with master. These changes are:

  * 'LocalRequest' implements 'Clone'.
  * 'LocalResponse' doesn't implement 'DerefMut<Target=Response>'.
    Instead, direct methods on the type, such as 'into_string()', can
    be used to read the 'Response'.
  * 'Response::body()' returns an '&ResponseBody' as opposed to '&mut
    ResponseBody', which is returned by a new 'Response::body_mut()'.
  * '&ResponseBody' implements 'known_size()` to retrieve a body's size,
    if it is known.

Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
2020-07-11 09:24:30 -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::asynchronous::Client;
async fn assert_path(client: &Client, path: &str) {
let res = client.get(path).dispatch().await;
assert_eq!(res.into_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).await.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;
}
}