Skip to content

Commit

Permalink
use V16 for tests
Browse files Browse the repository at this point in the history
cleanup zip file binaries
another fix of windows test
  • Loading branch information
olexiyb committed Jun 13, 2024
1 parent 49153ed commit 522b641
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ async-trait = "0.1"
xz2 = "0.1"
tar = "0.4"


[dev-dependencies]
serial_test = "2.0.0"
env_logger = "0.10"
serial_test = "3"
env_logger = "0.11"

[[test]]
name = "migration_tokio"
Expand Down
13 changes: 9 additions & 4 deletions src/pg_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ impl PgAccess {

Self::create_db_dir_structure(database_dir).await?;
// pg_ctl executable
let mut pg_ctl = cache_dir.clone();
pg_ctl.push("bin/pg_ctl");
let pg_ctl = cache_dir.clone().join("bin").join("pg_ctl");
// initdb executable
let mut init_db = cache_dir.clone();
init_db.push("bin/initdb");
let init_db = cache_dir.clone().join("bin").join("initdb");
// postgres zip file
let mut zip_file_path = cache_dir.clone();
let platform = fetch_settings.platform();
Expand Down Expand Up @@ -168,6 +166,13 @@ impl PgAccess {
self.cache_dir.display()
);
pg_unpack::unpack_postgres(&self.zip_file_path, &self.cache_dir).await?;
tokio::fs::remove_file(&self.zip_file_path)
.await
.map_err(|e| PgEmbedError {
error_type: PgEmbedErrorType::PgCleanUpFailure,
source: Some(Box::new(e)),
message: None,
})?;

lock.insert(self.cache_dir.clone(), PgAcquisitionStatus::Finished);
Ok(())
Expand Down
17 changes: 13 additions & 4 deletions tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::path::PathBuf;
use std::time::Duration;

use env_logger::Env;
use futures::TryFutureExt;

use pg_embed::pg_enums::PgAuthMethod;
use pg_embed::pg_errors::PgEmbedError;
use pg_embed::pg_fetch::{PgFetchSettings, PG_V15};
use pg_embed::pg_errors::{PgEmbedError, PgEmbedErrorType};
use pg_embed::pg_fetch::{PgFetchSettings, PG_V16};
use pg_embed::postgres::{PgEmbed, PgSettings};

pub async fn setup(
Expand All @@ -17,9 +18,17 @@ pub async fn setup(
let _ = env_logger::Builder::from_env(Env::default().default_filter_or("info"))
.is_test(true)
.try_init();
let cache_dir = PathBuf::from("data_test").join("cache");
tokio::fs::create_dir_all(&cache_dir)
.map_err(|e| PgEmbedError {
error_type: PgEmbedErrorType::DirCreationError,
source: Some(Box::new(e)),
message: None,
})
.await?;
let pg_settings = PgSettings {
database_dir,
cache_dir: None,
cache_dir: Some(cache_dir),
port,
user: "postgres".to_string(),
password: "password".to_string(),
Expand All @@ -29,7 +38,7 @@ pub async fn setup(
migration_dir,
};
let fetch_settings = PgFetchSettings {
version: PG_V15,
version: PG_V16,
..Default::default()
};
let mut pg = PgEmbed::new(pg_settings, fetch_settings).await?;
Expand Down
4 changes: 2 additions & 2 deletions tests/postgres_tokio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use env_logger::Env;
use pg_embed::pg_access::PgAccess;
use pg_embed::pg_enums::{PgAuthMethod, PgServerStatus};
use pg_embed::pg_errors::PgEmbedError;
use pg_embed::pg_fetch::{PgFetchSettings, PG_V15};
use pg_embed::pg_fetch::{PgFetchSettings, PG_V16};
use pg_embed::postgres::{PgEmbed, PgSettings};
use std::time::Duration;

Expand Down Expand Up @@ -156,7 +156,7 @@ async fn postgres_server_timeout() -> Result<(), PgEmbedError> {
migration_dir: None,
};
let fetch_settings = PgFetchSettings {
version: PG_V15,
version: PG_V16,
..Default::default()
};
let mut pg = PgEmbed::new(pg_settings, fetch_settings).await?;
Expand Down

0 comments on commit 522b641

Please sign in to comment.