mod common;
use common::Root;
const LIFECYCLE: [(&str, &str, &str, &str); 6] = [
(
"lifecycle.transition.not_permitted",
"OB-LIFE-1",
"blocking",
"final_posture",
),
(
"lifecycle.state.not_admitted",
"OB-LIFE-2",
"blocking",
"final_posture",
),
(
"lifecycle.dependency.on_terminal",
"OB-LIFE-3",
"advisory",
"permanently_advisory",
),
(
"lifecycle.deletion.not_permitted",
"OB-LIFE-4",
"blocking",
"final_posture",
),
(
"lifecycle.dependency.on_initial",
"OB-LIFE-5",
"advisory",
"permanently_advisory",
),
(
"lifecycle.state.not_set_by_edge",
"OB-LIFE-6",
"blocking",
"final_posture",
),
];
#[test]
fn every_lifecycle_rule_reaches_one_obligation_of_the_standard_package() {
let root = Root::shaped("standard-controls", |_| {});
let ran = root.run(&["check"]);
let flat = ran.out.split_whitespace().collect::<Vec<_>>().join(" ");
assert!(
flat.contains("so it names none")
|| flat.contains("every rule this engine carries reaches one obligation"),
"the register block is not in the output, so this case reads nothing: {ran:?}"
);
let unbound: Vec<&str> = LIFECYCLE
.into_iter()
.map(|(rule, ..)| rule)
.filter(|rule| flat.contains(&format!(" {rule} reaches ")))
.collect();
assert!(
unbound.is_empty(),
"these lifecycle rules reach no single obligation of headwater/standard: {unbound:?}"
);
}
fn control_of<'a>(taxonomy: &'a str, rule: &str) -> &'a str {
let at = taxonomy
.find("\ncontrols:\n")
.expect("the package declares controls");
let mechanism = format!(" mechanism: check:{rule}\n");
let blocks: Vec<&str> = taxonomy[at..]
.split("\n\n")
.filter(|block| block.contains(&mechanism))
.collect();
assert_eq!(blocks.len(), 1, "one control names `{rule}`: {blocks:?}");
blocks[0]
}
#[test]
fn each_lifecycle_control_declares_its_obligation_posture_and_promotion() {
let source = common::repository().join("taxonomy-source/headwater-standard/taxonomy.yml");
let taxonomy = std::fs::read_to_string(&source).expect("the maintained package reads");
for (rule, obligation, posture, promotion) in LIFECYCLE {
let control = control_of(&taxonomy, rule);
for line in [
format!(" discharges: [{obligation}]\n"),
format!(" posture: {posture}\n"),
format!(" {promotion}:\n"),
] {
assert!(
control.contains(&line),
"the control of `{rule}` does not declare `{}`:\n{control}",
line.trim()
);
}
}
}