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

Vcr ignore tests #3486

Merged
merged 9 commits into from
May 14, 2020
Merged
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
12 changes: 12 additions & 0 deletions products/compute/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1961,14 +1961,20 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "ssl_certificate_basic"
primary_resource_id: "default"
# Uses resource.UniqueId
skip_vcr: true
slevenick marked this conversation as resolved.
Show resolved Hide resolved
ignore_read_extra:
- "name_prefix"
- !ruby/object:Provider::Terraform::Examples
name: "ssl_certificate_random_provider"
primary_resource_id: "default"
# Uses resource.UniqueId
skip_vcr: true
- !ruby/object:Provider::Terraform::Examples
name: "ssl_certificate_target_https_proxies"
primary_resource_id: "default"
# Uses resource.UniqueId
skip_vcr: true
vars:
target_https_proxy_name: "test-proxy"
url_map_name: "url-map"
Expand Down Expand Up @@ -2006,14 +2012,20 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "region_ssl_certificate_basic"
primary_resource_id: "default"
# Uses resource.UniqueId
skip_vcr: true
ignore_read_extra:
- "name_prefix"
- !ruby/object:Provider::Terraform::Examples
name: "region_ssl_certificate_random_provider"
primary_resource_id: "default"
# Uses resource.UniqueId
skip_vcr: true
- !ruby/object:Provider::Terraform::Examples
name: "region_ssl_certificate_target_https_proxies"
primary_resource_id: "default"
# Uses resource.UniqueId
skip_vcr: true
vars:
region_target_https_proxy_name: "test-proxy"
region_url_map_name: "url-map"
Expand Down
2 changes: 2 additions & 0 deletions products/dns/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "dns_managed_zone_basic"
primary_resource_id: "example-zone"
# Randomness from random provider
skip_vcr: true
- !ruby/object:Provider::Terraform::Examples
name: "dns_managed_zone_private"
primary_resource_id: "private-zone"
Expand Down
4 changes: 4 additions & 0 deletions products/spanner/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "spanner_database_basic"
primary_resource_id: "database"
# Randomness due to spanner instance
skip_vcr: true
vars:
database_name: "my-database"
properties:
Expand Down Expand Up @@ -55,6 +57,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides
- !ruby/object:Provider::Terraform::Examples
name: "spanner_instance_basic"
primary_resource_id: "example"
# Randomness
skip_vcr: true
properties:
name: !ruby/object:Overrides::Terraform::PropertyOverride
description: |
Expand Down
7 changes: 7 additions & 0 deletions provider/terraform/examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ class Examples < Api::Object
# Defaults to `templates/terraform/examples/{{name}}.tf.erb`
attr_reader :config_path

# If the example should be skipped during VCR testing.
# This is the case when something about the resource or config causes VCR to fail for example
# a resource with a unique identifier generated within the resource via resource.UniqueId()
# Or a config with two fine grained resources that have a race condition during create
attr_reader :skip_vcr

def config_documentation(pwd)
docs_defaults = {
PROJECT_NAME: 'my-project-name',
Expand Down Expand Up @@ -262,6 +268,7 @@ def validate
check :primary_resource_name, type: String
check :skip_test, type: TrueClass
check :config_path, type: String, default: "templates/terraform/examples/#{name}.tf.erb"
check :skip_vcr, type: TrueClass
end
end
end
Expand Down
3 changes: 3 additions & 0 deletions templates/terraform/examples/base_configs/test_file.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ object.examples
-%>

func TestAcc<%= test_slug -%>(t *testing.T) {
<% if example.skip_vcr -%>
skipIfVcr(t)
<% end -%>
t.Parallel()

context := map[string]interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
Expand All @@ -13,7 +12,7 @@ func TestAccDataSourceComputeNetworkEndpointGroup(t *testing.T) {
t.Parallel()

context := map[string]interface{}{
"random_suffix": acctest.RandString(10),
"random_suffix": randString(t, 10),
}

vcrTest(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

Expand All @@ -16,7 +15,7 @@ func TestAccComputeInstanceIamPolicy(t *testing.T) {
project := getTestProjectFromEnv()
role := "roles/compute.osLogin"
zone := getTestZoneFromEnv()
instanceName := fmt.Sprintf("tf-test-instance-%s", acctest.RandString(10))
instanceName := fmt.Sprintf("tf-test-instance-%s", randString(t, 10))

vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestAccDataSourceRegionInstanceGroup(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()
name := "acctest-" + randString(t, 6)
vcrTest(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
// can exist, they need to be ran serially. See AccessPolicy for the test runner.

func testAccAccessContextManagerServicePerimeterResource_basicTest(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
org := getTestOrgFromEnv(t)
projects := BootstrapServicePerimeterProjects(t, 2)
policyTitle := "my policy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func TestAccBigQueryDatasetAccess_view(t *testing.T) {
}

func TestAccBigQueryDatasetAccess_multiple(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()

datasetID := fmt.Sprintf("tf_test_%s", randString(t, 10))
Expand Down
4 changes: 4 additions & 0 deletions third_party/terraform/tests/resource_compute_disk_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func TestAccComputeDisk_imageDiffSuppressPublicVendorsFamilyNames(t *testing.T)
}

func TestAccComputeDisk_timeout(t *testing.T) {
// Vcr speeds up test, so it doesn't time out
skipIfVcr(t)
t.Parallel()

diskName := fmt.Sprintf("tf-test-disk-%d", randInt(t))
Expand Down Expand Up @@ -376,6 +378,8 @@ func TestAccComputeDisk_deleteDetach(t *testing.T) {
}

func TestAccComputeDisk_deleteDetachIGM(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

diskName := fmt.Sprintf("tf-test-%s", randString(t, 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func TestAccInstanceGroupManager_update(t *testing.T) {
}

func TestAccInstanceGroupManager_updateLifecycle(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

tag1 := "tag1"
Expand Down Expand Up @@ -129,6 +131,8 @@ func TestAccInstanceGroupManager_updateLifecycle(t *testing.T) {
}

func TestAccInstanceGroupManager_updatePolicy(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

igm := fmt.Sprintf("igm-test-%s", randString(t, 10))
Expand Down Expand Up @@ -176,6 +180,8 @@ func TestAccInstanceGroupManager_updatePolicy(t *testing.T) {
}

func TestAccInstanceGroupManager_separateRegions(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

igm1 := fmt.Sprintf("igm-test-%s", randString(t, 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ func TestAccComputeInstanceTemplate_subnet_custom(t *testing.T) {
}

func TestAccComputeInstanceTemplate_subnet_xpn(t *testing.T) {
// Randomness
skipIfVcr(t)
t.Parallel()

var instanceTemplate compute.InstanceTemplate
Expand Down Expand Up @@ -819,6 +821,8 @@ func TestAccComputeInstanceTemplate_invalidDiskType(t *testing.T) {
}

func TestAccComputeInstanceTemplate_imageResourceTest(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()
diskName := "tf-test-disk-" + randString(t, 10)
computeImage := "tf-test-image-" + randString(t, 10)
Expand Down
2 changes: 2 additions & 0 deletions third_party/terraform/tests/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,8 @@ func TestAccComputeInstance_subnet_custom(t *testing.T) {
}

func TestAccComputeInstance_subnet_xpn(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()

var instance compute.Instance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestAccComputeNetworkEndpoint_networkEndpointsBasic(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()

context := map[string]interface{}{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ func TestAccRegionInstanceGroupManager_update(t *testing.T) {
}

func TestAccRegionInstanceGroupManager_updateLifecycle(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

tag1 := "tag1"
Expand Down Expand Up @@ -131,6 +133,8 @@ func TestAccRegionInstanceGroupManager_updateLifecycle(t *testing.T) {
}

func TestAccRegionInstanceGroupManager_rollingUpdatePolicy(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

igm := fmt.Sprintf("igm-test-%s", randString(t, 10))
Expand Down Expand Up @@ -166,6 +170,8 @@ func TestAccRegionInstanceGroupManager_rollingUpdatePolicy(t *testing.T) {
}

func TestAccRegionInstanceGroupManager_separateRegions(t *testing.T) {
// Randomness in instance template
skipIfVcr(t)
t.Parallel()

igm1 := fmt.Sprintf("igm-test-%s", randString(t, 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
)

func TestAccComputeSslCertificate_no_name(t *testing.T) {
// Randomness
skipIfVcr(t)
t.Parallel()

vcrTest(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ func TestAccContainerCluster_withNodePoolAutoscaling(t *testing.T) {
}

func TestAccContainerCluster_withNodePoolNamePrefix(t *testing.T) {
// Randomness
skipIfVcr(t)
t.Parallel()

clusterName := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ func TestAccContainerNodePool_maxPodsPerNode(t *testing.T) {
}

func TestAccContainerNodePool_namePrefix(t *testing.T) {
// Randomness
skipIfVcr(t)
t.Parallel()

cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
Expand All @@ -104,6 +106,8 @@ func TestAccContainerNodePool_namePrefix(t *testing.T) {
}

func TestAccContainerNodePool_noName(t *testing.T) {
// Randomness
skipIfVcr(t)
t.Parallel()

cluster := fmt.Sprintf("tf-test-cluster-%s", randString(t, 10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ func TestAccDataprocCluster_withEndpointConfig(t *testing.T) {
t.Parallel()

var cluster dataproc.Cluster
rnd := acctest.RandString(10)
rnd := randString(t, 10)
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
Expand All @@ -15,7 +14,7 @@ func TestAccDialogflowIntent_basic(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"billing_account": getTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(10),
"random_suffix": randString(t, 10),
}

resource.Test(t, resource.TestCase{
Expand All @@ -40,7 +39,7 @@ func TestAccDialogflowIntent_update(t *testing.T) {
context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"billing_account": getTestBillingAccountFromEnv(t),
"random_suffix": acctest.RandString(10),
"random_suffix": randString(t, 10),
}

resource.Test(t, resource.TestCase{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAccFirebaseWebApp_firebaseWebAppFull(t *testing.T) {

context := map[string]interface{}{
"org_id": getTestOrgFromEnv(t),
"random_suffix": acctest.RandString(10),
"random_suffix": randString(t, 10),
"display_name": "Display Name N",
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ func TestAccFolderIamBinding_multiple(t *testing.T) {

// Test that multiple IAM bindings can be applied to a folder all at once
func TestAccFolderIamBinding_multipleAtOnce(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()

org := getTestOrgFromEnv(t)
Expand Down Expand Up @@ -176,6 +178,8 @@ func TestAccFolderIamBinding_update(t *testing.T) {

// Test that an IAM binding can be removed from a folder
func TestAccFolderIamBinding_remove(t *testing.T) {
// Multiple fine-grained resources
skipIfVcr(t)
t.Parallel()

org := getTestOrgFromEnv(t)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestAccFolderIamMember_basic(t *testing.T) {

// Test that multiple IAM bindings can be applied to a folder
func TestAccFolderIamMember_multiple(t *testing.T) {
skipIfVcr(t)
t.Parallel()

org := getTestOrgFromEnv(t)
Expand Down Expand Up @@ -82,6 +83,7 @@ func TestAccFolderIamMember_multiple(t *testing.T) {

// Test that an IAM binding can be removed from a folder
func TestAccFolderIamMember_remove(t *testing.T) {
skipIfVcr(t)
t.Parallel()

org := getTestOrgFromEnv(t)
Expand Down
Loading