Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fmt: Gate formatting command on 0.7.7 #88

Merged
merged 3 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tfexec/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func (tf *Terraform) FormatCheck(ctx context.Context, opts ...FormatOption) (boo
}

func (tf *Terraform) formatCmd(ctx context.Context, args []string, opts ...FormatOption) (*exec.Cmd, error) {
err := tf.compatible(ctx, tf0_7_7, nil)
if err != nil {
return nil, fmt.Errorf("fmt was first introduced in Terraform 0.7.7: %w", err)
}

c := defaultFormatConfig

for _, o := range opts {
Expand Down
33 changes: 33 additions & 0 deletions tfexec/fmt_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package tfexec

import (
"context"
"errors"
"os"
"testing"
)

func TestFormat(t *testing.T) {
td := testTempDir(t)
defer os.RemoveAll(td)

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

// 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")
}

var expectedErr *ErrVersionMismatch
if !errors.As(err, &expectedErr) {
t.Fatalf("error doesn't match: %#v", err)
}
})
}
1 change: 1 addition & 0 deletions tfexec/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
)

var (
tf0_7_7 = version.Must(version.NewVersion("0.7.7"))
tf0_12_0 = version.Must(version.NewVersion("0.12.0"))
tf0_13_0 = version.Must(version.NewVersion("0.13.0"))
)
Expand Down