Skip to content

Commit

Permalink
testutil: update and extend latest versions
Browse files Browse the repository at this point in the history
Signed-off-by: Bruno Schaatsbergen <[email protected]>
  • Loading branch information
bschaatsbergen committed Oct 6, 2024
1 parent 6af74c5 commit 351f2e0
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 18 deletions.
2 changes: 1 addition & 1 deletion tfexec/apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
48 changes: 48 additions & 0 deletions tfexec/internal/e2etest/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
}
})
}
29 changes: 15 additions & 14 deletions tfexec/internal/testutil/tfcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tfexec/plan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions tfexec/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit 351f2e0

Please sign in to comment.