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

refactor: replace dirs crate with etcetera #736

Merged
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
2 changes: 1 addition & 1 deletion testcontainers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ bollard = { version = "0.17.0", features = ["ssl"] }
bollard-stubs = "=1.45.0-rc.26.0.1"
bytes = "1.6.0"
conquer-once = { version = "0.4", optional = true }
dirs = "5.0.1"
docker_credential = "1.3.1"
either = "1.12.0"
etcetera = "0.8.0"
futures = "0.3"
log = "0.4"
memchr = "2.7.2"
Expand Down
14 changes: 11 additions & 3 deletions testcontainers/src/core/env/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
str::FromStr,
};

use dirs::{home_dir, runtime_dir};
use etcetera::BaseStrategy;

use crate::core::env::GetEnvValue;

Expand Down Expand Up @@ -62,7 +62,7 @@ struct TestcontainersProperties {
#[cfg(feature = "properties-config")]
impl TestcontainersProperties {
async fn load() -> Option<Result<Self, ConfigurationError>> {
let home_dir = dirs::home_dir()?;
let home_dir = home_dir()?;
let properties_path = home_dir.join(TESTCONTAINERS_PROPERTIES);

let content = tokio::fs::read(properties_path).await.ok()?;
Expand Down Expand Up @@ -195,6 +195,14 @@ fn validate_path(path: String) -> Option<String> {
}
}

fn home_dir() -> Option<PathBuf> {
etcetera::home_dir().ok()
}

fn runtime_dir() -> Option<PathBuf> {
etcetera::choose_base_strategy().ok()?.runtime_dir()
}

/// Read the Docker authentication configuration in the following order:
///
/// 1. `DOCKER_AUTH_CONFIG` environment variable, unmarshalling the string value from its JSON representation and using it as the Docker config.
Expand All @@ -210,7 +218,7 @@ where
let mut path_to_config = match E::get_env_value("DOCKER_CONFIG").map(PathBuf::from) {
Some(path_to_config) => path_to_config,
None => {
let home_dir = dirs::home_dir()?;
let home_dir = home_dir()?;
home_dir.join(DEFAULT_DOCKER_CONFIG_PATH)
}
};
Expand Down
Loading