diff --git a/Cargo.lock b/Cargo.lock index 4c8f5f5f..0867bece 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1757,6 +1757,7 @@ dependencies = [ "serde", "tempfile", "testcontainers", + "testcontainers-modules", "tokio", "tracing", ] diff --git a/integrationtests/Cargo.toml b/integrationtests/Cargo.toml index 282663da..3e07fdf7 100644 --- a/integrationtests/Cargo.toml +++ b/integrationtests/Cargo.toml @@ -27,6 +27,7 @@ bitcoin_hashes = { version = "0.12.0", default-features = false } secp256k1 = { version = "0.27.0", default-features = false, features = ["recovery", "alloc", "rand"] } tracing = "0.1.40" testcontainers = "0.15.0" +testcontainers-modules = { version = "0.3.4", features = ["postgres"] } [target.'cfg(not(target_family="wasm"))'.dependencies] tokio = { version = "1.35.1", features = ["sync", "rt"] } diff --git a/integrationtests/tests/tests.rs b/integrationtests/tests/tests.rs index 1e88bc6d..1e74d5ba 100644 --- a/integrationtests/tests/tests.rs +++ b/integrationtests/tests/tests.rs @@ -9,11 +9,10 @@ use mokshamint::lightning::lnbits::LnbitsLightningSettings; use mokshamint::lightning::LightningType; use mokshamint::mint::MintBuilder; use reqwest::Url; -use std::collections::HashMap; use std::thread; use std::time::Duration; -use testcontainers::core::WaitFor; -use testcontainers::{clients, Image}; +use testcontainers::{clients, RunnableImage}; +use testcontainers_modules::postgres::Postgres; use tokio::runtime::Runtime; use tokio::time::{sleep_until, Instant}; @@ -23,7 +22,9 @@ pub fn test_integration() -> anyhow::Result<()> { // create postgres container that will be destroyed after the test is done let docker = clients::Cli::default(); - let node = docker.run(Postgres::default()); + let node = Postgres::default().with_host_auth(); + let img = RunnableImage::from(node).with_tag("16.2-alpine"); + let node = docker.run(img); let host_port = node.get_host_port_ipv4(5432); // start lnbits @@ -41,7 +42,7 @@ pub fn test_integration() -> anyhow::Result<()> { rt.block_on(async { let db_config = DatabaseConfig { db_url: format!( - "postgres://postgres:postgres@localhost:{}/test-db", + "postgres://postgres:postgres@localhost:{}/postgres", host_port ), }; @@ -164,41 +165,3 @@ fn read_fixture(name: &str) -> anyhow::Result { let raw_token = std::fs::read_to_string(format!("{base_dir}/tests/fixtures/{name}"))?; Ok(raw_token.trim().to_string()) } - -#[derive(Debug)] -pub struct Postgres { - env_vars: HashMap, -} - -impl Default for Postgres { - fn default() -> Self { - let mut env_vars = HashMap::new(); - env_vars.insert("POSTGRES_DB".to_owned(), "postgres".to_owned()); - env_vars.insert("POSTGRES_HOST_AUTH_METHOD".into(), "trust".into()); - env_vars.insert("POSTGRES_DB".into(), "test-db".into()); - - Self { env_vars } - } -} - -impl Image for Postgres { - type Args = (); - - fn name(&self) -> String { - "postgres".to_owned() - } - - fn tag(&self) -> String { - "15.3".to_owned() - } - - fn ready_conditions(&self) -> Vec { - vec![WaitFor::message_on_stderr( - "database system is ready to accept connections", - )] - } - - fn env_vars(&self) -> Box + '_> { - Box::new(self.env_vars.iter()) - } -}