Rocket/core/lib/tests/conditionally-set-server-header-996.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
985 B
Rust

#![feature(proc_macro_hygiene)]
#[macro_use] extern crate rocket;
use rocket::Response;
use rocket::http::Header;
#[get("/do_not_overwrite")]
fn do_not_overwrite() -> Response<'static> {
Response::build()
.header(Header::new("Server", "Test"))
.finalize()
}
#[get("/use_default")]
fn use_default() { }
mod conditionally_set_server_header {
use super::*;
use rocket::local::Client;
#[rocket::async_test]
async fn do_not_overwrite_server_header() {
let rocket = rocket::ignite().mount("/", routes![do_not_overwrite, use_default]);
let client = Client::new(rocket).unwrap();
let response = client.get("/do_not_overwrite").dispatch().await;
let server = response.headers().get_one("Server");
assert_eq!(server, Some("Test"));
let response = client.get("/use_default").dispatch().await;
let server = response.headers().get_one("Server");
assert_eq!(server, Some("Rocket"));
}
}