use microvms_core::control::ControlPlane;
use microvms_core::preflight::{PreflightReport, preflight};
use microvms_core::prelude::*;
use microvms_core::region::Region;
fn region() -> Region {
std::env::var("AWS_REGION")
.unwrap_or_else(|_| "us-east-1".into())
.parse()
.expect("a supported region")
}
fn print(label: &str, report: &PreflightReport) {
for check in &report.checks {
eprintln!(
"PREFLIGHT {label} {}={} ran={} fatal={} detail={}",
check.name,
if check.ok { "ok" } else { "fail" },
check.ran,
check.fatal,
check.detail
);
}
eprintln!("PREFLIGHT {label} ok={}", report.ok());
}
#[tokio::test]
#[ignore = "needs AWS credentials; makes one free read-only call"]
async fn preflight_passes_in_the_suites_region_and_changes_nothing() {
let plane = ControlPlane::new(region()).await.expect("credentials");
let before = (
plane.list_microvms().await.expect("ListMicrovms").len(),
plane.list_images().await.expect("ListMicrovmImages").len(),
);
let report = preflight(Some(region())).await;
print("suite", &report);
let after = (
plane.list_microvms().await.expect("ListMicrovms").len(),
plane.list_images().await.expect("ListMicrovmImages").len(),
);
eprintln!("PREFLIGHT suite vms+images before={before:?} after={after:?}");
assert!(report.ok(), "{report:#?}");
assert_eq!(before, after, "a preflight must create nothing");
}
#[tokio::test]
#[ignore = "needs AWS credentials; makes one free read-only call in us-west-1"]
async fn preflight_in_a_region_without_microvms_fails_its_service_check() {
let report = preflight(Some("us-west-1".parse().expect("a region name"))).await;
print("elsewhere", &report);
let region = report.check("region").expect("a region line");
assert!(!region.ok && !region.fatal, "{region:?}");
assert!(report.check("credentials").is_some_and(|check| check.ok));
let service = report.check("service").expect("a service line");
assert!(service.ran && !service.ok && service.fatal, "{service:?}");
assert!(!report.ok());
}
#[tokio::test]
#[ignore = "run by the conformance driver with every credential source removed"]
async fn preflight_without_credentials_makes_no_call() {
let report = preflight(Some(Region::US_EAST_1)).await;
print("nocreds", &report);
let credentials = report.check("credentials").expect("a credentials line");
assert!(credentials.ran && !credentials.ok, "{credentials:?}");
let service = report.check("service").expect("a service line");
assert!(!service.ran, "{service:?}");
assert!(!report.ok());
}