Skip to content

Commit

Permalink
chore(aws): fix unintended test failure of `aws::missing_any_credenti…
Browse files Browse the repository at this point in the history
…als` (starship#4805)

chore(aws): fix unintended test failure of `aws::missing_any_credentials` 

Because its mocking is not enough, The test may unintentionally fail
if `~/.aws/credentials` exists.
This commit fixes this issue by mocking `credentials` file as well.
  • Loading branch information
kawaemon authored Jan 11, 2023
1 parent e88484d commit 64e0208
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/modules/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,10 +802,14 @@ aws_secret_access_key=dummy
#[test]
fn missing_any_credentials() -> io::Result<()> {
let dir = tempfile::tempdir()?;

let credential_path = dir.path().join("credentials");
File::create(&credential_path)?;

let config_path = dir.path().join("config");
let mut file = File::create(&config_path)?;
let mut config_file = File::create(&config_path)?;

file.write_all(
config_file.write_all(
"[default]
region = us-east-1
output = json
Expand All @@ -818,6 +822,10 @@ region = us-east-2

let actual = ModuleRenderer::new("aws")
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
.env(
"AWS_CREDENTIALS_FILE",
credential_path.to_string_lossy().as_ref(),
)
.collect();
let expected = None;

Expand Down

0 comments on commit 64e0208

Please sign in to comment.