From 78e6ebad526d3e450a72990fca83bb70f1d387df Mon Sep 17 00:00:00 2001 From: Leo Antoli <430982+lantoli@users.noreply.github.com> Date: Thu, 27 Jun 2024 20:41:49 +0200 Subject: [PATCH] test: Unifies Azure and GCP networking tests (#2371) * unify Azure and GCP tests * TEMPORARY no update * Revert "TEMPORARY no update" This reverts commit ab60d67dece8f53272b2fad4a68b60b890e7636c. * run in parallel --- .../resource_network_peering_test.go | 103 ++++-------------- 1 file changed, 23 insertions(+), 80 deletions(-) diff --git a/internal/service/networkpeering/resource_network_peering_test.go b/internal/service/networkpeering/resource_network_peering_test.go index c4e50a456d..03c00ff158 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") @@ -73,7 +36,7 @@ func TestAccNetworkRSNetworkPeering_updateBasicAzure(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, @@ -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 ( @@ -156,7 +85,7 @@ func TestAccNetworkRSNetworkPeering_updateBasicGCP(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, @@ -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, + }, }, }) }