use super::{count_compatible, has_before_update_trigger, hierarchy};
use crate::catalog::SchemaCatalog;
#[test]
fn only_numeric_counter_types_are_count_compatible() {
for kind in [
"integer",
"BigInt",
" smallint ",
"int4",
"numeric",
"numeric(10,0)",
] {
assert!(count_compatible(kind), "{kind}");
}
for kind in ["date", "numeric_like", "timestamp", "text", "interval"] {
assert!(!count_compatible(kind), "{kind}");
}
}
#[test]
fn hierarchy_checks_ancestors_and_partition_before_update_triggers() {
let catalog = SchemaCatalog::from_json(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../test-cases/rules/postgres-table-shape/fixture/count-owners/indirect-edges.json"
)))
.unwrap();
assert!(!hierarchy::known_ancestors(
&catalog,
catalog.relation("orphan_leaf").unwrap()
));
assert!(!hierarchy::known_ancestors(
&catalog,
catalog.relation("orphan_child").unwrap()
));
assert!(hierarchy::known_ancestors(
&catalog,
catalog.relation("diamond_leaf").unwrap()
));
assert!(has_before_update_trigger(
&catalog,
catalog.relation("guarded_part").unwrap()
));
assert!(has_before_update_trigger(
&catalog,
catalog.relation("guarded_parent_p1").unwrap()
));
assert!(!has_before_update_trigger(
&catalog,
catalog.relation("projects").unwrap()
));
}