use super::*;
const POISONED_SPEC_BYTES: &str = r#"{
"node_types": [{
"alias": null,
"identifying_label": "L",
"implied_labels": [],
"properties": [{
"name": "p",
"value_type": {"Predefined": {"kind": "String", "not_null": false}},
"default_value": {"Constructor": {"name": "toString", "args": []}},
"inline_constraint": null
}]
}]
}"#;
fn poisoned_spec() -> crate::graph_type::GraphTypeSpec {
serde_json::from_str(POISONED_SPEC_BYTES).expect("hand-crafted bytes decode")
}
fn assert_poisoned_storage_error<T: std::fmt::Debug, E: std::fmt::Display>(
result: std::result::Result<T, E>,
) {
let error = result.expect_err("a poisoned persisted default fails typed, not panic");
assert!(
error
.to_string()
.contains("persisted graph type carries an invalid default value"),
"expected the typed storage-corruption error, got: {error}"
);
}
#[test]
fn replay_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let graph = Graph::default();
assert_poisoned_storage_error(graph.apply_redo(
vec![crate::redo::RedoOp::SetCurrentGraphType {
body: poisoned_spec(),
}],
1,
));
}
#[test]
fn visualize_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let spec: crate::graph_type::GraphTypeSpec =
serde_json::from_str(POISONED_SPEC_BYTES).expect("hand-crafted persisted bytes decode");
let body = spec.to_body();
assert_poisoned_storage_error(crate::graph_type_visualize::render_graph_type_as_graph(
&body,
&[],
relate_parser::AnyNodeMode::Single,
));
}
#[test]
fn json_restore_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let graph = Graph::default();
assert_poisoned_storage_error(graph.restore_graph_type_spec(Some(
"{ (:L => {p :: STRING DEFAULT ON COMMIT toString()})}",
)));
}
#[test]
fn checkpoint_verify_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let image: super::theater::CheckpointTheater = serde_json::from_str(&format!(
r#"{{"databases": {{}}, "index_details": {{}}, "index_options": {{}}, "graph_types": {{}}, "current_graph_type": {POISONED_SPEC_BYTES}, "derived_constraints": {{}}}}"#
))
.expect("hand-crafted checkpoint bytes decode");
let graph = Graph::default();
assert_poisoned_storage_error(graph.restore_checkpoint_theater(image));
}
#[test]
fn checkpoint_writer_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let graph = Graph::default();
graph.theater.lock().unwrap().current_graph_type = poisoned_spec();
assert_poisoned_storage_error(graph.graph_type_spec());
}
#[test]
fn show_graph_type_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let graph = Graph::default();
graph
.theater
.lock()
.unwrap()
.graph_types
.insert("gt".to_string(), poisoned_spec());
let view = crate::overlay::ExecGraph::read(&graph);
let clause = relate_parser::ShowGraphTypeClause {
name: SmallName::from_name("gt"),
yields: Default::default(),
};
assert_poisoned_storage_error(crate::exec::catalog_show::show_graph_type_rows(
&view, &clause,
));
}
#[test]
fn show_current_graph_type_of_a_poisoned_persisted_default_fails_typed_not_panic() {
let graph = Graph::default();
graph.theater.lock().unwrap().current_graph_type = poisoned_spec();
let view = crate::overlay::ExecGraph::read(&graph);
let clause = relate_parser::ShowCurrentGraphTypeClause {
yields: Default::default(),
stages: Vec::new(),
where_expr: None,
as_graph: None,
variant: None,
};
assert_poisoned_storage_error(crate::exec::catalog_show::show_current_graph_type_rows(
&view, &clause,
));
}