#![cfg(any(feature = "libpq", feature = "rustls-tls"))]
use pg_walstream::{BaseBackupOptions, PgReplicationConnection};
use tracing::warn;
fn replication_conn_string() -> String {
std::env::var("DATABASE_URL").unwrap_or_else(|_| {
"postgresql://postgres:postgres@localhost:5432/test_walstream?replication=database"
.to_string()
})
}
fn regular_conn_string() -> String {
std::env::var("DATABASE_URL_REGULAR").unwrap_or_else(|_| {
let repl = replication_conn_string();
repl.replace("?replication=database", "")
.replace("&replication=database", "")
})
}
fn init_tracing() {
let _ = tracing_subscriber::fmt()
.with_max_level(tracing::Level::INFO)
.try_init();
}
fn server_version_num(conn: &mut PgReplicationConnection) -> i64 {
conn.exec("SHOW server_version_num")
.expect("SHOW server_version_num")
.get_value(0, 0)
.expect("server_version_num value present")
.parse()
.expect("server_version_num is numeric")
}
#[test]
#[ignore = "requires live PostgreSQL 15+"]
fn test_base_backup_options_accepted() {
init_tracing();
let mut regular =
PgReplicationConnection::connect(®ular_conn_string()).expect("regular connection");
let version = server_version_num(&mut regular);
if version < 150000 {
warn!(
"skip BASE_BACKUP options test: server_version_num {version} < 150000 \
(the parenthesized BASE_BACKUP grammar is PG15+)"
);
return;
}
let opts = BaseBackupOptions {
label: Some("walstream_it".to_string()),
progress: true,
checkpoint: Some("fast".to_string()),
max_rate: Some(1024),
wal: true,
wait: false,
verify_checksums: true,
manifest: Some("no".to_string()),
..Default::default()
};
let mut repl = PgReplicationConnection::connect(&replication_conn_string())
.expect("replication connection");
match repl.base_backup(&opts) {
Ok(_) => { }
Err(e) => panic!("server must accept the generated BASE_BACKUP options: {e}"),
}
drop(repl);
}