2020-06-28 05:59:40 +00:00
|
|
|
use rocket::fairing::AdHoc;
|
|
|
|
|
|
|
|
#[rocket::async_test]
|
|
|
|
async fn test_inspectable_attach_state() {
|
2020-10-22 10:27:04 +00:00
|
|
|
let rocket = rocket::ignite()
|
2020-06-28 05:59:40 +00:00
|
|
|
.attach(AdHoc::on_attach("Add State", |rocket| async {
|
|
|
|
Ok(rocket.manage("Hi!"))
|
|
|
|
}));
|
|
|
|
|
2020-10-22 10:27:04 +00:00
|
|
|
let state = rocket.state::<&'static str>();
|
|
|
|
assert_eq!(state, Some(&"Hi!"));
|
2020-06-28 05:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[rocket::async_test]
|
|
|
|
async fn test_inspectable_attach_state_in_future_attach() {
|
2020-10-22 10:27:04 +00:00
|
|
|
let rocket = rocket::ignite()
|
2020-06-28 05:59:40 +00:00
|
|
|
.attach(AdHoc::on_attach("Add State", |rocket| async {
|
|
|
|
Ok(rocket.manage("Hi!"))
|
|
|
|
}))
|
2020-10-22 10:27:04 +00:00
|
|
|
.attach(AdHoc::on_attach("Inspect State", |rocket| async {
|
|
|
|
let state = rocket.state::<&'static str>();
|
|
|
|
assert_eq!(state, Some(&"Hi!"));
|
2020-06-28 05:59:40 +00:00
|
|
|
Ok(rocket)
|
|
|
|
}));
|
|
|
|
|
2020-10-22 10:27:04 +00:00
|
|
|
let state = rocket.state::<&'static str>();
|
|
|
|
assert_eq!(state, Some(&"Hi!"));
|
2020-06-28 05:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[rocket::async_test]
|
|
|
|
async fn test_attach_state_is_well_ordered() {
|
2020-10-22 10:27:04 +00:00
|
|
|
let rocket = rocket::ignite()
|
|
|
|
.attach(AdHoc::on_attach("Inspect State Pre", |rocket| async {
|
|
|
|
let state = rocket.state::<&'static str>();
|
|
|
|
assert_eq!(state, None);
|
2020-06-28 05:59:40 +00:00
|
|
|
Ok(rocket)
|
|
|
|
}))
|
|
|
|
.attach(AdHoc::on_attach("Add State", |rocket| async {
|
|
|
|
Ok(rocket.manage("Hi!"))
|
|
|
|
}));
|
|
|
|
|
2020-10-22 10:27:04 +00:00
|
|
|
let state = rocket.state::<&'static str>();
|
|
|
|
assert_eq!(state, Some(&"Hi!"));
|
2020-06-28 05:59:40 +00:00
|
|
|
}
|