improved compile schema error messages
This commit is contained in:
36
src/tests.rs
36
src/tests.rs
@ -251,26 +251,24 @@ fn test_cache_invalid_json_schema() {
|
||||
|
||||
let cache_result = cache_json_schema(schema_id, jsonb(invalid_schema));
|
||||
|
||||
// Manually check the structure for cache_json_schema failure
|
||||
let json_result = &cache_result.0;
|
||||
let success = json_result.get("success").and_then(Value::as_bool);
|
||||
let error_obj = json_result.get("error").and_then(Value::as_object);
|
||||
// Expect 2 leaf errors because the meta-schema validation fails at the type value
|
||||
// and within the type array itself.
|
||||
assert_failure_with_json!(
|
||||
cache_result,
|
||||
2, // Expect exactly two leaf errors
|
||||
"value must be one of", // Check message substring (present in both)
|
||||
"Caching invalid schema should fail with specific meta-schema validation errors."
|
||||
);
|
||||
|
||||
if success != Some(false) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected failure, success was not false): Caching invalid schema should fail.\nResult JSON:\n{}", pretty_json);
|
||||
}
|
||||
if error_obj.is_none() {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (expected 'error' object, but none found): Caching invalid schema should return an error object.\nResult JSON:\n{}", pretty_json);
|
||||
}
|
||||
// Check specific fields within the error object
|
||||
let message = error_obj.unwrap().get("message").and_then(Value::as_str);
|
||||
// Updated check based on the actual error message seen in the logs
|
||||
if message.map_or(true, |m| !m.contains("failed validation against its metaschema") || !m.contains("/type/0': value must be one of")) {
|
||||
let pretty_json = serde_json::to_string_pretty(&json_result).unwrap_or_else(|_| format!("(Failed to pretty-print JSON: {:?})", json_result));
|
||||
panic!("Assertion Failed (error message mismatch): Expected metaschema validation failure message containing '/type/0' error detail.\nResult JSON:\n{}", pretty_json);
|
||||
}
|
||||
// Ensure the error is an array and check specifics
|
||||
let error_array = cache_result.0["error"].as_array().expect("Error field should be an array");
|
||||
assert_eq!(error_array.len(), 2);
|
||||
// Note: Order might vary depending on boon's internal processing, check both possibilities or sort.
|
||||
// Assuming the order shown in the logs for now:
|
||||
assert_eq!(error_array[0]["instance_path"], "/type");
|
||||
assert!(error_array[0]["message"].as_str().unwrap().contains("value must be one of"));
|
||||
assert_eq!(error_array[1]["instance_path"], "/type/0");
|
||||
assert!(error_array[1]["message"].as_str().unwrap().contains("value must be one of"));
|
||||
}
|
||||
|
||||
#[pg_test]
|
||||
|
||||
Reference in New Issue
Block a user