mirror of
https://github.com/rwf2/Rocket.git
synced 2024-12-31 23:02:37 +00:00
d89c7024ed
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.
44 lines
1.4 KiB
Rust
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!"));
|
|
}
|