Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to testcontainers-rs 0.15, 0.5 backport #2085

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ serde_json = "1.0.107"
serde_test = "1.0.175"
serde_yaml = "0.9.25"
rstest = "0.17.0"
testcontainers = "0.15.0"
thiserror = "1.0"
tokio = { version = "1.32", features = ["full", "tracing"] }
trillium = "0.2.9"
Expand Down
2 changes: 1 addition & 1 deletion aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ serde_urlencoded = "0.7.1"
serde_yaml.workspace = true
signal-hook = "0.3.17"
signal-hook-tokio = { version = "0.3.1", features = ["futures-v0_3"] }
testcontainers = { version = "0.14.0", optional = true }
testcontainers = { workspace = true, optional = true }
thiserror.workspace = true
tokio.workspace = true
tokio-postgres = { version = "0.7.10", features = ["with-chrono-0_4", "with-serde_json-1", "with-uuid-1", "array-impls"] }
Expand Down
2 changes: 1 addition & 1 deletion aggregator_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
sqlx = { version = "0.7.2", optional = true, features = ["runtime-tokio-rustls", "migrate", "postgres"] }
testcontainers = { version = "0.14.0", optional = true }
testcontainers = { workspace = true, optional = true }
thiserror.workspace = true
tokio.workspace = true
tokio-postgres = { version = "0.7.10", features = ["with-chrono-0_4", "with-serde_json-1", "with-uuid-1", "array-impls"] }
Expand Down
7 changes: 3 additions & 4 deletions aggregator_core/src/datastore/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
test_util::noop_meter,
};
use deadpool_postgres::{Manager, Pool};
use janus_core::time::Clock;
use janus_core::{test_util::testcontainers::Postgres, time::Clock};
use lazy_static::lazy_static;
use rand::{distributions::Standard, random, thread_rng, Rng};
use ring::aead::{LessSafeKey, UnboundKey, AES_128_GCM};
Expand All @@ -17,7 +17,7 @@ use std::{
sync::{Arc, Barrier, Weak},
thread::{self, JoinHandle},
};
use testcontainers::{images::postgres::Postgres, RunnableImage};
use testcontainers::RunnableImage;
use tokio::sync::{oneshot, Mutex};
use tokio_postgres::{connect, Config, NoTls};
use tracing::trace;
Expand Down Expand Up @@ -56,8 +56,7 @@ impl EphemeralDatabase {
move || {
// Start an instance of Postgres running in a container.
let container_client = testcontainers::clients::Cli::default();
let db_container = container_client
.run(RunnableImage::from(Postgres::default()).with_tag("14-alpine"));
let db_container = container_client.run(RunnableImage::from(Postgres::default()));
const POSTGRES_DEFAULT_PORT: u16 = 5432;
let port_number = db_container.get_host_port_ipv4(POSTGRES_DEFAULT_PORT);
trace!("Postgres container is up with port {port_number}");
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ serde_json = { workspace = true, optional = true }
serde_yaml.workspace = true
stopper = { version = "0.2.0", optional = true }
tempfile = { version = "3", optional = true }
testcontainers = { version = "0.14", optional = true }
testcontainers = { workspace = true, optional = true }
thiserror.workspace = true
tokio = { workspace = true, features = ["macros", "net", "rt"] }
tokio-stream = { version = "0.1.14", features = ["net"], optional = true }
Expand Down
51 changes: 49 additions & 2 deletions core/src/test_util/testcontainers.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Testing functionality that interacts with the testcontainers library.

use std::sync::{Arc, Mutex, Weak};
use testcontainers::clients::Cli;
use std::{
collections::HashMap,
sync::{Arc, Mutex, Weak},
};
use testcontainers::{clients::Cli, core::WaitFor, Image};

/// Returns a container client, possibly shared with other callers to this function.
pub fn container_client() -> Arc<Cli> {
Expand All @@ -18,3 +21,47 @@ pub fn container_client() -> Arc<Cli> {
client
})
}

/// A [`testcontainers::Image`] that provides a Postgres server.
#[derive(Debug)]
pub struct Postgres {
env_vars: HashMap<String, String>,
}

impl Postgres {
const NAME: &str = "postgres";
const TAG: &str = "14-alpine";
}

impl Default for Postgres {
fn default() -> Self {
Self {
env_vars: HashMap::from([
("POSTGRES_DB".to_owned(), "postgres".to_owned()),
("POSTGRES_HOST_AUTH_METHOD".to_owned(), "trust".to_owned()),
]),
}
}
}

impl Image for Postgres {
type Args = ();

fn name(&self) -> String {
Self::NAME.to_owned()
}

fn tag(&self) -> String {
Self::TAG.to_owned()
}

fn ready_conditions(&self) -> Vec<WaitFor> {
Vec::from([WaitFor::message_on_stderr(
"database system is ready to accept connections",
)])
}

fn env_vars(&self) -> Box<dyn Iterator<Item = (&String, &String)> + '_> {
Box::new(self.env_vars.iter())
}
}
2 changes: 1 addition & 1 deletion integration_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ rand = "0.8"
reqwest = { version = "0.11", default-features = false, features = ["rustls-tls"] }
serde.workspace = true
serde_json = "1.0.107"
testcontainers = "0.14.0"
testcontainers.workspace = true
tokio.workspace = true
url = { version = "2.4.1", features = ["serde"] }

Expand Down
2 changes: 1 addition & 1 deletion integration_tests/src/daphne.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
process::{Command, Stdio},
thread::panicking,
};
use testcontainers::{clients::Cli, images::generic::GenericImage, Container, RunnableImage};
use testcontainers::{clients::Cli, Container, GenericImage, RunnableImage};

const DAPHNE_HELPER_IMAGE_NAME_AND_TAG: &str = "cloudflare/daphne-worker-helper:sha-f6b3ef1";

Expand Down
2 changes: 1 addition & 1 deletion interop_binaries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ring = "0.17.0"
serde.workspace = true
serde_json = "1.0.107"
sqlx = { version = "0.7.2", features = ["runtime-tokio-rustls", "migrate", "postgres"] }
testcontainers = { version = "0.14" }
testcontainers.workspace = true
tokio.workspace = true
tracing = "0.1.37"
tracing-log = "0.1.3"
Expand Down
Loading