Skip to content

Commit

Permalink
discard get version's stdout, do not use json
Browse files Browse the repository at this point in the history
  • Loading branch information
lonegunmanb committed Jan 12, 2023
1 parent e35b23f commit 6c23db2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion version_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package terraform_module_test_helper

import (
"fmt"
"github.com/gruntwork-io/terratest/modules/files"
"github.com/gruntwork-io/terratest/modules/logger"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -36,6 +38,7 @@ func GetVersion(t *testing.T, rootFolder, terraformModuleFolder string) TestVers
options := terraform.Options{
TerraformDir: tmpPath,
NoColor: true,
Logger: logger.Discard,
}
output, err := terraform.InitE(t, &options)
if err != nil {
Expand All @@ -45,7 +48,7 @@ func GetVersion(t *testing.T, rootFolder, terraformModuleFolder string) TestVers
Output: output,
}
}
output, err = terraform.RunTerraformCommandE(t, &options, "version", "-json")
output, err = terraform.RunTerraformCommandE(t, &options, "version")
return TestVersionSnapshot{
Time: time.Now(),
Success: err == nil,
Expand All @@ -55,6 +58,12 @@ func GetVersion(t *testing.T, rootFolder, terraformModuleFolder string) TestVers

func RecordVersionSnapshot(t *testing.T, rootFolder, terraformModuleFolder string) error {
path := filepath.Join(rootFolder, terraformModuleFolder, "TestRecord.md.tmp")
if files.FileExists(path) {
err := os.Remove(path)
if err != nil {
return err
}
}
f, err := os.Create(filepath.Clean(path))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion version_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestGetVersionSnapshot(t *testing.T) {
version := GetVersion(t, "./", "example/basic")
require.NotEmpty(t, version.Output)
require.Contains(t, version.Output, "terraform_version")
require.Contains(t, version.Output, "Terraform v")
require.Contains(t, version.Output, "registry.terraform.io/hashicorp/null")
}

Expand Down

0 comments on commit 6c23db2

Please sign in to comment.