diff --git a/.circleci/config.yml b/.circleci/config.yml index bd6bb0f3..c1bd2ba7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -37,7 +37,7 @@ jobs: # combined due to slowness of Go install macosbuildtest: macos: - xcode: "12.5.1" + xcode: "13.4.1" steps: - macos_install_go - checkout diff --git a/tfexec/fmt_test.go b/tfexec/fmt_test.go index bdc5b6f3..227b1c5a 100644 --- a/tfexec/fmt_test.go +++ b/tfexec/fmt_test.go @@ -2,19 +2,20 @@ package tfexec import ( "context" - "errors" "runtime" "testing" + + "github.com/hashicorp/terraform-exec/tfexec/internal/testutil" ) -func TestFormat(t *testing.T) { +func TestFormatCmd(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")) + tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1_1)) if err != nil { t.Fatal(err) } @@ -22,15 +23,34 @@ func TestFormat(t *testing.T) { // empty env, to avoid environ mismatch in testing tf.SetEnv(map[string]string{}) - t.Run("too old version", func(t *testing.T) { - _, err := tf.formatCmd(context.Background(), []string{}) - if err == nil { - t.Fatal("expected old version to fail") + t.Run("defaults", func(t *testing.T) { + fmtCmd, err := tf.formatCmd(context.Background(), []string{}) + if err != nil { + t.Fatal(err) } - var expectedErr *ErrVersionMismatch - if !errors.As(err, &expectedErr) { - t.Fatalf("error doesn't match: %#v", err) + assertCmd(t, []string{ + "fmt", + "-no-color", + }, nil, fmtCmd) + }) + + t.Run("override all defaults", func(t *testing.T) { + fmtCmd, err := tf.formatCmd(context.Background(), + []string{"string1", "string2"}, + Recursive(true), + Dir("mydir")) + if err != nil { + t.Fatal(err) } + + assertCmd(t, []string{ + "fmt", + "-no-color", + "string1", + "string2", + "-recursive", + "mydir", + }, nil, fmtCmd) }) } diff --git a/tfexec/workspace_show_test.go b/tfexec/workspace_show_test.go index 411ee6bc..fac6350a 100644 --- a/tfexec/workspace_show_test.go +++ b/tfexec/workspace_show_test.go @@ -2,40 +2,11 @@ package tfexec import ( "context" - "errors" - "runtime" "testing" "github.com/hashicorp/terraform-exec/tfexec/internal/testutil" ) -func TestWorkspaceShowCmd_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, "0.9.11")) - if err != nil { - t.Fatal(err) - } - - // empty env, to avoid environ mismatch in testing - tf.SetEnv(map[string]string{}) - - _, err = tf.workspaceShowCmd(context.Background()) - if err == nil { - t.Fatal("expected old version to fail") - } - - var expectedErr *ErrVersionMismatch - if !errors.As(err, &expectedErr) { - t.Fatalf("error doesn't match: %#v", err) - } - -} - func TestWorkspaceShowCmd_v1(t *testing.T) { td := t.TempDir()