2019-10-14 17:05:03 +02:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{self, Write};
|
|
|
|
|
2019-09-26 04:55:47 +02:00
|
|
|
use ansi_term::Color;
|
|
|
|
|
2019-11-02 12:08:54 +01:00
|
|
|
use crate::common::{self, TestCommand};
|
2019-09-26 04:55:47 +02:00
|
|
|
|
|
|
|
#[test]
|
2020-01-09 01:22:42 +01:00
|
|
|
#[ignore]
|
2019-10-14 17:05:03 +02:00
|
|
|
fn no_region_set() -> io::Result<()> {
|
2019-10-15 17:10:16 +02:00
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("PATH", env!("PATH"))
|
|
|
|
.output()?;
|
2019-09-26 04:55:47 +02:00
|
|
|
let expected = "";
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-10-14 17:05:03 +02:00
|
|
|
#[test]
|
|
|
|
fn region_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_REGION", "ap-northeast-2")
|
|
|
|
.output()?;
|
2020-07-08 00:45:32 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ (ap-northeast-2)"));
|
2019-10-14 17:05:03 +02:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-12-20 18:30:47 +01:00
|
|
|
#[test]
|
|
|
|
fn region_set_with_alias() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_REGION", "ap-southeast-2")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[aws.region_aliases]
|
|
|
|
ap-southeast-2 = "au"
|
|
|
|
})
|
|
|
|
.output()?;
|
2020-07-08 00:45:32 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ (au)"));
|
2019-12-20 18:30:47 +01:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-10-14 17:05:03 +02:00
|
|
|
#[test]
|
|
|
|
fn default_region_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_REGION", "ap-northeast-2")
|
|
|
|
.env("AWS_DEFAULT_REGION", "ap-northeast-1")
|
|
|
|
.output()?;
|
2020-07-08 00:45:32 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ (ap-northeast-1)"));
|
2019-10-14 17:05:03 +02:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-09-26 04:55:47 +02:00
|
|
|
#[test]
|
|
|
|
fn profile_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.output()?;
|
2019-10-14 15:56:16 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts"));
|
2019-09-26 04:55:47 +02:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-10-14 17:05:03 +02:00
|
|
|
|
2020-04-06 16:59:56 +02:00
|
|
|
#[test]
|
|
|
|
fn profile_set_from_aws_vault() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_VAULT", "astronauts-vault")
|
|
|
|
.env("AWS_PROFILE", "astronauts-profile")
|
|
|
|
.output()?;
|
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts-vault"));
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-11-02 12:08:54 +01:00
|
|
|
#[test]
|
|
|
|
fn profile_and_region_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.env("AWS_REGION", "ap-northeast-2")
|
|
|
|
.output()?;
|
|
|
|
let expected = format!(
|
|
|
|
"on {} ",
|
|
|
|
Color::Yellow.bold().paint("☁️ astronauts(ap-northeast-2)")
|
|
|
|
);
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-10-14 17:05:03 +02:00
|
|
|
#[test]
|
|
|
|
fn default_profile_set() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-14 17:05:03 +02:00
|
|
|
let config_path = dir.path().join("config");
|
|
|
|
let mut file = File::create(&config_path)?;
|
|
|
|
|
|
|
|
file.write_all(
|
|
|
|
"[default]
|
|
|
|
region = us-east-1
|
|
|
|
|
|
|
|
[profile astronauts]
|
|
|
|
region = us-east-2
|
|
|
|
"
|
|
|
|
.as_bytes(),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
|
|
|
|
.output()?;
|
2020-07-08 00:45:32 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ (us-east-1)"));
|
2019-10-14 17:05:03 +02:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-10-14 17:05:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn profile_and_config_set() -> io::Result<()> {
|
2019-10-15 16:01:44 +02:00
|
|
|
let dir = tempfile::tempdir()?;
|
2019-10-14 17:05:03 +02:00
|
|
|
let config_path = dir.path().join("config");
|
|
|
|
let mut file = File::create(&config_path)?;
|
|
|
|
|
|
|
|
file.write_all(
|
|
|
|
"[default]
|
|
|
|
region = us-east-1
|
|
|
|
|
|
|
|
[profile astronauts]
|
|
|
|
region = us-east-2
|
|
|
|
"
|
|
|
|
.as_bytes(),
|
|
|
|
)?;
|
|
|
|
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
2019-11-02 12:08:54 +01:00
|
|
|
.use_config(toml::toml! {
|
|
|
|
[aws]
|
|
|
|
})
|
2019-10-14 17:05:03 +02:00
|
|
|
.output()?;
|
|
|
|
let expected = format!(
|
|
|
|
"on {} ",
|
|
|
|
Color::Yellow.bold().paint("☁️ astronauts(us-east-2)")
|
|
|
|
);
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 18:12:25 +01:00
|
|
|
dir.close()
|
2019-10-14 17:05:03 +02:00
|
|
|
}
|
2019-11-02 12:08:54 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn profile_and_region_set_with_display_all() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.env("AWS_REGION", "ap-northeast-1")
|
|
|
|
.output()?;
|
|
|
|
let expected = format!(
|
|
|
|
"on {} ",
|
|
|
|
Color::Yellow.bold().paint("☁️ astronauts(ap-northeast-1)")
|
|
|
|
);
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn profile_set_with_display_all() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.output()?;
|
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts"));
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn region_set_with_display_all() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_REGION", "ap-northeast-1")
|
|
|
|
.output()?;
|
2020-07-08 00:45:32 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ (ap-northeast-1)"));
|
2019-11-02 12:08:54 +01:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn profile_and_region_set_with_display_region() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.env("AWS_DEFAULT_REGION", "ap-northeast-1")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[aws]
|
2020-07-08 00:45:32 +02:00
|
|
|
format = "on [$symbol$region]($style) "
|
2019-11-02 12:08:54 +01:00
|
|
|
})
|
|
|
|
.output()?;
|
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ ap-northeast-1"));
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn profile_and_region_set_with_display_profile() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.env("AWS_REGION", "ap-northeast-1")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[aws]
|
2020-07-08 00:45:32 +02:00
|
|
|
format = "on [$symbol$profile]($style) "
|
2019-11-02 12:08:54 +01:00
|
|
|
})
|
|
|
|
.output()?;
|
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts"));
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn region_set_with_display_profile() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env("AWS_REGION", "ap-northeast-1")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[aws]
|
2020-07-08 00:45:32 +02:00
|
|
|
format = "on [$symbol$profile]($style) "
|
2019-11-02 12:08:54 +01:00
|
|
|
})
|
|
|
|
.output()?;
|
2020-07-08 00:45:32 +02:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ "));
|
2019-11-02 12:08:54 +01:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2020-01-09 01:22:42 +01:00
|
|
|
#[ignore]
|
2019-11-02 12:08:54 +01:00
|
|
|
fn region_not_set_with_display_region() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
[aws]
|
2020-07-08 00:45:32 +02:00
|
|
|
format = "on [$symbol$region]($style) "
|
2019-11-02 12:08:54 +01:00
|
|
|
})
|
|
|
|
.output()?;
|
|
|
|
let expected = "";
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|