add workspace new compat tests
diff --git a/tfexec/internal/e2etest/workspace_test.go b/tfexec/internal/e2etest/workspace_test.go index d5ff3b6..a9ac373 100644 --- a/tfexec/internal/e2etest/workspace_test.go +++ b/tfexec/internal/e2etest/workspace_test.go
@@ -104,6 +104,54 @@ }) } +// The -lock and -lock-timeout flags for terraform workspace new were introduced in 0.12; +// test that earlier versions return a compat error. +func TestWorkspace_compat(t *testing.T) { + // TODO new test helper for compat? + + runTest(t, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { + t.Run("create new workspace with -lock option", func(t *testing.T) { + const newWorkspace = "new1" + err := tf.WorkspaceNew(context.Background(), newWorkspace, tfexec.Lock(true)) + + if tfv.LessThan(version.Must(version.NewVersion("0.12.0"))) { + if err == nil { + t.Fatal("expected error running WorkspaceNew, but got none") + } + var compatErr *tfexec.ErrVersionMismatch + if !errors.As(err, &compatErr) { + t.Fatalf("expected ErrVersionMismatch, but got %s", err) + } + } else { + if err != nil { + t.Fatalf("error creating new workspace: %s", err) + } + } + }) + }) + + runTest(t, "basic", func(t *testing.T, tfv *version.Version, tf *tfexec.Terraform) { + t.Run("create new workspace with -lock-timeout option", func(t *testing.T) { + const newWorkspace = "new1" + err := tf.WorkspaceNew(context.Background(), newWorkspace, tfexec.LockTimeout("909s")) + + if tfv.LessThan(version.Must(version.NewVersion("0.12.0"))) { + if err == nil { + t.Fatal("expected error running WorkspaceNew, but got none") + } + var compatErr *tfexec.ErrVersionMismatch + if !errors.As(err, &compatErr) { + t.Fatalf("expected ErrVersionMismatch, but got %s", err) + } + } else { + if err != nil { + t.Fatalf("error creating new workspace: %s", err) + } + } + }) + }) +} + func assertWorkspaceList(t *testing.T, tf *tfexec.Terraform, expectedCurrent string, expectedWorkspaces ...string) { actualWorkspaces, actualCurrent, err := tf.WorkspaceList(context.Background()) if err != nil {