diff --git a/src/lib.rs b/src/lib.rs index 2466f20..e799eeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -293,34 +293,31 @@ fn validate(id: &str, schemas: &[Value], instance: Value) -> Result Value { + pub fn user_schema() -> Value { let bytes = include_bytes!("../eg/user-profile.schema.json"); assert!(!bytes.is_empty()); serde_json::from_slice(bytes).unwrap() } - fn addr_schema() -> Value { + pub fn addr_schema() -> Value { let bytes = include_bytes!("../eg/address.schema.json"); assert!(!bytes.is_empty()); serde_json::from_slice(bytes).unwrap() } +} + +// Rust-only tests. +#[cfg(test)] +mod test { + use super::*; + use crate::test_util::*; + use serde_json::json; + use std::error::Error; // Make sure our Draft enum converts properly into boon's. #[test] @@ -509,6 +506,24 @@ mod tests { Ok(()) } +} + +// pgrx tests. +#[cfg(any(test, feature = "pg_test"))] +#[pg_schema] +mod tests { + use super::*; + use crate::test_util::*; + use pgrx::pg_sys::panic::CaughtError::PostgresError; + use pgrx::{spi::SpiError, Json, JsonB}; + use serde_json::json; + + // Enum used to record handling expected errors. + #[derive(Debug, Eq, PartialEq)] + enum ErrorCaught { + True, + False, + } #[pg_test] fn test_jsonschema_is_valid() {