#![cfg(feature = "postgres")]
use std::process::Command;
use std::sync::Arc;
use testcontainers_modules::postgres::Postgres;
use testcontainers_modules::testcontainers::runners::AsyncRunner;
use wasm_sql::sqldb::sqlx::postgres::PgPoolOptions;
use wasm_sql::sqldb::SqlDB;
#[macro_use]
mod common;
async fn instantiate() -> anyhow::Result<common::TestHarness> {
let container = Postgres::default().start().await?;
let host = container.get_host().await?;
let port = container.get_host_port_ipv4(5432).await?;
let database_url = format!("postgres://postgres:postgres@{}:{}/postgres", host, port);
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await?;
common::TestHarness::new(Arc::new(SqlDB::new(pool)), container)
}
#[ctor::ctor]
fn build_guest_component() {
let status = Command::new("cargo")
.args([
"+nightly",
"build",
"--manifest-path",
"tests/postgres-tests/Cargo.toml",
"--target",
"wasm32-wasip2",
])
.status()
.expect("Failed to run cargo build for postgres guest component");
if !status.success() {
panic!("Postgres guest component build failed");
}
}
mod bindings {
wasmtime::component::bindgen!({
world: "test:postgres/postgres-tests",
path: ["./wit", "./wit/postgres", "./tests/postgres-tests/wit"],
});
}
const WASM_PATH: &str = "target/wasm32-wasip2/debug/postgres_tests.wasm";
wasm_sql_tests!(bindings::PostgresTests, test_postgres_tests {
begin_transaction_commit,
transaction_rollback_on_drop,
acquire_connection,
connection_begin_transaction,
release_connection,
test_codec_int16,
test_codec_int32,
test_codec_int64,
test_codec_float32,
test_codec_float64,
test_codec_string,
test_codec_bool,
test_codec_json,
test_codec_uuid,
test_codec_hstore,
test_codec_date,
test_codec_time,
test_codec_timestamp,
test_codec_timestamptz,
test_codec_interval,
test_codec_inet,
test_codec_cidr,
test_codec_macaddr,
test_codec_numeric,
test_codec_nulls,
});