feat: Add configuration to set how much AWS profile info is shown (#556)

This commit is contained in:
Cédric Da Fonseca
2019-11-02 12:08:54 +01:00
committed by Matan Kushner
parent 26fa4ec1ea
commit fa1267f12f
4 changed files with 210 additions and 47 deletions
+129 -7
View File
@@ -4,12 +4,11 @@ use std::io::{self, Write};
use ansi_term::Color;
use tempfile;
use crate::common;
use crate::common::{self, TestCommand};
#[test]
fn no_region_set() -> io::Result<()> {
let output = common::render_module("aws")
.env_clear()
.env("PATH", env!("PATH"))
.output()?;
let expected = "";
@@ -21,7 +20,6 @@ fn no_region_set() -> io::Result<()> {
#[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"));
@@ -33,7 +31,6 @@ fn region_set() -> io::Result<()> {
#[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()?;
@@ -46,7 +43,6 @@ fn default_region_set() -> io::Result<()> {
#[test]
fn profile_set() -> io::Result<()> {
let output = common::render_module("aws")
.env_clear()
.env("AWS_PROFILE", "astronauts")
.output()?;
let expected = format!("on {} ", Color::Yellow.bold().paint("☁️ astronauts"));
@@ -55,6 +51,21 @@ fn profile_set() -> io::Result<()> {
Ok(())
}
#[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(())
}
#[test]
fn default_profile_set() -> io::Result<()> {
let dir = tempfile::tempdir()?;
@@ -72,7 +83,6 @@ region = us-east-2
)?;
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"));
@@ -98,9 +108,11 @@ region = us-east-2
)?;
let output = common::render_module("aws")
.env_clear()
.env("AWS_CONFIG_FILE", config_path.to_string_lossy().as_ref())
.env("AWS_PROFILE", "astronauts")
.use_config(toml::toml! {
[aws]
})
.output()?;
let expected = format!(
"on {} ",
@@ -110,3 +122,113 @@ region = us-east-2
assert_eq!(expected, actual);
Ok(())
}
#[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")
.use_config(toml::toml! {
[aws]
displayed_items = "all"
})
.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")
.use_config(toml::toml! {
[aws]
displayed_items = "all"
})
.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")
.use_config(toml::toml! {
[aws]
displayed_items = "all"
})
.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_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]
displayed_items = "region"
})
.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]
displayed_items = "profile"
})
.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]
displayed_items = "profile"
})
.output()?;
let expected = "";
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn region_not_set_with_display_region() -> io::Result<()> {
let output = common::render_module("aws")
.use_config(toml::toml! {
[aws]
displayed_items = "region"
})
.output()?;
let expected = "";
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}