From 96de6b0a58d0e191ae664a00b9eb273075e3eb5f Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Thu, 27 Jun 2024 12:22:44 +0200 Subject: [PATCH 1/4] unify Azure and GCP tests --- .../resource_network_peering_test.go | 99 ++++--------------- 1 file changed, 21 insertions(+), 78 deletions(-) diff --git a/internal/service/networkpeering/resource_network_peering_test.go b/internal/service/networkpeering/resource_network_peering_test.go index c4e50a456d..8f4cc93c25 100644 --- a/internal/service/networkpeering/resource_network_peering_test.go +++ b/internal/service/networkpeering/resource_network_peering_test.go @@ -25,44 +25,7 @@ func TestAccNetworkNetworkPeering_basicAWS(t *testing.T) { resource.ParallelTest(t, *basicAWSTestCase(t)) } -func TestAccNetworkRSNetworkPeering_basicAzure(t *testing.T) { - var ( - projectID = acc.ProjectIDExecution(t) - directoryID = os.Getenv("AZURE_DIRECTORY_ID") - subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID") - resourceGroupName = os.Getenv("AZURE_RESOURCE_GROUP_NAME") - vNetName = os.Getenv("AZURE_VNET_NAME") - providerName = "AZURE" - ) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.PreCheckBasic(t); acc.PreCheckPeeringEnvAzure(t) }, - ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - CheckDestroy: acc.CheckDestroyNetworkPeering, - Steps: []resource.TestStep{ - { - Config: configAzure(projectID, providerName, directoryID, subscriptionID, resourceGroupName, vNetName), - Check: resource.ComposeTestCheckFunc( - checkExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttrSet(resourceName, "container_id"), - resource.TestCheckResourceAttr(resourceName, "provider_name", providerName), - resource.TestCheckResourceAttr(resourceName, "vnet_name", vNetName), - resource.TestCheckResourceAttr(resourceName, "azure_directory_id", directoryID), - ), - }, - { - ResourceName: resourceName, - ImportStateIdFunc: importStateIDFunc(resourceName), - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"container_id"}, - }, - }, - }) -} - -func TestAccNetworkRSNetworkPeering_updateBasicAzure(t *testing.T) { +func TestAccNetworkRSNetworkPeering_Azure(t *testing.T) { var ( projectID = acc.ProjectIDExecution(t) directoryID = os.Getenv("AZURE_DIRECTORY_ID") @@ -100,52 +63,18 @@ func TestAccNetworkRSNetworkPeering_updateBasicAzure(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "azure_directory_id", directoryID), ), }, - }, - }) -} - -func TestAccNetworkRSNetworkPeering_basicGCP(t *testing.T) { - acc.SkipTestForCI(t) // needs GCP configuration - - var ( - projectID = os.Getenv("MONGODB_ATLAS_PROJECT_ID") - providerName = "GCP" - gcpProjectID = os.Getenv("GCP_PROJECT_ID") - networkName = acc.RandomName() - ) - - resource.Test(t, resource.TestCase{ - PreCheck: func() { acc.PreCheck(t); acc.PreCheckPeeringEnvGCP(t) }, - ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, - CheckDestroy: acc.CheckDestroyNetworkPeering, - Steps: []resource.TestStep{ - { - Config: configGCP(projectID, providerName, gcpProjectID, networkName), - Check: resource.ComposeTestCheckFunc( - checkExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttrSet(resourceName, "container_id"), - - resource.TestCheckResourceAttr(resourceName, "provider_name", providerName), - resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID), - resource.TestCheckResourceAttr(resourceName, "network_name", networkName), - - // computed values that are obtain from associated container, checks for existing prefix convention to ensure they are gcp related values - resource.TestCheckResourceAttrWith(resourceName, "atlas_gcp_project_id", acc.MatchesExpression("p-.*")), - resource.TestCheckResourceAttrWith(resourceName, "atlas_vpc_name", acc.MatchesExpression("nt-.*")), - ), - }, { - ResourceName: resourceName, - ImportStateIdFunc: importStateIDFunc(resourceName), - ImportState: true, - ImportStateVerify: true, + ResourceName: resourceName, + ImportStateIdFunc: importStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"container_id"}, }, }, }) } -func TestAccNetworkRSNetworkPeering_updateBasicGCP(t *testing.T) { +func TestAccNetworkRSNetworkPeering_GCP(t *testing.T) { acc.SkipTestForCI(t) // needs GCP configuration var ( @@ -172,6 +101,10 @@ func TestAccNetworkRSNetworkPeering_updateBasicGCP(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "provider_name", providerName), resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID), resource.TestCheckResourceAttr(resourceName, "network_name", networkName), + + // computed values that are obtain from associated container, checks for existing prefix convention to ensure they are gcp related values + resource.TestCheckResourceAttrWith(resourceName, "atlas_gcp_project_id", acc.MatchesExpression("p-.*")), + resource.TestCheckResourceAttrWith(resourceName, "atlas_vpc_name", acc.MatchesExpression("nt-.*")), ), }, { @@ -185,8 +118,18 @@ func TestAccNetworkRSNetworkPeering_updateBasicGCP(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "provider_name", providerName), resource.TestCheckResourceAttr(resourceName, "gcp_project_id", gcpProjectID), resource.TestCheckResourceAttr(resourceName, "network_name", updatedNetworkName), + + // computed values that are obtain from associated container, checks for existing prefix convention to ensure they are gcp related values + resource.TestCheckResourceAttrWith(resourceName, "atlas_gcp_project_id", acc.MatchesExpression("p-.*")), + resource.TestCheckResourceAttrWith(resourceName, "atlas_vpc_name", acc.MatchesExpression("nt-.*")), ), }, + { + ResourceName: resourceName, + ImportStateIdFunc: importStateIDFunc(resourceName), + ImportState: true, + ImportStateVerify: true, + }, }, }) } From ab60d67dece8f53272b2fad4a68b60b890e7636c Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:20:28 +0200 Subject: [PATCH 2/4] TEMPORARY no update --- .../networkpeering/resource_network_peering_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/internal/service/networkpeering/resource_network_peering_test.go b/internal/service/networkpeering/resource_network_peering_test.go index 8f4cc93c25..5677489d52 100644 --- a/internal/service/networkpeering/resource_network_peering_test.go +++ b/internal/service/networkpeering/resource_network_peering_test.go @@ -32,7 +32,6 @@ func TestAccNetworkRSNetworkPeering_Azure(t *testing.T) { subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID") resourceGroupName = os.Getenv("AZURE_RESOURCE_GROUP_NAME") vNetName = os.Getenv("AZURE_VNET_NAME") - updatedvNetName = os.Getenv("AZURE_VNET_NAME_UPDATED") providerName = "AZURE" ) @@ -52,17 +51,6 @@ func TestAccNetworkRSNetworkPeering_Azure(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "azure_directory_id", directoryID), ), }, - { - Config: configAzure(projectID, providerName, directoryID, subscriptionID, resourceGroupName, updatedvNetName), - Check: resource.ComposeTestCheckFunc( - checkExists(resourceName), - resource.TestCheckResourceAttrSet(resourceName, "project_id"), - resource.TestCheckResourceAttrSet(resourceName, "container_id"), - resource.TestCheckResourceAttr(resourceName, "provider_name", providerName), - resource.TestCheckResourceAttr(resourceName, "vnet_name", updatedvNetName), - resource.TestCheckResourceAttr(resourceName, "azure_directory_id", directoryID), - ), - }, { ResourceName: resourceName, ImportStateIdFunc: importStateIDFunc(resourceName), From 14a0db554ef254c928482d03a711299c4d936d92 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Thu, 27 Jun 2024 16:55:48 +0200 Subject: [PATCH 3/4] Revert "TEMPORARY no update" This reverts commit ab60d67dece8f53272b2fad4a68b60b890e7636c. --- .../networkpeering/resource_network_peering_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/internal/service/networkpeering/resource_network_peering_test.go b/internal/service/networkpeering/resource_network_peering_test.go index 5677489d52..8f4cc93c25 100644 --- a/internal/service/networkpeering/resource_network_peering_test.go +++ b/internal/service/networkpeering/resource_network_peering_test.go @@ -32,6 +32,7 @@ func TestAccNetworkRSNetworkPeering_Azure(t *testing.T) { subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID") resourceGroupName = os.Getenv("AZURE_RESOURCE_GROUP_NAME") vNetName = os.Getenv("AZURE_VNET_NAME") + updatedvNetName = os.Getenv("AZURE_VNET_NAME_UPDATED") providerName = "AZURE" ) @@ -51,6 +52,17 @@ func TestAccNetworkRSNetworkPeering_Azure(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "azure_directory_id", directoryID), ), }, + { + Config: configAzure(projectID, providerName, directoryID, subscriptionID, resourceGroupName, updatedvNetName), + Check: resource.ComposeTestCheckFunc( + checkExists(resourceName), + resource.TestCheckResourceAttrSet(resourceName, "project_id"), + resource.TestCheckResourceAttrSet(resourceName, "container_id"), + resource.TestCheckResourceAttr(resourceName, "provider_name", providerName), + resource.TestCheckResourceAttr(resourceName, "vnet_name", updatedvNetName), + resource.TestCheckResourceAttr(resourceName, "azure_directory_id", directoryID), + ), + }, { ResourceName: resourceName, ImportStateIdFunc: importStateIDFunc(resourceName), From 3cfdc7a13314bfaec0dabfdf7627e8d4e956a3c7 Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Thu, 27 Jun 2024 20:23:52 +0200 Subject: [PATCH 4/4] run in parallel --- .../service/networkpeering/resource_network_peering_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/service/networkpeering/resource_network_peering_test.go b/internal/service/networkpeering/resource_network_peering_test.go index 8f4cc93c25..03c00ff158 100644 --- a/internal/service/networkpeering/resource_network_peering_test.go +++ b/internal/service/networkpeering/resource_network_peering_test.go @@ -36,7 +36,7 @@ func TestAccNetworkRSNetworkPeering_Azure(t *testing.T) { providerName = "AZURE" ) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheckBasic(t); acc.PreCheckPeeringEnvAzure(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: acc.CheckDestroyNetworkPeering, @@ -85,7 +85,7 @@ func TestAccNetworkRSNetworkPeering_GCP(t *testing.T) { updatedNetworkName = acc.RandomName() ) - resource.Test(t, resource.TestCase{ + resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acc.PreCheck(t); acc.PreCheckPeeringEnvGCP(t) }, ProtoV6ProviderFactories: acc.TestAccProviderV6Factories, CheckDestroy: acc.CheckDestroyNetworkPeering,