Skip to content

Commit

Permalink
test: Unifies Azure and GCP networking tests (#2371)
Browse files Browse the repository at this point in the history
* unify Azure and GCP tests

* TEMPORARY no update

* Revert "TEMPORARY no update"

This reverts commit ab60d67.

* run in parallel
  • Loading branch information
lantoli authored Jun 27, 2024
1 parent bfc18aa commit 78e6eba
Showing 1 changed file with 23 additions and 80 deletions.
103 changes: 23 additions & 80 deletions internal/service/networkpeering/resource_network_peering_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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,
Expand All @@ -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 (
Expand All @@ -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,
Expand All @@ -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-.*")),
),
},
{
Expand All @@ -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,
},
},
})
}
Expand Down

0 comments on commit 78e6eba

Please sign in to comment.