This commit is contained in:
Bojan Serafimov
2022-08-18 13:14:05 -04:00
parent 3e0b57e766
commit fe1b471cfc
2 changed files with 11 additions and 19 deletions

View File

@@ -4,7 +4,6 @@ mod tests {
use tokio_postgres::NoTls;
use pg_bin::LocalPostgres;
use pg_bin::PgProtocol;
#[tokio::test]
async fn test_postgres_select_1() -> anyhow::Result<()> {
@@ -15,7 +14,7 @@ mod tests {
// Get a postgres
let mut postgres = LocalPostgres::new(pg_datadir, pg_prefix);
postgres.start();
let config = postgres.conn_info();
let config = postgres.admin_conn_info();
if let Err(e) = config.connect(NoTls).await {
eprintln!("error error {:?}", e);

View File

@@ -2,16 +2,11 @@
use std::{fs::{File, remove_dir_all}, path::PathBuf, process::{Child, Command, Stdio}, time::Duration};
use std::io::Write;
// TODO put these in a different mod
type Port = u16;
pub trait PgProtocol {
fn conn_info(&self) -> tokio_postgres::Config;
}
pub struct LocalPostgres {
datadir: PathBuf,
pg_prefix: PathBuf,
port: Port,
port: u16,
running: Option<Child>,
}
@@ -56,18 +51,8 @@ impl LocalPostgres {
std::thread::sleep(Duration::from_millis(300));
}
}
impl Drop for LocalPostgres {
fn drop(&mut self) {
if let Some(mut child) = self.running.take() {
child.kill().expect("failed to kill child");
}
}
}
impl PgProtocol for LocalPostgres {
fn conn_info(&self) -> tokio_postgres::Config {
pub fn admin_conn_info(&self) -> tokio_postgres::Config {
// I don't like this, but idk what else to do
let whoami = Command::new("whoami").output().unwrap().stdout;
let user = String::from_utf8_lossy(&whoami);
@@ -82,3 +67,11 @@ impl PgProtocol for LocalPostgres {
config
}
}
impl Drop for LocalPostgres {
fn drop(&mut self) {
if let Some(mut child) = self.running.take() {
child.kill().expect("failed to kill child");
}
}
}