use graphar::{GraphInfo, ValidateOptions, validate_graph_info};
use std::path::Path;
fn good_graph() -> GraphInfo {
GraphInfo::new("social", "./")
}
fn bad_graph() -> GraphInfo {
GraphInfo::new("", "./")
}
#[cfg(not(feature = "testmatrix"))]
#[test]
fn functional_status_is_a_linked_noop_and_validator_runs() {
graphar::functional_status("graphar/chunk_store", "write_chunk", true, "noop");
let ok = validate_graph_info(&good_graph(), Path::new("."), &ValidateOptions::default());
assert!(ok.is_empty(), "a conformant graph has no issues: {ok:?}");
let bad = validate_graph_info(&bad_graph(), Path::new("."), &ValidateOptions::default());
assert!(!bad.is_empty(), "an empty-name graph must have issues");
}
#[cfg(feature = "testmatrix")]
#[test]
fn surfaces_record_green_and_red_rows() {
use nornir_testmatrix::{drain_functional_rows, status};
let _ = drain_functional_rows();
let issues = validate_graph_info(&good_graph(), Path::new("."), &ValidateOptions::default());
assert!(issues.is_empty(), "conformant graph: {issues:?}");
graphar::functional_status("graphar/chunk_store", "write_chunk", true, "vertex/chunk0");
let bad = validate_graph_info(&bad_graph(), Path::new("."), &ValidateOptions::default());
assert!(!bad.is_empty(), "non-conformant graph must produce issues");
let rows = drain_functional_rows();
let greens: Vec<_> = rows
.iter()
.filter(|r| r.suite == "graphar/validate" && r.test_name == "graph_info")
.collect();
assert_eq!(greens.len(), 2, "two validate rows recorded; got {rows:?}");
assert!(status::is_green(&greens[0].status), "conformant graph is GREEN: {:?}", greens[0]);
assert_eq!(greens[0].aspect, "functional");
assert!(status::is_red(&greens[1].status), "empty-name graph is RED: {:?}", greens[1]);
let write = rows
.iter()
.find(|r| r.suite == "graphar/chunk_store" && r.test_name == "write_chunk")
.unwrap_or_else(|| panic!("write surface must record; got {rows:?}"));
assert!(status::is_green(&write.status), "a successful write is GREEN: {write:?}");
assert_eq!(write.message, "vertex/chunk0", "detail carries the chunk rel path");
}