Trusty: provenance library workspace (initial import)
This commit is contained in:
55
crates/adapters/trusty-postgres/tests/conformance.rs
Normal file
55
crates/adapters/trusty-postgres/tests/conformance.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
//! Runs the shared `Store` conformance suite against a live Postgres.
|
||||
//!
|
||||
//! Gated behind the TRUSTY_PG_URL env var. Set it to a libpq connection
|
||||
//! string that points at a disposable test DB, e.g.:
|
||||
//!
|
||||
//! TRUSTY_PG_URL="host=localhost user=postgres password=postgres dbname=trusty_test"
|
||||
//! cargo test -p trusty-postgres --test conformance -- --nocapture
|
||||
//!
|
||||
//! If TRUSTY_PG_URL is not set, the test prints a skip notice and exits
|
||||
//! clean. This keeps the default `cargo test --workspace` hermetic.
|
||||
|
||||
use trusty_postgres::TrustyPostgres;
|
||||
use trusty_store::testing::run_conformance;
|
||||
|
||||
const ENV_URL: &str = "TRUSTY_PG_URL";
|
||||
|
||||
fn reset_schema(store: &mut TrustyPostgres) {
|
||||
// Drop-and-recreate so the suite starts from a known-empty state.
|
||||
// Done by connecting to the same DB and issuing the drops directly.
|
||||
let url = std::env::var(ENV_URL).expect("TRUSTY_PG_URL must be set");
|
||||
let mut client = postgres::Client::connect(&url, postgres::NoTls).expect("connect");
|
||||
client
|
||||
.batch_execute(
|
||||
"DROP TABLE IF EXISTS chain_checkpoint CASCADE;
|
||||
DROP TABLE IF EXISTS producer_identity CASCADE;
|
||||
DROP TABLE IF EXISTS chain_tips CASCADE;
|
||||
DROP TABLE IF EXISTS hash_index CASCADE;
|
||||
DROP TABLE IF EXISTS provenance_envelope CASCADE;
|
||||
DROP TABLE IF EXISTS schema_meta CASCADE;",
|
||||
)
|
||||
.expect("drop tables");
|
||||
let _ = store; // store gets recreated below
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn postgres_passes_store_conformance() {
|
||||
let url = match std::env::var(ENV_URL) {
|
||||
Ok(v) => v,
|
||||
Err(_) => {
|
||||
eprintln!(
|
||||
"SKIP: set {} to run the conformance suite against a live Postgres",
|
||||
ENV_URL
|
||||
);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Initial open to ensure the tables exist.
|
||||
let mut store = TrustyPostgres::open(&url).expect("open");
|
||||
reset_schema(&mut store);
|
||||
// Re-open so apply_schema runs against a clean DB.
|
||||
let mut store = TrustyPostgres::open(&url).expect("re-open");
|
||||
|
||||
run_conformance(&mut store);
|
||||
}
|
||||
Reference in New Issue
Block a user