Skip to content

Commit

Permalink
make tests pass (or skip) on darwin/arm64 (#304)
Browse files Browse the repository at this point in the history
* make tests pass on darwin/arm64

* address PR feedback (add extra v1 tests)
  • Loading branch information
radeksimko committed May 18, 2022
1 parent 660d58b commit fae0ba3
Show file tree
Hide file tree
Showing 24 changed files with 235 additions and 36 deletions.
2 changes: 1 addition & 1 deletion tfexec/destroy_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestDestroyCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions tfexec/fmt_test.go
Expand Up @@ -3,10 +3,15 @@ package tfexec
import (
"context"
"errors"
"runtime"
"testing"
)

func TestFormat(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
t.Skip("Terraform for darwin/arm64 is not available until v1")
}

td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, "0.7.6"))
Expand Down
2 changes: 1 addition & 1 deletion tfexec/get_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestGetCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
11 changes: 8 additions & 3 deletions tfexec/graph_test.go
Expand Up @@ -2,12 +2,17 @@ package tfexec

import (
"context"
"runtime"
"testing"

"github.com/hashicorp/terraform-exec/tfexec/internal/testutil"
)

func TestGraphCmd(t *testing.T) {
func TestGraphCmd_v013(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
t.Skip("Terraform for darwin/arm64 is not available until v1")
}

td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013))
Expand Down Expand Up @@ -41,10 +46,10 @@ func TestGraphCmd(t *testing.T) {
})
}

func TestGraphCmd15(t *testing.T) {
func TestGraphCmd_v1(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest015))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/import_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestImportCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
61 changes: 60 additions & 1 deletion tfexec/init_test.go
Expand Up @@ -2,12 +2,17 @@ package tfexec

import (
"context"
"runtime"
"testing"

"github.com/hashicorp/terraform-exec/tfexec/internal/testutil"
)

func TestInitCmd(t *testing.T) {
func TestInitCmd_v012(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
t.Skip("Terraform for darwin/arm64 is not available until v1")
}

td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
Expand Down Expand Up @@ -68,3 +73,57 @@ func TestInitCmd(t *testing.T) {
}, nil, initCmd)
})
}

func TestInitCmd_v1(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}

// empty env, to avoid environ mismatch in testing
tf.SetEnv(map[string]string{})

t.Run("defaults", func(t *testing.T) {
// defaults
initCmd, err := tf.initCmd(context.Background())
if err != nil {
t.Fatal(err)
}

assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
"-upgrade=false",
}, nil, initCmd)
})

t.Run("override all defaults", func(t *testing.T) {
initCmd, err := tf.initCmd(context.Background(), Backend(false), BackendConfig("confpath1"), BackendConfig("confpath2"), FromModule("testsource"), Get(false), PluginDir("testdir1"), PluginDir("testdir2"), Reconfigure(true), Upgrade(true), Dir("initdir"))
if err != nil {
t.Fatal(err)
}

assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-from-module=testsource",
"-backend=false",
"-get=false",
"-upgrade=true",
"-reconfigure",
"-backend-config=confpath1",
"-backend-config=confpath2",
"-plugin-dir=testdir1",
"-plugin-dir=testdir2",
"initdir",
}, nil, initCmd)
})
}
2 changes: 1 addition & 1 deletion tfexec/internal/e2etest/testdata/bigint/main.tf
@@ -1,7 +1,7 @@
terraform {
required_providers {
random = {
version = "3.0.1"
version = "3.1.3"
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions tfexec/internal/e2etest/util_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -50,6 +51,16 @@ func runTestVersions(t *testing.T, versions []string, fixtureName string, cb fun
alreadyRunVersions := map[string]bool{}
for _, tfv := range versions {
t.Run(fmt.Sprintf("%s-%s", fixtureName, tfv), func(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
v, err := version.NewVersion(tfv)
if err != nil {
t.Fatal(err)
}
if v.LessThan(version.Must(version.NewVersion("1.0.2"))) {
t.Skipf("Terraform not available for darwin/arm64 < 1.0.2 (%s)", v)
}
}

if alreadyRunVersions[tfv] {
t.Skipf("already run version %q", tfv)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/output_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestOutputCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/providers_lock_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestProvidersLockCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/providers_schema_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestProvidersSchemaCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/refresh_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestRefreshCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
8 changes: 4 additions & 4 deletions tfexec/show_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestShowCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand All @@ -31,7 +31,7 @@ func TestShowCmd(t *testing.T) {
func TestShowStateFileCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand All @@ -52,7 +52,7 @@ func TestShowStateFileCmd(t *testing.T) {
func TestShowPlanFileCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand All @@ -73,7 +73,7 @@ func TestShowPlanFileCmd(t *testing.T) {
func TestShowPlanFileRawCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/state_mv_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestStateMvCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/state_rm_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestStateRmCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion tfexec/taint_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestTaintCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down
79 changes: 77 additions & 2 deletions tfexec/terraform_test.go
Expand Up @@ -32,7 +32,7 @@ func TestMain(m *testing.M) {
func TestSetEnv(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -272,7 +272,11 @@ func TestSetLogPath(t *testing.T) {
})
}

func TestCheckpointDisablePropagation(t *testing.T) {
func TestCheckpointDisablePropagation_v012(t *testing.T) {
if runtime.GOOS == "darwin" && runtime.GOARCH == "arm64" {
t.Skip("Terraform for darwin/arm64 is not available until v1")
}

td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012))
Expand Down Expand Up @@ -351,6 +355,77 @@ func TestCheckpointDisablePropagation(t *testing.T) {
})
}

func TestCheckpointDisablePropagation_v1(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}

err = os.Setenv("CHECKPOINT_DISABLE", "1")
if err != nil {
t.Fatal(err)
}
defer os.Unsetenv("CHECKPOINT_DISABLE")

t.Run("case 1: env var is set in environment and not overridden", func(t *testing.T) {

err = tf.SetEnv(map[string]string{
"FOOBAR": "1",
})
if err != nil {
t.Fatal(err)
}

initCmd, err := tf.initCmd(context.Background())
if err != nil {
t.Fatal(err)
}

assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
"-upgrade=false",
}, map[string]string{
"CHECKPOINT_DISABLE": "1",
"FOOBAR": "1",
}, initCmd)
})

t.Run("case 2: env var is set in environment and overridden with SetEnv", func(t *testing.T) {
err = tf.SetEnv(map[string]string{
"CHECKPOINT_DISABLE": "",
"FOOBAR": "2",
})
if err != nil {
t.Fatal(err)
}

initCmd, err := tf.initCmd(context.Background())
if err != nil {
t.Fatal(err)
}

assertCmd(t, []string{
"init",
"-no-color",
"-force-copy",
"-input=false",
"-backend=true",
"-get=true",
"-upgrade=false",
}, map[string]string{
"CHECKPOINT_DISABLE": "",
"FOOBAR": "2",
}, initCmd)
})
}

// test that a suitable error is returned if NewTerraform is called without a valid
// executable path
func TestNoTerraformBinary(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion tfexec/untaint_test.go
Expand Up @@ -10,7 +10,7 @@ import (
func TestUntaintCmd(t *testing.T) {
td := t.TempDir()

tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013))
tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1))
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit fae0ba3

Please sign in to comment.