2019-10-14 15:05:03 +00:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::{self, Write};
|
|
|
|
|
2019-09-26 02:55:47 +00:00
|
|
|
use ansi_term::Color;
|
|
|
|
|
|
|
|
use crate::common;
|
|
|
|
|
|
|
|
#[test]
|
2019-10-14 15:05:03 +00:00
|
|
|
fn no_region_set() -> io::Result<()> {
|
2019-09-26 02:55:47 +00:00
|
|
|
let output = common::render_module("aws").env_clear().output()?;
|
|
|
|
let expected = "";
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2019-10-14 15:05:03 +00:00
|
|
|
#[test]
|
|
|
|
fn region_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env_clear()
|
|
|
|
.env("AWS_REGION", "ap-northeast-2")
|
|
|
|
.output()?;
|
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ ap-northeast-2"));
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_region_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env_clear()
|
|
|
|
.env("AWS_REGION", "ap-northeast-2")
|
|
|
|
.env("AWS_DEFAULT_REGION", "ap-northeast-1")
|
|
|
|
.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(())
|
|
|
|
}
|
|
|
|
|
2019-09-26 02:55:47 +00:00
|
|
|
#[test]
|
|
|
|
fn profile_set() -> io::Result<()> {
|
|
|
|
let output = common::render_module("aws")
|
|
|
|
.env_clear()
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.output()?;
|
2019-10-14 13:56:16 +00:00
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts"));
|
2019-09-26 02:55:47 +00:00
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
2019-10-14 15:05:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn default_profile_set() -> io::Result<()> {
|
|
|
|
let dir = common::new_tempdir()?;
|
|
|
|
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_clear()
|
|
|
|
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
|
|
|
|
.output()?;
|
|
|
|
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ us-east-1"));
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn profile_and_config_set() -> io::Result<()> {
|
|
|
|
let dir = common::new_tempdir()?;
|
|
|
|
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_clear()
|
|
|
|
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
|
|
|
|
.env("AWS_PROFILE", "astronauts")
|
|
|
|
.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);
|
|
|
|
Ok(())
|
|
|
|
}
|