mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-11 03:59:05 +00:00
560f0977d3
* 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.
39 lines
1.2 KiB
Rust
39 lines
1.2 KiB
Rust
use super::rocket;
|
|
use rocket::local::Client;
|
|
|
|
#[rocket::async_test]
|
|
async fn rewrite_get_put() {
|
|
let client = Client::new(rocket()).unwrap();
|
|
let mut response = client.get("/").dispatch().await;
|
|
assert_eq!(response.body_string().await, Some("Hello, fairings!".into()));
|
|
}
|
|
|
|
#[rocket::async_test]
|
|
async fn counts() {
|
|
let client = Client::new(rocket()).unwrap();
|
|
|
|
// Issue 1 GET request.
|
|
client.get("/").dispatch().await;
|
|
|
|
// Check the GET count, taking into account _this_ GET request.
|
|
let mut response = client.get("/counts").dispatch().await;
|
|
assert_eq!(response.body_string().await, Some("Get: 2\nPost: 0".into()));
|
|
|
|
// Issue 1 more GET request and a POST.
|
|
client.get("/").dispatch().await;
|
|
client.post("/").dispatch().await;
|
|
|
|
// Check the counts.
|
|
let mut response = client.get("/counts").dispatch().await;
|
|
assert_eq!(response.body_string().await, Some("Get: 4\nPost: 1".into()));
|
|
}
|
|
|
|
#[rocket::async_test]
|
|
async fn token() {
|
|
let client = Client::new(rocket()).unwrap();
|
|
|
|
// Ensure the token is '123', which is what we have in `Rocket.toml`.
|
|
let mut res = client.get("/token").dispatch().await;
|
|
assert_eq!(res.body_string().await, Some("123".into()));
|
|
}
|