Skip to content

Commit

Permalink
Attempt to fix intermittent config_from_env() test failures by ensuri…
Browse files Browse the repository at this point in the history
…ng envvars are reset before unwrapping/asserting
  • Loading branch information
trxcllnt committed Oct 18, 2024
1 parent 4a1e674 commit a417a4f
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1315,16 +1315,18 @@ fn test_s3_no_credentials_conflict() {
env::set_var("AWS_ACCESS_KEY_ID", "aws-access-key-id");
env::set_var("AWS_SECRET_ACCESS_KEY", "aws-secret-access-key");

let error = config_from_env().unwrap_err();
assert_eq!(
"If setting S3 credentials, SCCACHE_S3_NO_CREDENTIALS must not be set.",
error.to_string()
);
let cfg = config_from_env();

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");
env::remove_var("AWS_ACCESS_KEY_ID");
env::remove_var("AWS_SECRET_ACCESS_KEY");

let error = cfg.unwrap_err();
assert_eq!(
"If setting S3 credentials, SCCACHE_S3_NO_CREDENTIALS must not be set.",
error.to_string()
);
}

#[test]
Expand All @@ -1333,14 +1335,16 @@ fn test_s3_no_credentials_invalid() {
env::set_var("SCCACHE_S3_NO_CREDENTIALS", "yes");
env::set_var("SCCACHE_BUCKET", "my-bucket");

let error = config_from_env().unwrap_err();
let cfg = config_from_env();

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");

let error = cfg.unwrap_err();
assert_eq!(
"SCCACHE_S3_NO_CREDENTIALS must be 'true', 'on', '1', 'false', 'off' or '0'.",
error.to_string()
);

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");
}

#[test]
Expand All @@ -1349,7 +1353,12 @@ fn test_s3_no_credentials_valid_true() {
env::set_var("SCCACHE_S3_NO_CREDENTIALS", "true");
env::set_var("SCCACHE_BUCKET", "my-bucket");

let env_cfg = config_from_env().unwrap();
let cfg = config_from_env();

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");

let env_cfg = cfg.unwrap();
match env_cfg.cache.s3 {
Some(S3CacheConfig {
ref bucket,
Expand All @@ -1361,9 +1370,6 @@ fn test_s3_no_credentials_valid_true() {
}
None => unreachable!(),
};

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");
}

#[test]
Expand All @@ -1372,7 +1378,12 @@ fn test_s3_no_credentials_valid_false() {
env::set_var("SCCACHE_S3_NO_CREDENTIALS", "false");
env::set_var("SCCACHE_BUCKET", "my-bucket");

let env_cfg = config_from_env().unwrap();
let cfg = config_from_env();

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");

let env_cfg = cfg.unwrap();
match env_cfg.cache.s3 {
Some(S3CacheConfig {
ref bucket,
Expand All @@ -1384,14 +1395,10 @@ fn test_s3_no_credentials_valid_false() {
}
None => unreachable!(),
};

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_BUCKET");
}

#[test]
fn test_gcs_service_account() {
env::set_var("SCCACHE_S3_NO_CREDENTIALS", "false");
env::set_var("SCCACHE_GCS_BUCKET", "my-bucket");
env::set_var("SCCACHE_GCS_SERVICE_ACCOUNT", "[email protected]");
env::set_var("SCCACHE_GCS_RW_MODE", "READ_WRITE");
Expand All @@ -1411,7 +1418,6 @@ fn test_gcs_service_account() {
None => unreachable!(),
};

env::remove_var("SCCACHE_S3_NO_CREDENTIALS");
env::remove_var("SCCACHE_GCS_BUCKET");
env::remove_var("SCCACHE_GCS_SERVICE_ACCOUNT");
env::remove_var("SCCACHE_GCS_RW_MODE");
Expand Down

0 comments on commit a417a4f

Please sign in to comment.