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

test: Unifies Azure and GCP networking tests #2371

Merged
merged 4 commits into from
Jun 27, 2024
Merged
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
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