use isoloom_plan::{Environment, Lab};
use isoloom_spec::model::{Spec, Target};
pub(crate) fn lab(yaml: &str) -> Lab {
let lab = Lab::parse(yaml).unwrap_or_else(|p| panic!("the test spec parses: {p:?}"));
assert_eq!(lab.problems(), [], "the test spec is valid");
lab
}
pub(crate) fn spec(yaml: &str) -> Spec {
lab(yaml).spec()
}
pub(crate) fn env(yaml: &str, target: Target) -> Environment {
Environment::build(&lab(yaml).for_target(target), target, None)
}
pub(crate) fn machine(m: &str, target: Target, templates: &[(&str, &str)]) -> Environment {
let yaml = format!("version: 1\nname: lab\nnetworks: {{ lan: {{ cidr: 10.9.0.0/24 }} }}\nmachines:\n m: {{ networks: {{ lan: 10 }}, {m} }}\n");
let texts = templates
.iter()
.filter_map(|(path, text)| Some((path.parse().ok()?, (*text).to_owned())))
.collect();
let lab = lab(&yaml).with_templates(texts);
Environment::build(&lab.for_target(target), target, None)
}
pub(crate) fn rendered(
m: &str,
target: Target,
templates: &[(&str, &str)],
render: impl Fn(&crate::configure::Configured<'_>, &isoloom_plan::configure::Resource) -> Option<String>,
) -> Vec<Option<String>> {
let env = machine(m, target, templates);
let c = crate::configure::Configured::of(&env, "m").expect("a recipe");
c.recipe().resources().map(|r| render(&c, r)).collect()
}