From 351f2e05977f244bd1a2390855e3943976d15857 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Sun, 6 Oct 2024 13:16:24 +0200 Subject: [PATCH] testutil: update and extend latest versions Signed-off-by: Bruno Schaatsbergen --- tfexec/apply_test.go | 2 +- tfexec/internal/e2etest/init_test.go | 48 ++++++++++++++++++++++++++++ tfexec/internal/testutil/tfcache.go | 29 +++++++++-------- tfexec/plan_test.go | 2 +- tfexec/version_test.go | 4 +-- 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/tfexec/apply_test.go b/tfexec/apply_test.go index fe0420ad..d3c65438 100644 --- a/tfexec/apply_test.go +++ b/tfexec/apply_test.go @@ -154,7 +154,7 @@ func TestApplyJSONCmd(t *testing.T) { func TestApplyCmd_AllowDeferral(t *testing.T) { td := t.TempDir() - tf, err := NewTerraform(td, tfVersion(t, testutil.Alpha_v1_9)) + tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_Alpha_v1_9)) if err != nil { t.Fatal(err) } diff --git a/tfexec/internal/e2etest/init_test.go b/tfexec/internal/e2etest/init_test.go index 1bcc0f91..896e72f3 100644 --- a/tfexec/internal/e2etest/init_test.go +++ b/tfexec/internal/e2etest/init_test.go @@ -5,11 +5,14 @@ package e2etest import ( "context" + "io" + "regexp" "testing" "github.com/hashicorp/go-version" "github.com/hashicorp/terraform-exec/tfexec" + "github.com/hashicorp/terraform-exec/tfexec/internal/testutil" ) func TestInit(t *testing.T) { @@ -20,3 +23,48 @@ func TestInit(t *testing.T) { } }) } + +func TestInitJSON_TF18AndEarlier(t *testing.T) { + versions := []string{ + testutil.Latest011, + testutil.Latest012, + testutil.Latest013, + testutil.Latest_v1_6, + testutil.Latest_v1_7, + testutil.Latest_v1_8, + } + + 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) + } + + re := regexp.MustCompile("terraform init -json was added in 1.9.0") + + err = tf.InitJSON(context.Background(), io.Discard) + if err != nil && !re.MatchString(err.Error()) { + t.Fatalf("error running Init: %s", err) + } + }) +} + +func TestInitJSON_TF19AndLater(t *testing.T) { + versions := []string{ + testutil.Latest_v1_9, + testutil.Latest_Alpha_v1_9, + testutil.Latest_Alpha_v1_10, + } + + 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) + } + + err = tf.InitJSON(context.Background(), io.Discard) + if err != nil { + t.Fatalf("error running Init: %s", err) + } + }) +} diff --git a/tfexec/internal/testutil/tfcache.go b/tfexec/internal/testutil/tfcache.go index 52a046b0..a50bb590 100644 --- a/tfexec/internal/testutil/tfcache.go +++ b/tfexec/internal/testutil/tfcache.go @@ -15,20 +15,21 @@ import ( ) const ( - Latest011 = "0.11.15" - Latest012 = "0.12.31" - Latest013 = "0.13.7" - Latest014 = "0.14.11" - Latest015 = "0.15.5" - Latest_v1 = "1.0.11" - Latest_v1_1 = "1.1.9" - Latest_v1_5 = "1.5.3" - Latest_v1_6 = "1.6.6" - Latest_v1_7 = "1.7.5" - Latest_v1_8 = "1.8.5" - - Beta_v1_8 = "1.8.0-beta1" - Alpha_v1_9 = "1.9.0-alpha20240404" + Latest011 = "0.11.15" + Latest012 = "0.12.31" + Latest013 = "0.13.7" + Latest014 = "0.14.11" + Latest015 = "0.15.5" + Latest_v1 = "1.0.11" + Latest_v1_1 = "1.1.9" + Latest_v1_5 = "1.5.3" + Latest_v1_6 = "1.6.6" + Latest_v1_7 = "1.7.5" + Latest_v1_8 = "1.8.5" + Latest_Beta_v1_8 = "1.8.0-beta1" + Latest_v1_9 = "1.9.7" + Latest_Alpha_v1_9 = "1.9.0-alpha20240516" + Latest_Alpha_v1_10 = "1.10.0-alpha2024092" ) const appendUserAgent = "tfexec-testutil" diff --git a/tfexec/plan_test.go b/tfexec/plan_test.go index e48dbe4b..91c13f5c 100644 --- a/tfexec/plan_test.go +++ b/tfexec/plan_test.go @@ -182,7 +182,7 @@ func TestPlanJSONCmd(t *testing.T) { func TestPlanCmd_AllowDeferral(t *testing.T) { td := t.TempDir() - tf, err := NewTerraform(td, tfVersion(t, testutil.Alpha_v1_9)) + tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_Alpha_v1_9)) if err != nil { t.Fatal(err) } diff --git a/tfexec/version_test.go b/tfexec/version_test.go index 4d7db857..fd6a60dc 100644 --- a/tfexec/version_test.go +++ b/tfexec/version_test.go @@ -301,10 +301,10 @@ func TestExperimentsEnabled(t *testing.T) { expectedError error }{ "experiments-enabled-in-1.9.0-alpha20240404": { - tfVersion: version.Must(version.NewVersion(testutil.Alpha_v1_9)), + tfVersion: version.Must(version.NewVersion(testutil.Latest_Alpha_v1_9)), }, "experiments-disabled-in-1.8.0-beta1": { - tfVersion: version.Must(version.NewVersion(testutil.Beta_v1_8)), + tfVersion: version.Must(version.NewVersion(testutil.Latest_Beta_v1_8)), expectedError: errors.New("experiments are not enabled in version 1.8.0-beta1, as it's not an alpha or dev build"), }, "experiments-disabled-in-1.5.3": {