Rocket/core/lib/tests/attach-inspect.rs
Sergio Benitez d89c7024ed Replace 'Manifest' with 'Cargo'.
This is largely an internal change. Prior to this commit, the 'Manifest'
type, now replaced with the 'Cargo' type, robbed responsibility from the
core 'Rocket' type. This new construction restores the previous
responsibility and makes it clear that 'Cargo' is _only_ for freezing,
and representing the stability of, Rocket's internal state.
2020-07-11 09:24:30 -07:00

44 lines
1.4 KiB
Rust

use rocket::fairing::AdHoc;
#[rocket::async_test]
async fn test_inspectable_attach_state() {
let mut rocket = rocket::ignite()
.attach(AdHoc::on_attach("Add State", |rocket| async {
Ok(rocket.manage("Hi!"))
}));
let state = rocket.inspect().await;
assert_eq!(state.state::<&'static str>(), Some(&"Hi!"));
}
#[rocket::async_test]
async fn test_inspectable_attach_state_in_future_attach() {
let mut rocket = rocket::ignite()
.attach(AdHoc::on_attach("Add State", |rocket| async {
Ok(rocket.manage("Hi!"))
}))
.attach(AdHoc::on_attach("Inspect State", |mut rocket| async {
let state = rocket.inspect().await;
assert_eq!(state.state::<&'static str>(), Some(&"Hi!"));
Ok(rocket)
}));
let _ = rocket.inspect().await;
}
#[rocket::async_test]
async fn test_attach_state_is_well_ordered() {
let mut rocket = rocket::ignite()
.attach(AdHoc::on_attach("Inspect State Pre", |mut rocket| async {
let state = rocket.inspect().await;
assert_eq!(state.state::<&'static str>(), None);
Ok(rocket)
}))
.attach(AdHoc::on_attach("Add State", |rocket| async {
Ok(rocket.manage("Hi!"))
}));
let state = rocket.inspect().await;
assert_eq!(state.state::<&'static str>(), Some(&"Hi!"));
}