crates/knut-popviz/tests/testmatrix_wiring.rs
//! Wiring proof for knut-popviz's `functional_status` test-matrix surface (the
//! newest feature: the bulk-loader reports its `run_load` outcome into the
//! nornir matrix). The live call site sits behind an async FalkorDB load, so
//! this exercises the crate's public wrapper directly — the same forwarder the
//! loader calls — and asserts on the REAL emitted rows. Offline, in-process.
//!
//! One test per build (single test per binary → no race on the process-global
//! functional buffer `--features testmatrix` records into):
//! * default build → the wrapper is a compiled-out no-op; assert it links.
//! * `--features testmatrix` → assert the wrapper records BOTH a green and a
//! red row with the correct status/metric mapping.
/// Default build: `testmatrix` OFF → `functional_status` is an inlined no-op.
#[cfg(not(feature = "testmatrix"))]
#[test]
fn functional_status_is_a_linked_noop() {
knut_popviz::functional_status("knut-popviz/run_load", "population_load", true, "Person");
knut_popviz::functional_status("knut-popviz/run_load", "population_load", false, "boom");
}
/// `--features testmatrix`: the wrapper must forward each outcome into the
/// matrix — a passing load → GREEN (metric 0.0), a failing load → RED (metric
/// 1.0) — exactly as the `run_load` success/error arms call it.
#[cfg(feature = "testmatrix")]
#[test]
fn wrapper_forwards_green_and_red_load_outcomes() {
use nornir_testmatrix::{drain_functional_rows, status};
let _ = drain_functional_rows();
// Mirror the two real call sites in `run_load` (Ok / Err arms).
knut_popviz::functional_status("knut-popviz/run_load", "population_load", true, "Person");
knut_popviz::functional_status(
"knut-popviz/run_load",
"population_load",
false,
"connection refused",
);
let rows = drain_functional_rows();
let load_rows: Vec<_> = rows
.iter()
.filter(|r| r.suite == "knut-popviz/run_load" && r.test_name == "population_load")
.collect();
assert_eq!(load_rows.len(), 2, "both load outcomes recorded: {rows:?}");
let green = load_rows
.iter()
.find(|r| status::is_green(&r.status))
.expect("a GREEN load row");
assert_eq!(green.aspect, "functional");
assert_eq!(green.metric, 0.0, "green rows carry metric 0.0");
assert_eq!(green.message, "Person", "detail carries the target label");
let red = load_rows
.iter()
.find(|r| status::is_red(&r.status))
.expect("a RED load row");
assert_eq!(red.metric, 1.0, "red rows carry metric 1.0");
assert_eq!(
red.message, "connection refused",
"detail carries the failure note"
);
}