-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `tfversion` package and `TerraformVersionCheck` interface * Add `TerraformVersionChecks` field and implement checks in `Test()` * Extract `testExpectTFatal()` to internal/plugintest package * Implement built-in version checks * Add documentation for version checks * fix typo * Add Terraform Version Checks page to website navigation * Add comment for `All()` and fix test * Add Changie Entries * Add copyright headers * Add comments to tests * Add tfversion_checks_test.go * Rename interface request and response to avoid abbreviation * Add version variables * Update documentation to include and use pre-defined version variables Co-authored-by: Brian Flad <bflad417@gmail.com> * Add copyright header * Properly handle error Co-authored-by: Brian Flad <bflad417@gmail.com> * Set golangci-lint run timeout to 5 minutes * Fix wording in logging messages Co-authored-by: Brian Flad <bflad417@gmail.com> --------- Co-authored-by: Brian Flad <bflad417@gmail.com>
- Loading branch information
Showing
46 changed files
with
1,776 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Introduced new `tfversion` package with interface and built-in Terraform | ||
version check functionality' | ||
time: 2023-06-02T10:15:45.704158-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `SkipAbove` built-in version check, which skips the test if | ||
the Terraform CLI version is above the given maximum.' | ||
time: 2023-06-02T12:44:03.123635-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `SkipBelow` built-in version check, which skips the test if | ||
the Terraform CLI version is below the given minimum.' | ||
time: 2023-06-02T12:44:37.228557-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `SkipBetween` built-in version check, which skips the test | ||
if the Terraform CLI version is between the given minimum (inclusive) and maximum | ||
(exclusive).' | ||
time: 2023-06-02T12:44:53.737283-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `SkipIf` built-in version check, which skips the test if the | ||
Terraform CLI version matches the given version.' | ||
time: 2023-06-02T12:45:14.812485-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `RequireAbove` built-in version check, which fails the test | ||
if the Terraform CLI version is below the given maximum.' | ||
time: 2023-06-02T12:45:32.983833-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `RequireBelow` built-in version check, which fails the test | ||
if the Terraform CLI version is above the given minimum.' | ||
time: 2023-06-02T12:46:53.705136-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `RequireBetween` built-in version check, fails the test if | ||
the Terraform CLI version is outside the given minimum (exclusive) and maximum (inclusive).' | ||
time: 2023-06-02T12:47:11.762061-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `RequireNot` built-in version check, which fails the test | ||
if the Terraform CLI version matches the given version.' | ||
time: 2023-06-02T12:47:32.000508-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `Any` built-in version check, which fails the test if none | ||
of the given sub-checks return a nil error and empty skip message.' | ||
time: 2023-06-02T12:47:53.181503-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
kind: FEATURES | ||
body: 'tfversion: Added `All` built-in version check, which fails or skips the test | ||
if any of the given sub-checks return a non-nil error or non-empty skip message.' | ||
time: 2023-06-02T12:48:07.933978-04:00 | ||
custom: | ||
Issue: "128" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,8 @@ linters: | |
- unconvert | ||
- unparam | ||
- unused | ||
- vet | ||
- vet | ||
|
||
run: | ||
# Prevent false positive timeouts in CI | ||
timeout: 5m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package resource | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/go-version" | ||
"github.com/mitchellh/go-testing-interface" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
) | ||
|
||
func runTFVersionChecks(ctx context.Context, t testing.T, terraformVersion *version.Version, terraformVersionChecks []tfversion.TerraformVersionCheck) { | ||
t.Helper() | ||
|
||
for _, tfVersionCheck := range terraformVersionChecks { | ||
resp := tfversion.CheckTerraformVersionResponse{} | ||
tfVersionCheck.CheckTerraformVersion(ctx, tfversion.CheckTerraformVersionRequest{TerraformVersion: terraformVersion}, &resp) | ||
|
||
if resp.Error != nil { | ||
t.Fatalf(resp.Error.Error()) | ||
} | ||
|
||
if resp.Skip != "" { | ||
t.Skip(resp.Skip) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package resource | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/hashicorp/go-version" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/internal/plugintest" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
|
||
testinginterface "github.com/mitchellh/go-testing-interface" | ||
) | ||
|
||
func TestRunTFVersionChecks(t *testing.T) { | ||
t.Parallel() | ||
|
||
tests := map[string]struct { | ||
versionChecks []tfversion.TerraformVersionCheck | ||
tfVersion *version.Version | ||
expectError bool | ||
}{ | ||
"run-test": { | ||
versionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIf(version.Must(version.NewVersion("1.1.0"))), | ||
tfversion.RequireAbove(version.Must(version.NewVersion("1.2.0"))), | ||
}, | ||
tfVersion: version.Must(version.NewVersion("1.3.0")), | ||
expectError: false, | ||
}, | ||
"skip-test": { | ||
versionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIf(version.Must(version.NewVersion("1.1.0"))), | ||
}, | ||
tfVersion: version.Must(version.NewVersion("1.1.0")), | ||
expectError: false, | ||
}, | ||
"fail-test": { | ||
versionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.RequireNot(version.Must(version.NewVersion("1.1.0"))), | ||
}, | ||
tfVersion: version.Must(version.NewVersion("1.1.0")), | ||
expectError: true, | ||
}, | ||
} | ||
|
||
for name, test := range tests { | ||
name, test := name, test | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if test.expectError { | ||
plugintest.TestExpectTFatal(t, func() { | ||
runTFVersionChecks(context.Background(), &testinginterface.RuntimeT{}, test.tfVersion, test.versionChecks) | ||
}) | ||
} else { | ||
runTFVersionChecks(context.Background(), t, test.tfVersion, test.versionChecks) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.