Skip to content

Commit

Permalink
fixed flaky test TestAccSecurityCenterManagement (GoogleCloudPlatform…
Browse files Browse the repository at this point in the history
  • Loading branch information
vijaykanthm authored and abd-goog committed Sep 26, 2024
1 parent 8f48520 commit 35239fd
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% autogen_exception -%>
package securitycentermanagement_test
<% unless version == 'ga' -%>

import (
"fmt"
Expand Down Expand Up @@ -27,7 +29,7 @@ func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule(t

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
ExternalProviders: map[string]resource.ExternalProvider{
"random": {},
"time": {},
Expand Down Expand Up @@ -68,6 +70,7 @@ func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule(t
func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule_sccFolderCustomModuleBasicExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_folder" "folder" {
provider = google-beta
parent = "organizations/%{org_id}"
display_name = "tf-test-folder-name%{random_suffix}"
deletion_protection = false
Expand All @@ -80,6 +83,7 @@ resource "time_sleep" "wait_1_minute" {
}

resource "google_scc_management_folder_security_health_analytics_custom_module" "example" {
provider = google-beta
folder = google_folder.folder.folder_id
location = "%{location}"
display_name = "tf_test_basic_custom_module%{random_suffix}"
Expand Down Expand Up @@ -107,12 +111,14 @@ resource "google_scc_management_folder_security_health_analytics_custom_module"
func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule_sccFolderCustomModuleFullExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_folder" "folder" {
provider = google-beta
parent = "organizations/%{org_id}"
display_name = "tf-test-folder-name%{random_suffix}"
deletion_protection = false
}

resource "google_scc_management_folder_security_health_analytics_custom_module" "example" {
provider = google-beta
folder = google_folder.folder.folder_id
location = "%{location}"
display_name = "tf_test_full_custom_module%{random_suffix}"
Expand Down Expand Up @@ -151,12 +157,14 @@ resource "google_scc_management_folder_security_health_analytics_custom_module"
func testAccSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModule_sccFolderCustomModuleUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_folder" "folder" {
provider = google-beta
parent = "organizations/%{org_id}"
display_name = "tf-test-folder-name%{random_suffix}"
deletion_protection = false
}

resource "google_scc_management_folder_security_health_analytics_custom_module" "example" {
provider = google-beta
folder = google_folder.folder.folder_id
location = "%{location}"
display_name = "tf_test_full_custom_module%{random_suffix}"
Expand Down Expand Up @@ -234,3 +242,5 @@ func testAccCheckSecurityCenterManagementFolderSecurityHealthAnalyticsCustomModu
return nil
}
}

<% end -%>
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<% autogen_exception -%>

package securitycentermanagement_test
<% unless version == 'ga' -%>

import (
"fmt"
Expand All @@ -23,10 +26,6 @@ func TestAccSecurityCenterManagement(t *testing.T) {
}

for name, tc := range testCases {
// shadow the tc variable into scope so that when
// the loop continues, if t.Run hasn't executed tc(t)
// yet, we don't have a race condition
// see https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables
tc := tc
t.Run(name, func(t *testing.T) {
tc(t)
Expand All @@ -35,7 +34,9 @@ func TestAccSecurityCenterManagement(t *testing.T) {
}

func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule(t *testing.T) {
// t.Parallel()

<%# Comment explaining the beta-only status due to concurrent modification issues (Error 409). %>
<%# This is being marked as beta-only. See the bug link: <https://b.corp.google.com/issues/358692342> %>

context := map[string]interface{}{
"org_id": envvar.GetTestOrgFromEnv(t),
Expand All @@ -45,7 +46,7 @@ func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t), // Ensure beta factory is used
CheckDestroy: testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -73,6 +74,8 @@ func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule
func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule__sccOrganizationCustomModuleExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_organization_event_threat_detection_custom_module" "example" {
provider = google-beta

organization = "%{org_id}"
location = "%{location}"
display_name = "tf_test_custom_module%{random_suffix}"
Expand All @@ -96,6 +99,8 @@ resource "google_scc_management_organization_event_threat_detection_custom_modul
func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule_sccOrganizationCustomModuleUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_organization_event_threat_detection_custom_module" "example" {
provider = google-beta

organization = "%{org_id}"
location = "%{location}"
display_name = "tf_test_custom_module%{random_suffix}_updated"
Expand Down Expand Up @@ -156,3 +161,4 @@ func testAccSecurityCenterManagementOrganizationEventThreatDetectionCustomModule
return nil
}
}
<% end -%>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% autogen_exception -%>
package securitycentermanagement_test
<% unless version == 'ga' -%>

import (
"fmt"
Expand All @@ -24,7 +26,7 @@ func testAccSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule(t

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -58,6 +60,7 @@ func testAccSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule(t
func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule_sccProjectCustomModuleBasicExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_project_security_health_analytics_custom_module" "example" {
provider = google-beta
display_name = "tf_test_basic_custom_module%{random_suffix}"
enablement_state = "ENABLED"
location = "%{location}"
Expand All @@ -81,6 +84,7 @@ resource "google_scc_management_project_security_health_analytics_custom_module"
func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule_sccProjectCustomModuleFullExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_project_security_health_analytics_custom_module" "example" {
provider = google-beta
display_name = "tf_test_full_custom_module%{random_suffix}"
enablement_state = "ENABLED"
location = "%{location}"
Expand Down Expand Up @@ -118,6 +122,7 @@ resource "google_scc_management_project_security_health_analytics_custom_module"
func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomModule_sccProjectCustomModuleUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_project_security_health_analytics_custom_module" "example" {
provider = google-beta
location = "%{location}"
display_name = "full_custom_module"
enablement_state = "DISABLED"
Expand Down Expand Up @@ -193,3 +198,5 @@ func testAccCheckSecurityCenterManagementProjectSecurityHealthAnalyticsCustomMod
return nil
}
}

<% end -%>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<% autogen_exception -%>
package securitycentermanagement_test
<% unless version == 'ga' -%>

import (
"fmt"
Expand Down Expand Up @@ -26,7 +28,7 @@ func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMod

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModuleDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -63,6 +65,7 @@ func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomMod
func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule_sccOrganizationCustomModuleBasicExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_organization_security_health_analytics_custom_module" "example" {
provider = google-beta
organization = "%{org_id}"
location = "%{location}"
display_name = "tf_test_basic_custom_module%{random_suffix}"
Expand All @@ -87,6 +90,7 @@ resource "google_scc_management_organization_security_health_analytics_custom_mo
func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule_sccOrganizationCustomModuleFullExample(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_organization_security_health_analytics_custom_module" "example" {
provider = google-beta
organization = "%{org_id}"
location = "%{location}"
display_name = "tf_test_full_custom_module%{random_suffix}"
Expand Down Expand Up @@ -125,6 +129,7 @@ resource "google_scc_management_organization_security_health_analytics_custom_mo
func testAccSecurityCenterManagementOrganizationSecurityHealthAnalyticsCustomModule_sccOrganizationCustomModuleUpdate(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_scc_management_organization_security_health_analytics_custom_module" "example" {
provider = google-beta
organization = "%{org_id}"
location = "%{location}"
display_name = "tf_test_full_custom_module%{random_suffix}"
Expand Down Expand Up @@ -202,3 +207,5 @@ func testAccCheckSecurityCenterManagementOrganizationSecurityHealthAnalyticsCust
return nil
}
}

<% end -%>

0 comments on commit 35239fd

Please sign in to comment.