-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tfversion: Add
SkipIfNotAlpha
version check
- Loading branch information
1 parent
7f6b899
commit e7c7ad9
Showing
4 changed files
with
131 additions
and
6 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
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 tfversion | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// SkipIfNotAlpha will skip (pass) the test if the Terraform CLI | ||
// version is not an alpha prerelease (for example, 1.10.0-alpha20241023). | ||
// | ||
// Alpha builds of Terraform include experimental features, so this version check | ||
// can be used for acceptance testing of experimental features, such as deferred actions. | ||
func SkipIfNotAlpha() TerraformVersionCheck { | ||
return skipIfNotAlphaCheck{} | ||
} | ||
|
||
// skipIfNotAlphaCheck implements the TerraformVersionCheck interface | ||
type skipIfNotAlphaCheck struct{} | ||
|
||
// CheckTerraformVersion satisfies the TerraformVersionCheck interface. | ||
func (s skipIfNotAlphaCheck) CheckTerraformVersion(ctx context.Context, req CheckTerraformVersionRequest, resp *CheckTerraformVersionResponse) { | ||
if strings.Contains(req.TerraformVersion.Prerelease(), "alpha") { | ||
return | ||
} | ||
|
||
resp.Skip = fmt.Sprintf("Terraform CLI version %s is not an alpha build: skipping test.", req.TerraformVersion) | ||
} |
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,94 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tfversion_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
|
||
r "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
|
||
testinginterface "github.com/mitchellh/go-testing-interface" | ||
) | ||
|
||
func Test_SkipIfNotAlpha_SkipTest_Stable(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0") | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": func() (tfprotov6.ProviderServer, error) { //nolint:unparam // required signature | ||
return nil, nil | ||
}, | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func Test_SkipIfNotAlpha_SkipTest_Beta1(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-beta1") | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": providerserver.NewProviderServer(testprovider.Provider{}), | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} | ||
func Test_SkipIfNotAlpha_SkipTest_RC(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.8.0-rc2") | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": providerserver.NewProviderServer(testprovider.Provider{}), | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func Test_SkipIfNotAlpha_RunTest_Alpha(t *testing.T) { //nolint:paralleltest | ||
t.Setenv("TF_ACC_TERRAFORM_PATH", "") | ||
t.Setenv("TF_ACC_TERRAFORM_VERSION", "1.9.0-alpha20240501") | ||
|
||
r.UnitTest(&testinginterface.RuntimeT{}, r.TestCase{ | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"test": providerserver.NewProviderServer(testprovider.Provider{}), | ||
}, | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipIfNotAlpha(), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
Config: `//non-empty config`, | ||
}, | ||
}, | ||
}) | ||
} |