cloud: Skip E2E tests without an exact version

This commit is contained in:
Chris Arcand 2021-10-27 18:07:12 -05:00
parent e364ef2905
commit f881c2d794
9 changed files with 55 additions and 30 deletions

View File

@ -13,14 +13,13 @@ import (
expect "github.com/Netflix/go-expect"
tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/terraform/internal/e2e"
tfversion "github.com/hashicorp/terraform/version"
)
func Test_terraform_apply_autoApprove(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
tfVersion := "1.1.0-tfc-integration"
if !hasTerraformVersion(t, tfVersion) {
t.Skip("Skipping test because TFC does not have current terraform version.")
}
cases := map[string]struct {
operations []operationSets
@ -33,7 +32,7 @@ func Test_terraform_apply_autoApprove(t *testing.T) {
wsName := "app"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(wsName),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
AutoApply: tfe.Bool(false),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
@ -73,7 +72,7 @@ func Test_terraform_apply_autoApprove(t *testing.T) {
wsName := "app"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(wsName),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
AutoApply: tfe.Bool(true),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
@ -113,7 +112,7 @@ func Test_terraform_apply_autoApprove(t *testing.T) {
wsName := "app"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(wsName),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
AutoApply: tfe.Bool(false),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
@ -151,7 +150,7 @@ func Test_terraform_apply_autoApprove(t *testing.T) {
wsName := "app"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(wsName),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
AutoApply: tfe.Bool(true),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)

View File

@ -14,6 +14,8 @@ import (
)
func Test_backend_apply_before_init(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
cases := map[string]struct {
operations []operationSets
}{

View File

@ -12,6 +12,7 @@ import (
tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/go-uuid"
tfversion "github.com/hashicorp/terraform/version"
)
const (
@ -193,7 +194,8 @@ func writeMainTF(t *testing.T, block string, dir string) {
}
// Ensure that TFC/E has a particular terraform version.
func hasTerraformVersion(t *testing.T, version string) bool {
func skipWithoutRemoteTerraformVersion(t *testing.T) {
version := tfversion.String()
opts := tfe.AdminTerraformVersionsListOptions{
ListOptions: tfe.ListOptions{
PageNumber: 1,
@ -226,5 +228,7 @@ findTfVersion:
opts.PageNumber = tfVersionList.NextPage
}
return hasVersion
if !hasVersion {
t.Skip(fmt.Sprintf("Skipping test because TFC/E does not have current Terraform version to test with (%s)", version))
}
}

View File

@ -13,6 +13,7 @@ import (
"testing"
tfe "github.com/hashicorp/go-tfe"
tfversion "github.com/hashicorp/terraform/version"
)
var terraformBin string
@ -97,7 +98,12 @@ func setupBinary() func() {
log.Fatal(err)
}
cmd := exec.Command("go", "build", "-o", tmpTerraformBinaryDir)
cmd := exec.Command(
"go",
"build",
"-o", tmpTerraformBinaryDir,
"-ldflags", fmt.Sprintf("-X \"github.com/hashicorp/terraform/version.Prerelease=%s\"", tfversion.Prerelease),
)
err = cmd.Run()
if err != nil {
log.Fatal(err)

View File

@ -15,6 +15,8 @@ import (
)
func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {
@ -242,6 +244,8 @@ func Test_migrate_multi_to_tfc_cloud_name_strategy(t *testing.T) {
}
func Test_migrate_multi_to_tfc_cloud_tags_strategy(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {

View File

@ -15,6 +15,8 @@ import (
)
func Test_migrate_remote_backend_name_to_tfc_name(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {
operations []operationSets
@ -197,6 +199,8 @@ func Test_migrate_remote_backend_name_to_tfc_name(t *testing.T) {
}
func Test_migrate_remote_backend_name_to_tfc_name_different_org(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {
operations []operationSets
@ -334,6 +338,8 @@ func Test_migrate_remote_backend_name_to_tfc_name_different_org(t *testing.T) {
}
func Test_migrate_remote_backend_name_to_tfc_tags(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {
operations []operationSets
@ -477,6 +483,8 @@ func Test_migrate_remote_backend_name_to_tfc_tags(t *testing.T) {
}
func Test_migrate_remote_backend_prefix_to_tfc_name(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {
operations []operationSets
@ -695,6 +703,8 @@ func Test_migrate_remote_backend_prefix_to_tfc_name(t *testing.T) {
}
func Test_migrate_remote_backend_prefix_to_tfc_tags(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {
operations []operationSets

View File

@ -15,6 +15,8 @@ import (
)
func Test_migrate_single_to_tfc(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
cases := map[string]struct {

View File

@ -13,14 +13,12 @@ import (
expect "github.com/Netflix/go-expect"
tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/terraform/internal/e2e"
tfversion "github.com/hashicorp/terraform/version"
)
func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
tfVersion := "1.1.0-alpha-20211027-dev-e51508be"
if !hasTerraformVersion(t, tfVersion) {
t.Skip("Skipping test because TFC does not have current terraform version.")
}
cases := map[string]struct {
setup func(t *testing.T) (string, func())
@ -42,7 +40,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
// terraform version of this current branch.
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("prod"),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
writeMainTF(t, tfBlock, dir)
@ -69,7 +67,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
wsName := "dev"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(wsName),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
writeMainTF(t, tfBlock, dir)
@ -110,7 +108,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
wsName := "prod"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("prod"),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
writeMainTF(t, tfBlock, dir)
@ -174,7 +172,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
wsName := "prod"
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("prod"),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendName(orgName, wsName)
writeMainTF(t, tfBlock, dir)
@ -200,7 +198,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
// version that does not support `cloud`.
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("new-workspace"),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendTags(orgName, tag)
writeMainTF(t, tfBlock, dir)
@ -214,7 +212,7 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
postInputOutput: []string{
// this is a temporary measure till we resolve some of the
// version mismatching.
fmt.Sprintf(`Remote workspace Terraform version "%s" does not match local Terraform version`, tfVersion)},
fmt.Sprintf(`Remote workspace Terraform version "%s" does not match local Terraform version`, tfversion.String())},
},
},
},
@ -308,11 +306,9 @@ func Test_migrate_tfc_to_tfc_single_workspace(t *testing.T) {
}
func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
ctx := context.Background()
tfVersion := "1.1.0-alpha-20211027-dev-e51508be"
if !hasTerraformVersion(t, tfVersion) {
t.Skip("Skipping test because TFC does not have current terraform version.")
}
cases := map[string]struct {
setup func(t *testing.T) (string, func())
@ -331,12 +327,12 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) {
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("app-prod"),
Tags: []*tfe.Tag{{Name: tag}},
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("app-staging"),
Tags: []*tfe.Tag{{Name: tag}},
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendTags(orgName, tag)
writeMainTF(t, tfBlock, dir)
@ -378,7 +374,7 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) {
// using the right version for post init operations.
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String(name),
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendName(orgName, name)
writeMainTF(t, tfBlock, dir)
@ -425,12 +421,12 @@ func Test_migrate_tfc_to_tfc_multiple_workspace(t *testing.T) {
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("app-prod"),
Tags: []*tfe.Tag{{Name: tag}},
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
_ = createWorkspace(t, orgName, tfe.WorkspaceCreateOptions{
Name: tfe.String("app-staging"),
Tags: []*tfe.Tag{{Name: tag}},
TerraformVersion: tfe.String(tfVersion),
TerraformVersion: tfe.String(tfversion.String()),
})
tfBlock := terraformConfigCloudBackendTags(orgName, tag)
writeMainTF(t, tfBlock, dir)

View File

@ -46,6 +46,8 @@ output "test_env" {
}
func Test_cloud_run_variables(t *testing.T) {
skipWithoutRemoteTerraformVersion(t)
cases := testCases{
"run variables from CLI arg": {
operations: []operationSets{