Skip to content

Commit 9f95800

Browse files
authored
chore: Reuses project in tests for network_container resource (#2039)
* configBasic * unify ds tests * run extra GCP test in serial * use random CIDR per test * change CIDR ranges * fix CIDR * remove checkExists for ds * TestAccNetworkContainerRS_importBasic * TestAccNetworkContainerRS_withRegionsGCP * fix GCP CIDR * use execution project in mig tests * fix tests
1 parent d1c205a commit 9f95800

File tree

4 files changed

+107
-381
lines changed

4 files changed

+107
-381
lines changed

internal/service/networkcontainer/data_source_network_container_test.go

Lines changed: 0 additions & 140 deletions
This file was deleted.

internal/service/networkcontainer/data_source_network_containers_test.go

Lines changed: 0 additions & 142 deletions
This file was deleted.
Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package networkcontainer_test
22

33
import (
4+
"fmt"
45
"testing"
56

7+
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
68
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
79
"github.com/mongodb/terraform-provider-mongodbatlas/internal/common/constant"
810
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
@@ -11,8 +13,10 @@ import (
1113

1214
func TestMigNetworkContainerRS_basicAWS(t *testing.T) {
1315
var (
14-
projectName = acc.RandomProjectName()
15-
configAWS = configAWS(projectName, orgID, cidrBlock, constant.AWS, "US_EAST_1")
16+
projectID = acc.ProjectIDExecution(t)
17+
randInt = acctest.RandIntRange(0, 255)
18+
cidrBlock = fmt.Sprintf("10.8.%d.0/24", randInt)
19+
config = configBasic(projectID, cidrBlock, constant.AWS, "US_EAST_1")
1620
)
1721

1822
resource.ParallelTest(t, resource.TestCase{
@@ -21,23 +25,25 @@ func TestMigNetworkContainerRS_basicAWS(t *testing.T) {
2125
Steps: []resource.TestStep{
2226
{
2327
ExternalProviders: mig.ExternalProviders(),
24-
Config: configAWS,
28+
Config: config,
2529
Check: resource.ComposeTestCheckFunc(
2630
checkExists(resourceName),
2731
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
2832
resource.TestCheckResourceAttr(resourceName, "provider_name", constant.AWS),
2933
resource.TestCheckResourceAttrSet(resourceName, "provisioned"),
3034
),
3135
},
32-
mig.TestStepCheckEmptyPlan(configAWS),
36+
mig.TestStepCheckEmptyPlan(config),
3337
},
3438
})
3539
}
3640

3741
func TestMigNetworkContainerRS_basicAzure(t *testing.T) {
3842
var (
39-
projectName = acc.RandomProjectName()
40-
configAzure = configAzure(projectName, orgID, cidrBlock, constant.AZURE)
43+
projectID = acc.ProjectIDExecution(t)
44+
randInt = acctest.RandIntRange(0, 255)
45+
cidrBlock = fmt.Sprintf("10.8.%d.0/24", randInt)
46+
config = configBasic(projectID, cidrBlock, constant.AZURE, "US_EAST_2")
4147
)
4248

4349
resource.ParallelTest(t, resource.TestCase{
@@ -46,23 +52,25 @@ func TestMigNetworkContainerRS_basicAzure(t *testing.T) {
4652
Steps: []resource.TestStep{
4753
{
4854
ExternalProviders: mig.ExternalProviders(),
49-
Config: configAzure,
55+
Config: config,
5056
Check: resource.ComposeTestCheckFunc(
5157
checkExists(resourceName),
5258
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
5359
resource.TestCheckResourceAttr(resourceName, "provider_name", constant.AZURE),
5460
resource.TestCheckResourceAttrSet(resourceName, "provisioned"),
5561
),
5662
},
57-
mig.TestStepCheckEmptyPlan(configAzure),
63+
mig.TestStepCheckEmptyPlan(config),
5864
},
5965
})
6066
}
6167

6268
func TestMigNetworkContainerRS_basicGCP(t *testing.T) {
6369
var (
64-
projectName = acc.RandomProjectName()
65-
configGCP = configGCP(projectName, orgID, gcpCidrBlock, constant.GCP)
70+
projectID = acc.ProjectIDExecution(t)
71+
randInt = acctest.RandIntRange(0, 255)
72+
gcpCidrBlock = fmt.Sprintf("10.%d.0.0/18", randInt)
73+
config = configBasic(projectID, gcpCidrBlock, constant.GCP, "")
6674
)
6775

6876
resource.ParallelTest(t, resource.TestCase{
@@ -71,15 +79,15 @@ func TestMigNetworkContainerRS_basicGCP(t *testing.T) {
7179
Steps: []resource.TestStep{
7280
{
7381
ExternalProviders: mig.ExternalProviders(),
74-
Config: configGCP,
82+
Config: config,
7583
Check: resource.ComposeTestCheckFunc(
7684
checkExists(resourceName),
7785
resource.TestCheckResourceAttrSet(resourceName, "project_id"),
7886
resource.TestCheckResourceAttr(resourceName, "provider_name", constant.GCP),
7987
resource.TestCheckResourceAttrSet(resourceName, "provisioned"),
8088
),
8189
},
82-
mig.TestStepCheckEmptyPlan(configGCP),
90+
mig.TestStepCheckEmptyPlan(config),
8391
},
8492
})
8593
}

0 commit comments

Comments
 (0)