Repository: starship/starship
File: src/modules/aws.rs (Rust)

Code before:
            let actual = ModuleRenderer::new("aws")
                .env("AWS_PROFILE", "astronauts")
                .env("AWS_REGION", "ap-northeast-2")
                .env(
                    "AWS_SHARED_CREDENTIALS_FILE",
                    credentials_path.to_string_lossy().as_ref(),
                )
                .collect();

            let actual_variant = ModuleRenderer::new("aws")
                .env("AWS_PROFILE", "astronauts")
                .env("AWS_REGION", "ap-northeast-2")
                .env(
                    "AWS_CREDENTIALS_FILE",
                    credentials_path.to_string_lossy().as_ref(),
                )
                .collect();

            assert_eq!(
                actual, actual_variant,
                "both AWS_SHARED_CREDENTIALS_FILE and AWS_CREDENTIALS_FILE should work"
            );

            // In principle, "30m" should be correct. However, bad luck in scheduling
            // on shared runners may delay it. Allow for up to 2 seconds of delay.
            let possible_values = ["30m", "29m59s", "29m58s"];
            let possible_values = possible_values.map(|duration| {
                let segment_colored = format!("☁️  astronauts (ap-northeast-2) [{}] ", duration);
                Some(format!(
                    "on {}",
                    Color::Yellow.bold().paint(segment_colored)
                ))
            });

            assert!(possible_values.contains(&actual));
        });

        dir.close()
    }

    #[test]
    fn profile_and_region_set_show_duration() {
        let actual = ModuleRenderer::new("aws")
            .env("AWS_PROFILE", "astronauts")
            .env("AWS_REGION", "ap-northeast-2")
            .env("AWS_ACCESS_KEY_ID", "dummy")
            .collect();
        let expected = Some(format!(
            "on {}",
            Color::Yellow
                .bold()

Review comment (bug):
Despite #4455 this test has been failing intermittently, so let's increase the range a bit to avoid worsening the situation:
```suggestion
            // In principle, "30m" should be correct. However, bad luck in scheduling
            // on shared runners may delay it. Allow a few seconds of skew.
            let possible_values = [
                "30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s",
            ];
```

Code after:
            let actual = ModuleRenderer::new("aws")
                .env("AWS_PROFILE", "astronauts")
                .env("AWS_REGION", "ap-northeast-2")
                .env(
                    "AWS_SHARED_CREDENTIALS_FILE",
                    credentials_path.to_string_lossy().as_ref(),
                )
                .collect();

            let actual_variant = ModuleRenderer::new("aws")
                .env("AWS_PROFILE", "astronauts")
                .env("AWS_REGION", "ap-northeast-2")
                .env(
                    "AWS_CREDENTIALS_FILE",
                    credentials_path.to_string_lossy().as_ref(),
                )
                .collect();

            assert_eq!(
                actual, actual_variant,
                "both AWS_SHARED_CREDENTIALS_FILE and AWS_CREDENTIALS_FILE should work"
            );

            // In principle, "30m" should be correct. However, bad luck in scheduling
            // on shared runners may delay it.
            let possible_values = [
                "30m2s", "30m1s", "30m", "29m59s", "29m58s", "29m57s", "29m56s", "29m55s",
            ];
            let possible_values = possible_values.map(|duration| {
                let segment_colored = format!("☁️  astronauts (ap-northeast-2) [{}] ", duration);
                Some(format!(
                    "on {}",
                    Color::Yellow.bold().paint(segment_colored)
                ))
            });

            assert!(
                possible_values.contains(&actual),
                "time is not in range: {actual:?}"
            );
        });

        dir.close()
    }

    #[test]
    fn profile_and_region_set_show_duration() {
        let actual = ModuleRenderer::new("aws")
            .env("AWS_PROFILE", "astronauts")
            .env("AWS_REGION", "ap-northeast-2")
            .env("AWS_ACCESS_KEY_ID", "dummy")