Skip to content

Commit

Permalink
Add tests to ensure terragrunt, TOML and terraform version handle sit…
Browse files Browse the repository at this point in the history
…uations where no version is available when config files are present

Issue #420
  • Loading branch information
MatthewJohn committed May 9, 2024
1 parent 627ef90 commit 9b95ed7
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/param_parsing/terraform_version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,18 @@ func TestGetParamsFromTerraformVersion(t *testing.T) {
}
}

func TestGetParamsFromTerraformVersion_no_version(t *testing.T) {
var params Params
params.ChDirPath = "../../test-data/skip-integration-tests/test_versiontf_no_version_constraint"
params, err := GetParamsFromTerraformVersion(params)
if err != nil {
t.Fatalf("Got error '%s'", err)
}
if params.Version != "" {
t.Errorf("Expected empty version string. Got: %v", params.Version)
}
}

func TestGetParamsFromTerraformVersion_no_file(t *testing.T) {
var params Params
params.ChDirPath = "../../test-data/skip-integration-tests/test_no_file"
Expand Down
17 changes: 16 additions & 1 deletion lib/param_parsing/terragrunt_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package param_parsing

import (
"testing"

"github.com/hashicorp/go-version"
"github.com/warrensbox/terraform-switcher/lib"
"testing"
)

func TestGetVersionFromTerragrunt(t *testing.T) {
Expand Down Expand Up @@ -34,6 +35,20 @@ func TestGetVersionTerragrunt_with_no_terragrunt_file(t *testing.T) {
}
}

func TestGetVersionTerragrunt_with_no_version(t *testing.T) {
var params Params
logger = lib.InitLogger("DEBUG")
params = initParams(params)
params.ChDirPath = "../../test-data/skip-integration-tests/test_terragrunt_no_version"
params, err := GetVersionFromTerragrunt(params)
if err != nil {
t.Fatalf("Got error '%s'", err)
}
if params.Version != "" {
t.Error("Version should be empty")
}
}

func TestGetVersionFromTerragrunt_erroneous_file(t *testing.T) {
var params Params
logger = lib.InitLogger("DEBUG")
Expand Down
12 changes: 12 additions & 0 deletions lib/param_parsing/tfswitch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,15 @@ func TestGetParamsFromTfSwitch_no_file(t *testing.T) {
t.Errorf("Expected empty version string. Got: %v", params.Version)
}
}

func TestGetParamsFromTfSwitch_no_version(t *testing.T) {
var params Params
params.ChDirPath = "../../test-data/skip-integration-tests/test_no_version"
params, err := GetParamsFromTfSwitch(params)
if err != nil {
t.Errorf("Expected no error. Got: %v", err)
}
if params.Version != "" {
t.Errorf("Expected empty version string. Got: %v", params.Version)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
terragrunt_version_constraint = "= 0.36.2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bin = "/usr/local/bin/terraform_from_toml"
log-level = "NOTICE"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
terraform {
required_providers {
aws = ">= 2.52.0"
kubernetes = ">= 1.11.1"
}
}

0 comments on commit 9b95ed7

Please sign in to comment.