fix issue when localBinPath is set (#359)
When running e2e tests against a locally built Terraform
binary, the runTestWithVersions helper has some surprising
behavior: it throws away the selected versions and runs
the test against the local binary instead. This seems fairly
undesirable, since the tests using that helper are testing
version-specific behavior (and thus fail when a local
bin path is set).
This commit clarifies some naming and ensures that version
override behavior is confined to `runTest`, which makes no
assumptions about which versions it's using.
diff --git a/tfexec/internal/e2etest/apply_test.go b/tfexec/internal/e2etest/apply_test.go
index 5211a3d..967e596 100644
--- a/tfexec/internal/e2etest/apply_test.go
+++ b/tfexec/internal/e2etest/apply_test.go
@@ -29,7 +29,7 @@
func TestApplyJSON_TF014AndEarlier(t *testing.T) {
versions := []string{testutil.Latest011, testutil.Latest012, testutil.Latest013, testutil.Latest014}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
@@ -47,7 +47,7 @@
func TestApplyJSON_TF015AndLater(t *testing.T) {
versions := []string{testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
diff --git a/tfexec/internal/e2etest/destroy_test.go b/tfexec/internal/e2etest/destroy_test.go
index 9d157fd..bd7124f 100644
--- a/tfexec/internal/e2etest/destroy_test.go
+++ b/tfexec/internal/e2etest/destroy_test.go
@@ -34,7 +34,7 @@
func TestDestroyJSON_TF014AndEarlier(t *testing.T) {
versions := []string{testutil.Latest011, testutil.Latest012, testutil.Latest013, testutil.Latest014}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
@@ -52,7 +52,7 @@
func TestDestroyJSON_TF015AndLater(t *testing.T) {
versions := []string{testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
diff --git a/tfexec/internal/e2etest/plan_test.go b/tfexec/internal/e2etest/plan_test.go
index 83364fd..ca6dbcd 100644
--- a/tfexec/internal/e2etest/plan_test.go
+++ b/tfexec/internal/e2etest/plan_test.go
@@ -53,7 +53,7 @@
func TestPlanJSON_TF014AndEarlier(t *testing.T) {
versions := []string{testutil.Latest011, testutil.Latest012, testutil.Latest013, testutil.Latest014}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
@@ -74,7 +74,7 @@
func TestPlanJSON_TF015AndLater(t *testing.T) {
versions := []string{testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
diff --git a/tfexec/internal/e2etest/refresh_test.go b/tfexec/internal/e2etest/refresh_test.go
index 1cea79e..500d3f7 100644
--- a/tfexec/internal/e2etest/refresh_test.go
+++ b/tfexec/internal/e2etest/refresh_test.go
@@ -34,7 +34,7 @@
func TestRefreshJSON_TF014AndEarlier(t *testing.T) {
versions := []string{testutil.Latest011, testutil.Latest012, testutil.Latest013, testutil.Latest014}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
@@ -52,7 +52,7 @@
func TestRefreshJSON_TF015AndLater(t *testing.T) {
versions := []string{testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}
- runTestWithVersions(t, "basic", versions, func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, versions, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
diff --git a/tfexec/internal/e2etest/show_test.go b/tfexec/internal/e2etest/show_test.go
index 29e7711..e1cb92b 100644
--- a/tfexec/internal/e2etest/show_test.go
+++ b/tfexec/internal/e2etest/show_test.go
@@ -116,7 +116,7 @@
// no providers to download, this is unintended behaviour, as
// init is not actually necessary. This is considered a known issue in
// pre-1.2.0 versions.
- runTestVersions(t, []string{testutil.Latest012, testutil.Latest013, testutil.Latest014, testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest012, testutil.Latest013, testutil.Latest014, testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
var noInit *tfexec.ErrNoInit
_, err := tf.Show(context.Background())
if !errors.As(err, &noInit) {
@@ -154,7 +154,7 @@
// no providers to download, this is unintended behaviour, as
// init is not actually necessary. This is considered a known issue in
// pre-1.2.0 versions.
- runTestVersions(t, []string{testutil.Latest012, testutil.Latest013, testutil.Latest014, testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}, "registry_module", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest012, testutil.Latest013, testutil.Latest014, testutil.Latest015, testutil.Latest_v1, testutil.Latest_v1_1}, "registry_module", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
var noInit *tfexec.ErrNoInit
_, err := tf.Show(context.Background())
if !errors.As(err, &noInit) {
@@ -306,7 +306,7 @@
// so we maintain one fixture per supported version.
// See github.com/hashicorp/terraform/25920
func TestShowStateFile012(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest012}, "non_default_statefile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest012}, "non_default_statefile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
expected := &tfjson.State{
FormatVersion: "0.1",
// TerraformVersion is ignored to facilitate latest version testing
@@ -344,7 +344,7 @@
}
func TestShowStateFile013(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest013, testutil.Latest014}, "non_default_statefile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest013, testutil.Latest014}, "non_default_statefile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
expected := &tfjson.State{
FormatVersion: "0.1",
// TerraformVersion is ignored to facilitate latest version testing
@@ -382,7 +382,7 @@
}
func TestShowStateFile014(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest014}, "non_default_statefile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest014}, "non_default_statefile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
expected := &tfjson.State{
FormatVersion: "0.1",
// TerraformVersion is ignored to facilitate latest version testing
@@ -422,7 +422,7 @@
// Plan files cannot be transferred between different Terraform versions,
// so we maintain one fixture per supported version
func TestShowPlanFile012_linux(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest012}, "non_default_planfile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest012}, "non_default_planfile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
if runtime.GOOS != "linux" {
t.Skip("plan file created in 0.12 on Linux is not compatible with other systems")
}
@@ -488,7 +488,7 @@
}
func TestShowPlanFile013(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest013}, "non_default_planfile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest013}, "non_default_planfile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
providerName := "registry.terraform.io/hashicorp/null"
expected := &tfjson.Plan{
@@ -550,7 +550,7 @@
}
func TestShowPlanFile014(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest014}, "non_default_planfile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest014}, "non_default_planfile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
providerName := "registry.terraform.io/hashicorp/null"
expected := &tfjson.Plan{
@@ -615,7 +615,7 @@
}
func TestShowPlanFileRaw012_linux(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest012}, "non_default_planfile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest012}, "non_default_planfile_012", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
if runtime.GOOS != "linux" {
t.Skip("plan file created in 0.12 on Linux is not compatible with other systems")
}
@@ -647,7 +647,7 @@
}
func TestShowPlanFileRaw013(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest013}, "non_default_planfile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest013}, "non_default_planfile_013", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
f, err := os.Open("testdata/non_default_planfile_013/human_readable_output.txt")
if err != nil {
t.Fatal(err)
@@ -675,7 +675,7 @@
}
func TestShowPlanFileRaw014(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest014}, "non_default_planfile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest014}, "non_default_planfile_014", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
f, err := os.Open("testdata/non_default_planfile_013/human_readable_output.txt")
if err != nil {
t.Fatal(err)
diff --git a/tfexec/internal/e2etest/upgrade012_test.go b/tfexec/internal/e2etest/upgrade012_test.go
index c40de0c..0cdc14e 100644
--- a/tfexec/internal/e2etest/upgrade012_test.go
+++ b/tfexec/internal/e2etest/upgrade012_test.go
@@ -12,7 +12,7 @@
)
func TestUpgrade012(t *testing.T) {
- runTestVersions(t, []string{testutil.Latest012}, "pre_011_syntax", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
+ runTestWithVersions(t, []string{testutil.Latest012}, "pre_011_syntax", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) {
err := tf.Init(context.Background())
if err != nil {
t.Fatalf("error running Init in test directory: %s", err)
diff --git a/tfexec/internal/e2etest/util_test.go b/tfexec/internal/e2etest/util_test.go
index 49cc063..66800d5 100644
--- a/tfexec/internal/e2etest/util_test.go
+++ b/tfexec/internal/e2etest/util_test.go
@@ -42,12 +42,6 @@
versions = strings.Split(override, ",")
}
- runTestWithVersions(t, fixtureName, versions, cb)
-}
-
-func runTestWithVersions(t *testing.T, fixtureName string, versions []string, cb func(t *testing.T, tfVersion *version.Version, tf *tfexec.Terraform)) {
- t.Helper()
-
// If the env var TFEXEC_E2ETEST_TERRAFORM_PATH is set to the path of a
// valid Terraform executable, only tests appropriate to that
// executable's version will be run.
@@ -79,10 +73,10 @@
versions = []string{lVersion.String()}
}
- runTestVersions(t, versions, fixtureName, cb)
+ runTestWithVersions(t, versions, fixtureName, cb)
}
-func runTestVersions(t *testing.T, versions []string, fixtureName string, cb func(t *testing.T, tfVersion *version.Version, tf *tfexec.Terraform)) {
+func runTestWithVersions(t *testing.T, versions []string, fixtureName string, cb func(t *testing.T, tfVersion *version.Version, tf *tfexec.Terraform)) {
t.Helper()
alreadyRunVersions := map[string]bool{}