filters are now entities and auto-generated for all table backed types
This commit is contained in:
@ -533,6 +533,12 @@ fn test_unique_items_6_1() {
|
||||
crate::tests::runner::run_test_case(&path, 6, 1).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_filter_0_0() {
|
||||
let path = format!("{}/fixtures/filter.json", env!("CARGO_MANIFEST_DIR"));
|
||||
crate::tests::runner::run_test_case(&path, 0, 0).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_min_items_0_0() {
|
||||
let path = format!("{}/fixtures/minItems.json", env!("CARGO_MANIFEST_DIR"));
|
||||
|
||||
@ -107,12 +107,28 @@ fn test_library_api() {
|
||||
}
|
||||
}
|
||||
},
|
||||
"source_schema.filter": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"type": { "type": ["string.condition", "null"] },
|
||||
"name": { "type": ["string.condition", "null"] },
|
||||
"target": { "type": ["target_schema.filter", "null"] }
|
||||
},
|
||||
"compiledPropertyNames": ["name", "target", "type"]
|
||||
},
|
||||
"target_schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"value": { "type": "number" }
|
||||
},
|
||||
"compiledPropertyNames": ["value"]
|
||||
},
|
||||
"target_schema.filter": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"value": { "type": ["number.condition", "null"] }
|
||||
},
|
||||
"compiledPropertyNames": ["value"]
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -20,5 +20,5 @@ pub struct Expect {
|
||||
#[serde(default)]
|
||||
pub sql: Option<Vec<SqlExpectation>>,
|
||||
#[serde(default)]
|
||||
pub schemas: Option<Vec<String>>,
|
||||
pub schemas: Option<std::collections::HashMap<String, serde_json::Value>>,
|
||||
}
|
||||
|
||||
@ -3,13 +3,13 @@ use std::sync::Arc;
|
||||
|
||||
impl Expect {
|
||||
pub fn assert_schemas(&self, db: &Arc<crate::database::Database>) -> Result<(), String> {
|
||||
if let Some(expected_schemas) = &self.schemas {
|
||||
if let Some(expected_map) = &self.schemas {
|
||||
// Collect actual schemas and sort
|
||||
let mut actual: Vec<String> = db.schemas.keys().cloned().collect();
|
||||
actual.sort();
|
||||
|
||||
// Collect expected schemas and sort
|
||||
let mut expected: Vec<String> = expected_schemas.clone();
|
||||
let mut expected: Vec<String> = expected_map.keys().cloned().collect();
|
||||
expected.sort();
|
||||
|
||||
if actual != expected {
|
||||
@ -21,6 +21,23 @@ impl Expect {
|
||||
actual
|
||||
));
|
||||
}
|
||||
|
||||
for (key, expected_val) in expected_map {
|
||||
if expected_val.is_object() && expected_val.as_object().unwrap().is_empty() {
|
||||
continue; // A `{}` means we just wanted to test it was collected/promoted, skip deep match
|
||||
}
|
||||
let actual_ast = db.schemas.get(key).unwrap();
|
||||
let actual_val = serde_json::to_value(actual_ast).unwrap();
|
||||
|
||||
if actual_val != *expected_val {
|
||||
return Err(format!(
|
||||
"Detailed Schema Match Failure for '{}'!\n\nExpected:\n{}\n\nActual:\n{}",
|
||||
key,
|
||||
serde_json::to_string_pretty(expected_val).unwrap(),
|
||||
serde_json::to_string_pretty(&actual_val).unwrap()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user