test(terraform): move tests which do not require env vars (#1455)

Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
This commit is contained in:
Tilmann Meyer 2020-07-09 02:24:38 +02:00 committed by GitHub
parent 297cbd8654
commit 7edd0f6218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 60 deletions

View File

@ -132,12 +132,6 @@ jobs:
if: matrix.os == 'macOS-latest' if: matrix.os == 'macOS-latest'
run: pip3 install mercurial run: pip3 install mercurial
# Install Terraform at a fixed version
- name: Setup | Terraform
uses: volcano-coffee-company/setup-terraform@v1
with:
version: "0.12.14"
# Run the ignored tests that expect the above setup # Run the ignored tests that expect the above setup
- name: Build | Test - name: Build | Test
run: cargo test -- -Z unstable-options --include-ignored run: cargo test -- -Z unstable-options --include-ignored

View File

@ -97,6 +97,10 @@ fn format_terraform_version(version: &str) -> Option<String> {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::modules::utils::test::render_module;
use ansi_term::Color;
use std::fs::{self, File};
use std::io::Write;
#[test] #[test]
fn test_format_terraform_version_release() { fn test_format_terraform_version_release() {
@ -138,4 +142,53 @@ is 0.12.14. You can update by downloading from www.terraform.io/downloads.html
Some("v0.12.13 ".to_string()) Some("v0.12.13 ".to_string())
); );
} }
#[test]
fn folder_with_dotterraform_with_version_no_environment() -> io::Result<()> {
let dir = tempfile::tempdir()?;
let tf_dir = dir.path().join(".terraform");
fs::create_dir(&tf_dir)?;
let actual = render_module(
"terraform",
dir.path(),
Some(toml::toml! {
[terraform]
format = "via [$symbol$version$workspace]($style) "
}),
);
let expected = Some(format!(
"via {} ",
Color::Fixed(105).bold().paint("💠 v0.12.14 default")
));
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn folder_with_dotterraform_with_version_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 actual = render_module(
"terraform",
dir.path(),
Some(toml::toml! {
[terraform]
format = "via [$symbol$version$workspace]($style) "
}),
);
let expected = Some(format!(
"via {} ",
Color::Fixed(105).bold().paint("💠 v0.12.14 development")
));
assert_eq!(expected, actual);
Ok(())
}
} }

View File

@ -123,6 +123,10 @@ active boot switches: -d:release\n",
stdout: String::from("0.6.0"), stdout: String::from("0.6.0"),
stderr: String::default(), stderr: String::default(),
}), }),
"terraform version" => Some(CommandOutput {
stdout: String::from("Terraform v0.12.14"),
stderr: String::default(),
}),
s if s.starts_with("erl") => Some(CommandOutput { s if s.starts_with("erl") => Some(CommandOutput {
stdout: String::from("22.1.3"), stdout: String::from("22.1.3"),
stderr: String::default(), stderr: String::default(),

View File

@ -3,7 +3,6 @@ use std::fs::{self, File};
use std::io::{self, Write}; use std::io::{self, Write};
use crate::common; use crate::common;
use crate::common::TestCommand;
#[test] #[test]
fn folder_without_dotterraform() -> io::Result<()> { fn folder_without_dotterraform() -> io::Result<()> {
@ -117,56 +116,3 @@ fn folder_with_dotterraform_with_environment() -> io::Result<()> {
assert_eq!(expected, actual); assert_eq!(expected, actual);
Ok(()) Ok(())
} }
#[test]
#[ignore]
fn folder_with_dotterraform_with_version_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())
.use_config(toml::toml! {
[terraform]
format = "via [$symbol$version$workspace]($style) "
})
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = format!(
"via {} ",
Color::Fixed(105).bold().paint("💠 v0.12.14 default")
);
assert_eq!(expected, actual);
Ok(())
}
#[test]
#[ignore]
fn folder_with_dotterraform_with_version_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())
.use_config(toml::toml! {
[terraform]
format = "via [$symbol$version$workspace]($style) "
})
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = format!(
"via {} ",
Color::Fixed(105).bold().paint("💠 v0.12.14 development")
);
assert_eq!(expected, actual);
Ok(())
}