diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 8e8cfec8..5b7383b3 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -132,12 +132,6 @@ jobs: if: matrix.os == 'macOS-latest' 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 - name: Build | Test run: cargo test -- -Z unstable-options --include-ignored diff --git a/src/modules/terraform.rs b/src/modules/terraform.rs index 9c7c3df4..d708e563 100644 --- a/src/modules/terraform.rs +++ b/src/modules/terraform.rs @@ -97,6 +97,10 @@ fn format_terraform_version(version: &str) -> Option { #[cfg(test)] mod tests { use super::*; + use crate::modules::utils::test::render_module; + use ansi_term::Color; + use std::fs::{self, File}; + use std::io::Write; #[test] 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()) ); } + + #[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(()) + } } diff --git a/src/utils.rs b/src/utils.rs index 79b8d883..8b3a9372 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -123,6 +123,10 @@ active boot switches: -d:release\n", stdout: String::from("0.6.0"), 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 { stdout: String::from("22.1.3"), stderr: String::default(), diff --git a/tests/testsuite/terraform.rs b/tests/testsuite/terraform.rs index 194e9f4b..e13b9aec 100644 --- a/tests/testsuite/terraform.rs +++ b/tests/testsuite/terraform.rs @@ -3,7 +3,6 @@ use std::fs::{self, File}; use std::io::{self, Write}; use crate::common; -use crate::common::TestCommand; #[test] fn folder_without_dotterraform() -> io::Result<()> { @@ -117,56 +116,3 @@ fn folder_with_dotterraform_with_environment() -> io::Result<()> { assert_eq!(expected, actual); 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(()) -}