Skip to content

Commit

Permalink
Removed Once Cell (#52)
Browse files Browse the repository at this point in the history
* Removed Once Cell test dependency
  • Loading branch information
tnewman authored Apr 1, 2024
1 parent ef811c4 commit b252fcc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ aws-config = "1.1.9"
aws-sdk-s3 = "1.21.0"

[dev-dependencies]
once_cell = "1.19.0"
rand = "0.8"
tempfile = "3.10"
testcontainers-modules = { version = "0.3.6", features = ["minio"] }
24 changes: 15 additions & 9 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use dray::{
error::Error,
ssh_server::DraySshServer,
};

use once_cell::sync::Lazy;
use rand::Rng;
use std::sync::OnceLock;
use tempfile::NamedTempFile;
use testcontainers_modules::{
minio::MinIO,
Expand All @@ -31,11 +30,9 @@ struct TestClient {
bucket: String,
}

static DOCKER_CLI: Lazy<testcontainers::clients::Cli> =
Lazy::new(testcontainers::clients::Cli::default);
static DOCKER_CLI: OnceLock<testcontainers::clients::Cli> = OnceLock::new();

static MINIO: Lazy<Container<'_, MinIO>> =
Lazy::new(|| DOCKER_CLI.run(testcontainers_modules::minio::MinIO::default()));
static MINIO: OnceLock<Container<'_, MinIO>> = OnceLock::new();

static INIT_TRACING: Once = Once::new();

Expand All @@ -45,7 +42,16 @@ async fn setup() -> TestClient {
tracing::subscriber::set_global_default(subscriber).unwrap();
});

let dray_config = get_config().await;
DOCKER_CLI.get_or_init(testcontainers::clients::Cli::default);

let minio = MINIO.get_or_init(|| {
DOCKER_CLI
.get()
.expect("Docker is initialized")
.run(testcontainers_modules::minio::MinIO::default())
});

let dray_config = get_config(minio).await;

let s3_client = create_s3_client(&dray_config).await;

Expand All @@ -72,7 +78,7 @@ async fn setup() -> TestClient {
test_client
}

async fn get_config() -> DrayConfig {
async fn get_config(minio: &Container<'_, MinIO>) -> DrayConfig {
let port = get_free_port()
.await
.expect("Could not find a free port to bind!");
Expand All @@ -90,7 +96,7 @@ async fn get_config() -> DrayConfig {
s3: S3Config {
endpoint_name: Some(format!(
"http://localhost:{}",
MINIO.get_host_port_ipv4(9000)
minio.get_host_port_ipv4(9000)
)),
endpoint_region: "custom".to_string(),
bucket: format!("integration-test-{}", rng.gen::<u32>()),
Expand Down

0 comments on commit b252fcc

Please sign in to comment.