2019-12-09 01:42:51 +00:00
|
|
|
use ansi_term::Color;
|
|
|
|
use std::fs::{self, File};
|
|
|
|
use std::io::{self, Write};
|
|
|
|
|
|
|
|
use crate::common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn folder_without_dotterraform() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
|
|
|
|
let output = common::render_module("terraform")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = "";
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 17:12:25 +00:00
|
|
|
dir.close()
|
2019-12-09 01:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_tf_file() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("main.tf"))?;
|
|
|
|
|
|
|
|
let output = common::render_module("terraform")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 default"));
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 17:12:25 +00:00
|
|
|
dir.close()
|
2019-12-09 01:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_workspace_override() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("main.tf"))?;
|
|
|
|
|
|
|
|
let output = common::render_module("terraform")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.env("TF_WORKSPACE", "development")
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 development"));
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 17:12:25 +00:00
|
|
|
dir.close()
|
2019-12-09 01:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_datadir_override() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
File::create(dir.path().join("main.tf"))?;
|
|
|
|
|
|
|
|
let datadir = tempfile::tempdir()?;
|
|
|
|
let mut file = File::create(datadir.path().join("environment"))?;
|
|
|
|
file.write_all(b"development")?;
|
|
|
|
file.sync_all()?;
|
|
|
|
|
|
|
|
let output = common::render_module("terraform")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.env("TF_DATA_DIR", datadir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 development"));
|
|
|
|
assert_eq!(expected, actual);
|
2020-03-15 17:12:25 +00:00
|
|
|
dir.close()?;
|
|
|
|
datadir.close()
|
2019-12-09 01:42:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_dotterraform_no_environment() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
let tf_dir = dir.path().join(".terraform");
|
|
|
|
fs::create_dir(&tf_dir)?;
|
|
|
|
|
|
|
|
let output = common::render_module("terraform")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 default"));
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn folder_with_dotterraform_with_environment() -> io::Result<()> {
|
|
|
|
let dir = tempfile::tempdir()?;
|
|
|
|
let tf_dir = dir.path().join(".terraform");
|
|
|
|
fs::create_dir(&tf_dir)?;
|
|
|
|
let mut file = File::create(tf_dir.join("environment"))?;
|
|
|
|
file.write_all(b"development")?;
|
|
|
|
file.sync_all()?;
|
|
|
|
|
|
|
|
let output = common::render_module("terraform")
|
|
|
|
.arg("--path")
|
|
|
|
.arg(dir.path())
|
|
|
|
.output()?;
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
|
|
|
let expected = format!("via {} ", Color::Fixed(105).bold().paint("💠 development"));
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
Ok(())
|
|
|
|
}
|