Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Derekm/speed up tests #1144

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ testacc-ci: fmtcheck
echo "See the contributing guide for more information: https://github.com/hashicorp/terraform-provider-hcp/blob/main/contributing/writing-tests.md"; \
exit 1; \
fi
TF_ACC=1 go test -short -coverprofile=coverage-e2e.out $(TEST) -v $(TESTARGS) -timeout $(TIMEOUT) -parallel=10
TF_ACC=1 go test -short -coverprofile=coverage-e2e.out $(TEST) -v $(TESTARGS) -timeout $(TIMEOUT) -parallel=100
go tool cover -html=coverage-e2e.out -o coverage-e2e.html

depscheck:
Expand Down
6 changes: 3 additions & 3 deletions contributing/writing-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export TF_LOG=...

Terraform has a framework for writing acceptance tests which minimizes the
amount of boilerplate code necessary to use common testing patterns. The entry
point to the framework is the `resource.Test()` function.
point to the framework is the `resource.ParallelTest()` function.

Tests are divided into `TestStep`s. Each `TestStep` proceeds by applying some
Terraform configuration using the provider under test, and then verifying that
Expand All @@ -88,7 +88,7 @@ to a single resource. Most tests follow a similar structure.
to running acceptance tests. This is common to all tests exercising a single
provider.

Each `TestStep` is defined in the call to `resource.Test()`. Most assertion
Each `TestStep` is defined in the call to `resource.ParallelTest()`. Most assertion
functions are defined out of band with the tests. This keeps the tests
readable, and allows reuse of assertion functions across different tests of the
same type of resource. The definition of a complete test looks like this:
Expand All @@ -97,7 +97,7 @@ same type of resource. The definition of a complete test looks like this:
func TestAccConsulCluster(t *testing.T) {
resourceName := "hcp_consul_cluster.test"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: testAccCheckConsulClusterDestroy,
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/iam/data_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func TestAccServicePrincipalDataSource(t *testing.T) {
name := acctest.RandString(16)

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAccServicePrincipalKeyResource(t *testing.T) {
spName := acctest.RandString(16)
var spk, spk2, spk3 models.HashicorpCloudIamServicePrincipalKey

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
6 changes: 3 additions & 3 deletions internal/provider/iam/resource_service_principal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccServicePrincipalResource_Project(t *testing.T) {
var sp models.HashicorpCloudIamServicePrincipal
var sp2 models.HashicorpCloudIamServicePrincipal

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down Expand Up @@ -67,7 +67,7 @@ func TestAccServicePrincipalResource_ExplicitProject(t *testing.T) {
spName := acctest.RandString(16)
var sp models.HashicorpCloudIamServicePrincipal

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand All @@ -90,7 +90,7 @@ func TestAccServicePrincipalResource_Organization(t *testing.T) {
spName := acctest.RandString(16)
var sp models.HashicorpCloudIamServicePrincipal

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccHCPLogStreamingDestinationSplunk(t *testing.T) {
var sp models.LogService20210330Destination
var sp2 models.LogService20210330Destination

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
CheckDestroy: func(s *terraform.State) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestAccIAMPolicyDataSource(t *testing.T) {
role1, role2 := "roles/viewer", "roles/admin"
var p1, p2 models.HashicorpCloudResourcemanagerPolicy

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down Expand Up @@ -80,7 +80,7 @@ func TestAccIAMPolicyDataSource_Validation(t *testing.T) {
principals[i] = fmt.Sprintf("%d", i)
}

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
IsUnitTest: true,
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestAccOrganizationDataSource(t *testing.T) {
dataSourceAddress := "data.hcp_organization.org"
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccProjectDataSource(t *testing.T) {
project := acctest.RandString(16)
description := acctest.RandString(64)

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestAccOrganizationIamBindingResource(t *testing.T) {
roleName := "roles/contributor"
roleName2 := "roles/viewer"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestAccProjectIamPolicyResource(t *testing.T) {
roleName := "roles/contributor"
roleName2 := "roles/viewer"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down Expand Up @@ -54,7 +54,7 @@ func TestAccProjectIamBindingResource(t *testing.T) {
roleName := "roles/contributor"
roleName2 := "roles/viewer"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccProjectResource(t *testing.T) {

projectNameUpdated := acctest.RandString(16)
descriptionUpdated := acctest.RandString(200)
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAcc_dataSourceVaultSecretsAppMigration(t *testing.T) {
firstSecretValue := "hey, this is version 1!"
secondSecretValue := "hey, this is version 2!"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
Steps: []resource.TestStep{
// Create two secrets, one with an additional version and check the latest secrets from data source
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestAcc_dataSourceVaultSecretsApp(t *testing.T) {
firstSecretValue := "hey, this is version 1!"
secondSecretValue := "hey, this is version 2!"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestAcc_dataSourceVaultSecretsSecret(t *testing.T) {
testSecretName := "secret_one"
testSecretValue := "some value"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acctest.PreCheck(t) },
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestAccVaultSecretsResourceApp(t *testing.T) {
testAppName := generateRandomSlug()
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestAccVaultSecretsResourceSecret(t *testing.T) {
testAppName := generateRandomSlug()
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
ProtoV6ProviderFactories: acctest.ProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/providersdkv2/data_source_packer_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestAcc_dataSourcePackerImage_Simple(t *testing.T) {
var iteration *models.HashicorpCloudPackerIteration
var build *models.HashicorpCloudPackerBuild

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t, map[string]bool{"aws": false, "azure": false})
upsertRegistry(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestAcc_dataSourcePackerIteration_Simple(t *testing.T) {

var iteration *models.HashicorpCloudPackerIteration

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t, map[string]bool{"aws": false, "azure": false})
upsertRegistry(t)
Expand Down
4 changes: 2 additions & 2 deletions internal/providersdkv2/location_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestDetermineOldestProject(t *testing.T) {
var projectID = "prov-project-id-invalid"

func TestAccMultiProject(t *testing.T) {
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
CheckDestroy: func(t *terraform.State) error {
Expand Down Expand Up @@ -139,7 +139,7 @@ func TestAccMultiProject(t *testing.T) {
}

func TestAccMultiProjectResource(t *testing.T) {
resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
CheckDestroy: func(t *terraform.State) error {
Expand Down
7 changes: 4 additions & 3 deletions internal/providersdkv2/resource_aws_network_peering_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build slow_tests

package providersdkv2

import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
Expand All @@ -16,7 +17,7 @@ import (

var (
// using unique names for AWS resource to make debugging easier
hvnPeeringUniqueAWSName = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504"))
hvnPeeringUniqueAWSName = uniqueName()
testAccAwsPeeringConfig = fmt.Sprintf(`
provider "aws" {
region = "us-west-2"
Expand Down Expand Up @@ -82,7 +83,7 @@ var (
func TestAccAwsPeering(t *testing.T) {
resourceName := "hcp_aws_network_peering.peering"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": true, "azure": false}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build slow_tests

package providersdkv2

import (
Expand Down Expand Up @@ -108,7 +110,7 @@ var (
func TestAccTGWAttachment(t *testing.T) {
resourceName := "hcp_aws_transit_gateway_attachment.example"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": true, "azure": false}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build slow_tests

package providersdkv2

import (
"context"
"fmt"
"os"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

var (
uniqueAzurePeeringTestID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504"))
uniqueAzurePeeringTestID = uniqueName()
subscriptionID = os.Getenv("ARM_SUBSCRIPTION_ID")
tenantID = os.Getenv("ARM_TENANT_ID")
)
Expand Down Expand Up @@ -188,7 +189,7 @@ func testAccAzurePeeringConnection(t *testing.T, adConfig string) {
resourceName := "hcp_azure_peering_connection.peering"
tfConfig := baseConfig("", adConfig)

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand Down Expand Up @@ -279,7 +280,7 @@ func testAccAzurePeeringConnectionNVA(t *testing.T, adConfig string) {
resourceName := "hcp_azure_peering_connection.peering"
tfConfig := baseConfig(peeringHubSpokeNVAConfig, adConfig)

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand Down Expand Up @@ -367,7 +368,7 @@ func testAccAzurePeeringConnectionGateway(t *testing.T, adConfig string) {
resourceName := "hcp_azure_peering_connection.peering"
tfConfig := baseConfig(peeringHubSpokeGatewayConfig, gatewayConfig(adConfig))

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand Down Expand Up @@ -455,7 +456,7 @@ func testAccAzurePeeringConnectionNVAandGateway(t *testing.T, adConfig string) {
resourceName := "hcp_azure_peering_connection.peering"
tfConfig := baseConfig(peeringHubSpokeNVAandGatewayConfig, gatewayConfig(adConfig))

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": true}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
ExternalProviders: map[string]resource.ExternalProvider{
Expand Down
7 changes: 4 additions & 3 deletions internal/providersdkv2/resource_boundary_cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build slow_tests

package providersdkv2

import (
"context"
"fmt"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/hashicorp/terraform-provider-hcp/internal/clients"
)

var boundaryUniqueID = fmt.Sprintf("hcp-provider-test-%s", time.Now().Format("200601021504"))
var boundaryUniqueID = uniqueName()

var boundaryClusterResourceTemplate = fmt.Sprintf(`
resource hcp_boundary_cluster "test" {
Expand Down Expand Up @@ -52,7 +53,7 @@ func TestAccBoundaryCluster(t *testing.T) {
boundaryClusterResourceName := "hcp_boundary_cluster.test"
boundaryClusterDataSourceName := "data.hcp_boundary_cluster.test"

resource.Test(t, resource.TestCase{
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t, map[string]bool{"aws": false, "azure": false}) },
ProtoV6ProviderFactories: testProtoV6ProviderFactories,
CheckDestroy: testAccCheckBoundaryClusterDestroy,
Expand Down
Loading
Loading