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

Code before:
            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()
                .paint("☁️  astronauts (ap-northeast-2) ")
        ));

        assert_eq!(expected, actual);
    }

    #[test]
    fn expiration_date_set_expired() {
        use chrono::{DateTime, NaiveDateTime, SecondsFormat, Utc};

Review comment (bug):
To increase observability on failure:
```suggestion
            assert!(
                possible_values.contains(&actual),
                "time is in range: {actual:?}"
            );
```

Code after:
            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")
            .collect();
        let expected = Some(format!(
            "on {}",
            Color::Yellow
                .bold()
                .paint("☁️  astronauts (ap-northeast-2) ")
        ));

        assert_eq!(expected, actual);