Skip to content

Commit

Permalink
Shorten pg test directories
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Feb 26, 2024
1 parent 820df4a commit 037c822
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions butane_test_helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ repository = "https://github.com/Electron100/butane"
documentation = "https://docs.rs/butane/"

[dependencies]
block-id = "0.2"
butane_core = { features = ["pg", "sqlite"], workspace = true }
libc = "0.2"
once_cell = { workspace = true }
postgres = { features = ["with-geo-types-0_7"], workspace = true }
rand = { workspace = true }
uuid = { features = ["v4"], workspace = true }

[package.metadata.release]
Expand Down
7 changes: 5 additions & 2 deletions butane_test_helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::sync::Mutex;
use butane_core::db::{connect, get_backend, pg, sqlite, Backend, Connection, ConnectionSpec};
use butane_core::migrations::{self, MemMigrations, Migration, Migrations, MigrationsMut};
use once_cell::sync::Lazy;
use block_id::{Alphabet, BlockId};
use uuid::Uuid;

pub fn pg_connection() -> (Connection, PgSetupData) {
Expand Down Expand Up @@ -52,12 +53,13 @@ pub struct PgSetupData {
}

pub fn create_tmp_server() -> PgServerState {
eprintln!("create tmp server");
let seed: u128 = rand::random::<u64>() as u128;
let instance_id = BlockId::new(Alphabet::alphanumeric(), seed, 5).encode_string(0).unwrap();
// create a temporary directory
let dir = std::env::current_dir()
.unwrap()
.join("tmp_pg")
.join(Uuid::new_v4().to_string());
.join(instance_id);
std::fs::create_dir_all(&dir).unwrap();

// Run initdb to create a postgres cluster in our temporary director
Expand Down Expand Up @@ -95,6 +97,7 @@ pub fn create_tmp_server() -> PgServerState {
loop {
buf.clear();
stderr.read_line(&mut buf).unwrap();
eprintln!("{buf}");
if buf.contains("ready to accept connections") {
break;
}
Expand Down

0 comments on commit 037c822

Please sign in to comment.