From 81eb5413eadb178417a54ab48face7ee41e5f8b7 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Thu, 2 Sep 2021 14:48:51 +0100 Subject: [PATCH 1/5] use last two stable Go versions --- .circleci/config.yml | 152 +++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 93 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8969bc0a..e6ebbcf8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -59,22 +59,16 @@ jobs: - go_unit_test - go_e2e_test - go113_build: - docker: - - image: circleci/golang:1.13 - steps: - - checkout - - go_build - - go114_build: + # previous stable Go version + go116_build: docker: - - image: circleci/golang:1.14 + - image: circleci/golang:1.16 steps: - checkout - go_build - go114_test: + go116_test: docker: - - image: circleci/golang:1.14 + - image: circleci/golang:1.16 parameters: test_results: type: string @@ -83,15 +77,16 @@ jobs: - checkout - go_unit_test - go115_build: + # latest stable Go version + go117_build: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.17 steps: - checkout - go_build - go115_test: + go117_test: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.17 parameters: test_results: type: string @@ -99,11 +94,11 @@ jobs: steps: - checkout - go_unit_test - go116_test_main: + go117_test_main: environment: TFEXEC_E2ETEST_VERSIONS: refs/heads/main docker: - - image: circleci/golang:1.16 + - image: circleci/golang:1.17 parameters: test_results: type: string @@ -112,33 +107,28 @@ jobs: - checkout - go_unit_test - go_e2e_test - go115_vet: + go117_vet: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.17 steps: - checkout - run: go vet ./... - go115_fmt: + go117_fmt: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.17 steps: - checkout - run: gofmt -s -l . - go115_release: + go117_release: docker: - - image: circleci/golang:1.15 + - image: circleci/golang:1.17 steps: - add_ssh_keys: fingerprints: - db:cf:97:b8:d6:ac:86:74:96:e1:54:e4:bc:27:2b:d0 - checkout - run: ./scripts/release/release.sh - go116_build: - docker: - - image: circleci/golang:1.16 - steps: - - checkout - - go_build + workflows: version: 2 pr: @@ -146,27 +136,23 @@ workflows: - winbuildtest - macosbuildtest - # build only for these versions - - go113_build - - - go114_build - - go114_test: + - go116_build + - go116_test: requires: - - go114_build - - - go115_build - - go115_test: + - go116_build + - go117_build + - go117_test: requires: - - go115_build - - go116_test_main: + - go117_build + - go117_test_main: requires: - - go115_build - - go115_vet: + - go117_build + - go117_vet: requires: - - go115_build - - go115_fmt: + - go117_build + - go117_fmt: requires: - - go115_build + - go117_build release: jobs: - winbuildtest: @@ -179,65 +165,54 @@ workflows: branches: only: - main - - # build only for these versions - - go113_build: - filters: - branches: - only: - - main - - - go114_build: + - go116_build: filters: branches: only: - main - - go114_test: + - go116_test: requires: - - go114_build + - go116_build filters: branches: only: - main - - go115_build: + - go117_build: filters: branches: only: - main - - go115_test: + - go117_test: requires: - - go115_build + - go117_build filters: branches: only: - main - - go116_test_main: + + - go117_test_main: requires: - - go116_build + - go117_build filters: branches: only: - main - - go115_vet: + - go117_vet: requires: - - go115_build + - go117_build filters: branches: only: - main - - go115_fmt: + - go117_fmt: requires: - - go115_build - filters: - branches: - only: - - main - - go116_build: + - go117_build filters: branches: only: - main + - trigger-release: filters: branches: @@ -245,19 +220,16 @@ workflows: - main type: approval - - go115_release: + - go117_release: filters: branches: only: - main requires: - trigger-release - - go113_build - - go114_test - - go115_test - - go116_test_main - - go115_vet - - go115_fmt + - go117_test_main + - go117_vet + - go117_fmt - winbuildtest - macosbuildtest nightly: @@ -275,36 +247,31 @@ workflows: - slack/notify: event: fail template: basic_fail_1 - - go113_build: - post-steps: - - slack/notify: - event: fail - template: basic_fail_1 - - go114_build: + - go116_build: post-steps: - slack/notify: event: fail template: basic_fail_1 - - go114_test: + - go116_test: post-steps: - slack/notify: event: fail template: basic_fail_1 requires: - - go114_build - - go115_build: + - go116_build + - go117_build: post-steps: - slack/notify: event: fail template: basic_fail_1 - - go115_test: + - go117_test: post-steps: - slack/notify: event: fail template: basic_fail_1 requires: - - go115_build - - go116_test_main: + - go117_build + - go117_test_main: post-steps: - slack/notify: event: fail @@ -327,9 +294,8 @@ workflows: ] } requires: - - go115_build - - go115_test - - go114_test - - go113_build + - go116_build + - go116_test + - go117_build - winbuildtest - macosbuildtest From a8dbca0212687d60fc31fc54516a34b73341f54a Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Thu, 21 Oct 2021 15:27:10 +0100 Subject: [PATCH 2/5] remove code specific to Go 1.12 --- tfexec/cmdstring.go | 3 --- tfexec/cmdstring_go112.go | 19 ------------------- 2 files changed, 22 deletions(-) delete mode 100644 tfexec/cmdstring_go112.go diff --git a/tfexec/cmdstring.go b/tfexec/cmdstring.go index 4f81d114..72370c4f 100644 --- a/tfexec/cmdstring.go +++ b/tfexec/cmdstring.go @@ -1,12 +1,9 @@ -// +build go1.13 - package tfexec import ( "os/exec" ) -// cmdString handles go 1.12 as stringer was only added to exec.Cmd in 1.13 func cmdString(c *exec.Cmd) string { return c.String() } diff --git a/tfexec/cmdstring_go112.go b/tfexec/cmdstring_go112.go deleted file mode 100644 index 75614dbf..00000000 --- a/tfexec/cmdstring_go112.go +++ /dev/null @@ -1,19 +0,0 @@ -// +build !go1.13 - -package tfexec - -import ( - "os/exec" - "strings" -) - -// cmdString handles go 1.12 as stringer was only added to exec.Cmd in 1.13 -func cmdString(c *exec.Cmd) string { - b := new(strings.Builder) - b.WriteString(c.Path) - for _, a := range c.Args[1:] { - b.WriteByte(' ') - b.WriteString(a) - } - return b.String() -} From 6590b885d0788aa0612beb92fc768a2efc2f4f53 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Thu, 21 Oct 2021 15:31:47 +0100 Subject: [PATCH 3/5] remove code specific to Go<1.14 The TFCache.find() function made use of t.Cleanup(), which was not available until Go 1.14. --- tfexec/internal/testutil/tfcache_find.go | 2 -- tfexec/internal/testutil/tfcache_find_noop.go | 14 -------------- 2 files changed, 16 deletions(-) delete mode 100644 tfexec/internal/testutil/tfcache_find_noop.go diff --git a/tfexec/internal/testutil/tfcache_find.go b/tfexec/internal/testutil/tfcache_find.go index 28a249a4..eb03bcb7 100644 --- a/tfexec/internal/testutil/tfcache_find.go +++ b/tfexec/internal/testutil/tfcache_find.go @@ -1,5 +1,3 @@ -// +build go1.14 - package testutil import ( diff --git a/tfexec/internal/testutil/tfcache_find_noop.go b/tfexec/internal/testutil/tfcache_find_noop.go deleted file mode 100644 index 5b8909d7..00000000 --- a/tfexec/internal/testutil/tfcache_find_noop.go +++ /dev/null @@ -1,14 +0,0 @@ -// +build !go1.14 - -package testutil - -import ( - "runtime" - "testing" - - "github.com/hashicorp/terraform-exec/tfinstall" -) - -func (tf *TFCache) find(t *testing.T, key string, finder func(dir string) tfinstall.ExecPathFinder) string { - panic("not implemented for " + runtime.Version()) -} From cafc1e0683cbaea6ebf5e54de2f0a89f63f3e7f1 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Thu, 21 Oct 2021 15:40:25 +0100 Subject: [PATCH 4/5] remove code specific to Go<1.14 The testTempDir() function made use of t.Cleanup(), which was not available until Go 1.14. --- tfexec/add_test.go | 2 +- tfexec/apply_test.go | 2 +- tfexec/destroy_test.go | 2 +- tfexec/fmt_test.go | 2 +- tfexec/get_test.go | 2 +- tfexec/import_test.go | 2 +- tfexec/init_test.go | 2 +- tfexec/internal/testutil/temp_dir.go | 24 ------------------------ tfexec/output_test.go | 2 +- tfexec/plan_test.go | 2 +- tfexec/providers_lock_test.go | 2 +- tfexec/providers_schema_test.go | 2 +- tfexec/refresh_test.go | 2 +- tfexec/show_test.go | 8 ++++---- tfexec/state_mv_test.go | 2 +- tfexec/state_rm_test.go | 2 +- tfexec/terraform_test.go | 10 +++------- tfexec/upgrade012_test.go | 2 +- tfexec/upgrade013_test.go | 2 +- tfexec/workspace_new_test.go | 2 +- 20 files changed, 24 insertions(+), 52 deletions(-) delete mode 100644 tfexec/internal/testutil/temp_dir.go diff --git a/tfexec/add_test.go b/tfexec/add_test.go index 1af63cc7..cfe92ae4 100644 --- a/tfexec/add_test.go +++ b/tfexec/add_test.go @@ -8,7 +8,7 @@ import ( ) func TestAddCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1_1)) if err != nil { diff --git a/tfexec/apply_test.go b/tfexec/apply_test.go index e43fe2e8..1cf2f562 100644 --- a/tfexec/apply_test.go +++ b/tfexec/apply_test.go @@ -8,7 +8,7 @@ import ( ) func TestApplyCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1)) if err != nil { diff --git a/tfexec/destroy_test.go b/tfexec/destroy_test.go index 7ee20793..93daf356 100644 --- a/tfexec/destroy_test.go +++ b/tfexec/destroy_test.go @@ -8,7 +8,7 @@ import ( ) func TestDestroyCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/fmt_test.go b/tfexec/fmt_test.go index 4abe1128..0403067d 100644 --- a/tfexec/fmt_test.go +++ b/tfexec/fmt_test.go @@ -7,7 +7,7 @@ import ( ) func TestFormat(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, "0.7.6")) if err != nil { diff --git a/tfexec/get_test.go b/tfexec/get_test.go index 5254e967..2e2aa6ef 100644 --- a/tfexec/get_test.go +++ b/tfexec/get_test.go @@ -8,7 +8,7 @@ import ( ) func TestGetCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/import_test.go b/tfexec/import_test.go index 2f81e768..2a9d0af6 100644 --- a/tfexec/import_test.go +++ b/tfexec/import_test.go @@ -8,7 +8,7 @@ import ( ) func TestImportCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/init_test.go b/tfexec/init_test.go index 5eea7ef1..cafa5db1 100644 --- a/tfexec/init_test.go +++ b/tfexec/init_test.go @@ -8,7 +8,7 @@ import ( ) func TestInitCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/internal/testutil/temp_dir.go b/tfexec/internal/testutil/temp_dir.go deleted file mode 100644 index 618a4fd6..00000000 --- a/tfexec/internal/testutil/temp_dir.go +++ /dev/null @@ -1,24 +0,0 @@ -// +build go1.14 - -package testutil - -import ( - "io/ioutil" - "os" - "testing" -) - -// TODO: Remove once we drop support for Go <1.15 -// in favour of native t.TempDir() -func TempDir(t *testing.T) string { - dir, err := ioutil.TempDir("", "tf") - if err != nil { - t.Fatalf("error creating temporary test directory: %s", err) - } - - t.Cleanup(func() { - os.RemoveAll(dir) - }) - - return dir -} diff --git a/tfexec/output_test.go b/tfexec/output_test.go index 01249b53..6a7d5305 100644 --- a/tfexec/output_test.go +++ b/tfexec/output_test.go @@ -8,7 +8,7 @@ import ( ) func TestOutputCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/plan_test.go b/tfexec/plan_test.go index 16a376bf..7a467ac3 100644 --- a/tfexec/plan_test.go +++ b/tfexec/plan_test.go @@ -8,7 +8,7 @@ import ( ) func TestPlanCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest_v1)) if err != nil { diff --git a/tfexec/providers_lock_test.go b/tfexec/providers_lock_test.go index 9d5b8dbc..f8e2591c 100644 --- a/tfexec/providers_lock_test.go +++ b/tfexec/providers_lock_test.go @@ -8,7 +8,7 @@ import ( ) func TestProvidersLockCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/providers_schema_test.go b/tfexec/providers_schema_test.go index 640e2661..b84cf733 100644 --- a/tfexec/providers_schema_test.go +++ b/tfexec/providers_schema_test.go @@ -8,7 +8,7 @@ import ( ) func TestProvidersSchemaCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/refresh_test.go b/tfexec/refresh_test.go index e17d9938..b06901cb 100644 --- a/tfexec/refresh_test.go +++ b/tfexec/refresh_test.go @@ -8,7 +8,7 @@ import ( ) func TestRefreshCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013)) if err != nil { diff --git a/tfexec/show_test.go b/tfexec/show_test.go index b33ab6c2..3cc46362 100644 --- a/tfexec/show_test.go +++ b/tfexec/show_test.go @@ -8,7 +8,7 @@ import ( ) func TestShowCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { @@ -29,7 +29,7 @@ func TestShowCmd(t *testing.T) { } func TestShowStateFileCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { @@ -50,7 +50,7 @@ func TestShowStateFileCmd(t *testing.T) { } func TestShowPlanFileCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { @@ -71,7 +71,7 @@ func TestShowPlanFileCmd(t *testing.T) { } func TestShowPlanFileRawCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { diff --git a/tfexec/state_mv_test.go b/tfexec/state_mv_test.go index 9164185c..775756d2 100644 --- a/tfexec/state_mv_test.go +++ b/tfexec/state_mv_test.go @@ -8,7 +8,7 @@ import ( ) func TestStateMvCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013)) if err != nil { diff --git a/tfexec/state_rm_test.go b/tfexec/state_rm_test.go index e2794e4e..a1904a6d 100644 --- a/tfexec/state_rm_test.go +++ b/tfexec/state_rm_test.go @@ -8,7 +8,7 @@ import ( ) func TestStateRmCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013)) if err != nil { diff --git a/tfexec/terraform_test.go b/tfexec/terraform_test.go index 742e20f1..d8f4ab4c 100644 --- a/tfexec/terraform_test.go +++ b/tfexec/terraform_test.go @@ -28,7 +28,7 @@ func TestMain(m *testing.M) { } func TestSetEnv(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { @@ -62,7 +62,7 @@ func TestSetEnv(t *testing.T) { } func TestCheckpointDisablePropagation(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) if err != nil { @@ -143,7 +143,7 @@ func TestCheckpointDisablePropagation(t *testing.T) { // test that a suitable error is returned if NewTerraform is called without a valid // executable path func TestNoTerraformBinary(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() _, err := NewTerraform(td, "") if err == nil { @@ -156,10 +156,6 @@ func TestNoTerraformBinary(t *testing.T) { } } -func testTempDir(t *testing.T) string { - return testutil.TempDir(t) -} - func tfVersion(t *testing.T, v string) string { if tfCache == nil { t.Fatalf("tfCache not yet configured, TestMain must run first") diff --git a/tfexec/upgrade012_test.go b/tfexec/upgrade012_test.go index 958d0d24..db61bd78 100644 --- a/tfexec/upgrade012_test.go +++ b/tfexec/upgrade012_test.go @@ -10,7 +10,7 @@ import ( ) func TestUpgrade012(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() t.Run("defaults", func(t *testing.T) { tf, err := NewTerraform(td, tfVersion(t, testutil.Latest012)) diff --git a/tfexec/upgrade013_test.go b/tfexec/upgrade013_test.go index 7a6220d0..1ab79b41 100644 --- a/tfexec/upgrade013_test.go +++ b/tfexec/upgrade013_test.go @@ -10,7 +10,7 @@ import ( ) func TestUpgrade013(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() t.Run("defaults", func(t *testing.T) { tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013)) diff --git a/tfexec/workspace_new_test.go b/tfexec/workspace_new_test.go index eaf7c9db..5831e87c 100644 --- a/tfexec/workspace_new_test.go +++ b/tfexec/workspace_new_test.go @@ -9,7 +9,7 @@ import ( ) func TestWorkspaceNewCmd(t *testing.T) { - td := testTempDir(t) + td := t.TempDir() tf, err := NewTerraform(td, tfVersion(t, testutil.Latest013)) if err != nil { From 16ed05937f309632a607be109b5b9e05eeb5f6a0 Mon Sep 17 00:00:00 2001 From: Katy Moe Date: Thu, 21 Oct 2021 16:54:25 +0100 Subject: [PATCH 5/5] remove code specitic to Go<1.13 The cmdString() function made use of Cmd.String(), which was not available until Go 1.13. --- tfexec/cmd.go | 2 +- tfexec/cmdstring.go | 9 --------- 2 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 tfexec/cmdstring.go diff --git a/tfexec/cmd.go b/tfexec/cmd.go index e792dc9c..83abd22d 100644 --- a/tfexec/cmd.go +++ b/tfexec/cmd.go @@ -176,7 +176,7 @@ func (tf *Terraform) buildTerraformCmd(ctx context.Context, mergeEnv map[string] cmd.Env = tf.buildEnv(mergeEnv) cmd.Dir = tf.workingDir - tf.logger.Printf("[INFO] running Terraform command: %s", cmdString(cmd)) + tf.logger.Printf("[INFO] running Terraform command: %s", cmd.String()) return cmd } diff --git a/tfexec/cmdstring.go b/tfexec/cmdstring.go deleted file mode 100644 index 72370c4f..00000000 --- a/tfexec/cmdstring.go +++ /dev/null @@ -1,9 +0,0 @@ -package tfexec - -import ( - "os/exec" -) - -func cmdString(c *exec.Cmd) string { - return c.String() -}