jspg error refactoring checkpoint
This commit is contained in:
@ -18,7 +18,6 @@ fn test_library_api() {
|
||||
"type": "drop",
|
||||
"errors": [{
|
||||
"code": "ENGINE_NOT_INITIALIZED",
|
||||
"message": "JSPG extension has not been initialized via jspg_setup",
|
||||
"details": {}
|
||||
}]
|
||||
})
|
||||
@ -250,7 +249,9 @@ fn test_library_api() {
|
||||
"errors": [
|
||||
{
|
||||
"code": "REQUIRED_FIELD_MISSING",
|
||||
"message": "Missing name",
|
||||
"values": {
|
||||
"field_name": "name"
|
||||
},
|
||||
"details": {
|
||||
"path": "name",
|
||||
"schema": "source_schema"
|
||||
@ -258,7 +259,9 @@ fn test_library_api() {
|
||||
},
|
||||
{
|
||||
"code": "STRICT_PROPERTY_VIOLATION",
|
||||
"message": "Unexpected property 'wrong'",
|
||||
"values": {
|
||||
"property_name": "wrong"
|
||||
},
|
||||
"details": {
|
||||
"path": "wrong",
|
||||
"schema": "source_schema"
|
||||
|
||||
@ -86,7 +86,7 @@ pub fn run_test_case(path: &str, suite_idx: usize, case_idx: usize) -> Result<()
|
||||
let error_messages: Vec<String> = drop
|
||||
.errors
|
||||
.iter()
|
||||
.map(|e| format!("Error {} at path {}: {}", e.code, e.details.path.as_deref().unwrap_or("/"), e.message))
|
||||
.map(|e| format!("Error {} at path {}: {:?}", e.code, e.details.path.as_deref().unwrap_or("/"), e.values))
|
||||
.collect();
|
||||
failures.push(format!(
|
||||
"[{}] Cannot run '{}' test '{}': System Setup Compilation structurally failed:\n{}",
|
||||
@ -117,7 +117,7 @@ pub fn run_test_case(path: &str, suite_idx: usize, case_idx: usize) -> Result<()
|
||||
}
|
||||
}
|
||||
"validate" => {
|
||||
let result = test.run_validate(db_unwrapped.unwrap());
|
||||
let result = test.run_validate(db_unwrapped.unwrap(), path, suite_idx, case_idx);
|
||||
if let Err(e) = result {
|
||||
println!("TEST VALIDATE ERROR FOR '{}': {}", test.description, e);
|
||||
failures.push(format!(
|
||||
@ -205,6 +205,25 @@ pub fn canonicalize_with_map(s: &str, uuid_map: &HashMap<String, String>, gen_ma
|
||||
ts_re.replace_all(&s1, "{{timestamp}}").to_string()
|
||||
}
|
||||
|
||||
pub fn update_validation_fixture(path: &str, suite_idx: usize, case_idx: usize, errors: &[crate::drop::Error]) {
|
||||
let content = fs::read_to_string(path).unwrap();
|
||||
let mut file_data: Value = serde_json::from_str(&content).unwrap();
|
||||
|
||||
if let Some(expect) = file_data[suite_idx]["tests"][case_idx].get_mut("expect") {
|
||||
if let Some(obj) = expect.as_object_mut() {
|
||||
if errors.is_empty() {
|
||||
obj.remove("errors");
|
||||
} else {
|
||||
let serialized_errors = serde_json::to_value(errors).unwrap();
|
||||
obj.insert("errors".to_string(), serialized_errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let formatted_json = serde_json::to_string_pretty(&file_data).unwrap();
|
||||
fs::write(path, formatted_json).unwrap();
|
||||
}
|
||||
|
||||
pub fn update_sql_fixture(path: &str, suite_idx: usize, case_idx: usize, queries: &[String]) {
|
||||
use crate::tests::formatter::SqlFormatter;
|
||||
let content = fs::read_to_string(path).unwrap();
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
use super::expect::Expect;
|
||||
use crate::database::Database;
|
||||
use crate::tests::runner::update_validation_fixture;
|
||||
use crate::validator::Validator;
|
||||
use serde::Deserialize;
|
||||
use serde_json::Value;
|
||||
use std::env;
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@ -58,16 +61,16 @@ impl Case {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn run_validate(&self, db: Arc<Database>) -> Result<(), String> {
|
||||
use crate::validator::Validator;
|
||||
|
||||
pub fn run_validate(&self, db: Arc<Database>, path: &str, suite_idx: usize, case_idx: usize) -> Result<(), String> {
|
||||
let validator = Validator::new(db);
|
||||
|
||||
let schema_id = &self.schema_id;
|
||||
|
||||
let test_data = self.data.clone().unwrap_or(Value::Null);
|
||||
let result = validator.validate(schema_id, &test_data);
|
||||
|
||||
if env::var("UPDATE_EXPECT").is_ok() {
|
||||
update_validation_fixture(path, suite_idx, case_idx, &result.errors);
|
||||
}
|
||||
|
||||
if let Some(expect) = &self.expect {
|
||||
expect.assert_drop(&result)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user