Skip to content

Commit

Permalink
make tests more robust to other environmental settings
Browse files Browse the repository at this point in the history
  • Loading branch information
emcake committed Feb 25, 2024
1 parent c48476b commit b8c3a58
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions crates/aws/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,19 +669,23 @@ mod tests {
fn when_merging_with_env_unsupplied_options_are_added() {
ScopedEnv::run(|| {
let raw_options = hashmap! {};

std::env::set_var(s3_constants::AWS_ACCESS_KEY_ID, "env_key");
std::env::set_var(s3_constants::AWS_ENDPOINT_URL, "env_key");
std::env::set_var(s3_constants::AWS_SECRET_ACCESS_KEY, "env_key");
std::env::set_var(s3_constants::AWS_REGION, "env_key");
let keys_under_test = vec![
AmazonS3ConfigKey::Endpoint,
AmazonS3ConfigKey::SecretAccessKey,
AmazonS3ConfigKey::Region,
AmazonS3ConfigKey::AccessKeyId,
];

for k in keys_under_test.iter() {
std::env::set_var(k.as_ref(), "env_key");
}

let combined_options =
S3ObjectStoreFactory {}.with_env_s3(&StorageOptions(raw_options));

assert_eq!(combined_options.0.len(), 4);

for v in combined_options.0.values() {
assert_eq!(v, "env_key");
for k in keys_under_test.iter() {
assert!(combined_options.0.contains_key(k.as_ref()));
assert_eq!(&combined_options.0[k.as_ref()], "env_key");
}
})
}
Expand All @@ -690,23 +694,28 @@ mod tests {
#[serial]
fn when_merging_with_env_supplied_options_take_precedence() {
ScopedEnv::run(|| {
let raw_options = hashmap! {
"AWS_ACCESS_KEY_ID".to_string() => "options_key".to_string(),
"AWS_ENDPOINT_URL".to_string() => "options_key".to_string(),
"AWS_SECRET_ACCESS_KEY".to_string() => "options_key".to_string(),
"AWS_REGION".to_string() => "options_key".to_string()
};

std::env::set_var("aws_access_key_id", "env_key");
std::env::set_var("aws_endpoint", "env_key");
std::env::set_var("aws_secret_access_key", "env_key");
std::env::set_var("aws_region", "env_key");
let keys_under_test = vec![
AmazonS3ConfigKey::Endpoint,
AmazonS3ConfigKey::SecretAccessKey,
AmazonS3ConfigKey::Region,
AmazonS3ConfigKey::AccessKeyId,
];

let raw_options = keys_under_test
.iter()
.map(|k| (k.as_ref().to_string(), "options_key".to_string()))
.collect();

for k in keys_under_test.iter() {
std::env::set_var(k.as_ref(), "env_key");
}

let combined_options =
S3ObjectStoreFactory {}.with_env_s3(&StorageOptions(raw_options));

for v in combined_options.0.values() {
assert_eq!(v, "options_key");
for k in keys_under_test.iter() {
assert!(combined_options.0.contains_key(k.as_ref()));
assert_eq!(&combined_options.0[k.as_ref()], "options_key");
}
});
}
Expand Down

0 comments on commit b8c3a58

Please sign in to comment.