Rocket/core/lib/tests/absolute-uris-okay-issue-443.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

35 lines
927 B
Rust

#![feature(proc_macro_hygiene)]
#[macro_use] extern crate rocket;
use rocket::response::Redirect;
#[get("/google")]
fn google() -> Redirect {
Redirect::to("https://www.google.com")
}
#[get("/rocket")]
fn rocket() -> Redirect {
Redirect::to("https://rocket.rs:80")
}
mod test_absolute_uris_okay {
use super::*;
use rocket::local::Client;
#[rocket::async_test]
async fn redirect_works() {
let rocket = rocket::ignite().mount("/", routes![google, rocket]);
let client = Client::new(rocket).unwrap();
let response = client.get("/google").dispatch().await;
let location = response.headers().get_one("Location");
assert_eq!(location, Some("https://www.google.com"));
let response = client.get("/rocket").dispatch().await;
let location = response.headers().get_one("Location");
assert_eq!(location, Some("https://rocket.rs:80"));
}
}