Skip to content

Commit 09357b9

Browse files
authored
chore: Reuses projects in executions in some resources and rename mig tests (#2007)
* rename mig tests * TestMain in all packages [skip ci] * pass test context to GetClusterInfo * use ProjectIDExecution in GetClusterInfo * alert_configuration * fix ProjectIDStr * database_user * remove unneded "${...}" * run database_user tests in parallel * run alert_configuration tests in parallel * TestMain in main_test.go file * fix checkDestroy so it returns ok if it doesn't find anything like group/project or cluster
1 parent fa3b046 commit 09357b9

File tree

125 files changed

+1712
-1240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+1712
-1240
lines changed

.github/workflows/acceptance-tests-runner.yml

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ env:
104104
TF_LOG: ${{ vars.LOG_LEVEL }}
105105
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
106106
ACCTEST_REGEX_RUN: "^TestAcc"
107-
ACCTEST_REGEX_SKIP: "^TestAccMigration"
108107
MONGODB_ATLAS_BASE_URL: ${{ inputs.mongodb_atlas_base_url }}
109108
MONGODB_ATLAS_ORG_ID: ${{ inputs.mongodb_atlas_org_id }}
110109
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.mongodb_atlas_public_key }}

.github/workflows/migration-tests.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ env:
3232
TF_ACC: 1
3333
TF_LOG: ${{ vars.LOG_LEVEL }}
3434
ACCTEST_TIMEOUT: ${{ vars.ACCTEST_TIMEOUT }}
35-
ACCTEST_REGEX_RUN: "^TestAccMigration"
35+
ACCTEST_REGEX_RUN: "^TestMig"
3636
MONGODB_ATLAS_BASE_URL: ${{ vars.MONGODB_ATLAS_BASE_URL }}
3737
MONGODB_ATLAS_ORG_ID: ${{ vars.MONGODB_ATLAS_ORG_ID_CLOUD_DEV }}
3838
MONGODB_ATLAS_PUBLIC_KEY: ${{ secrets.MONGODB_ATLAS_PUBLIC_KEY_CLOUD_DEV }}

GNUmakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ test: fmtcheck
4444
.PHONY: testacc
4545
testacc: fmtcheck
4646
@$(eval VERSION=acc)
47-
TF_ACC=1 go test $(ACCTEST_PACKAGES) -run '$(ACCTEST_REGEX_RUN)' -skip '$(ACCTEST_REGEX_SKIP)' -v -parallel $(PARALLEL_GO_TEST) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags="$(LINKER_FLAGS)"
47+
TF_ACC=1 go test $(ACCTEST_PACKAGES) -run '$(ACCTEST_REGEX_RUN)' -v -parallel $(PARALLEL_GO_TEST) $(TESTARGS) -timeout $(ACCTEST_TIMEOUT) -ldflags="$(LINKER_FLAGS)"
4848

4949
.PHONY: testaccgov
5050
testaccgov: fmtcheck
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package accesslistapikey_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
8+
)
9+
10+
func TestMain(m *testing.M) {
11+
cleanup := acc.SetupSharedResources()
12+
exitCode := m.Run()
13+
cleanup()
14+
os.Exit(exitCode)
15+
}

internal/service/accesslistapikey/resource_access_list_api_key_migration_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
1212
)
1313

14-
func TestAccMigrationProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
14+
func TestMigProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
1515
var (
1616
resourceName = "mongodbatlas_access_list_api_key.test"
1717
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
@@ -37,7 +37,7 @@ func TestAccMigrationProjectAccesslistAPIKey_SettingIPAddress(t *testing.T) {
3737
})
3838
}
3939

40-
func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
40+
func TestMigProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
4141
mig.SkipIfVersionBelow(t, "1.14.0") // 1.14.0 is the version when this resource was migrated to the new Atlas SDK
4242

4343
var (
@@ -75,7 +75,7 @@ func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock(t *testing.T) {
7575
})
7676
}
7777

78-
func TestAccMigrationProjectAccesslistAPIKey_SettingCIDRBlock_WideCIDR_SDKMigration(t *testing.T) {
78+
func TestMigProjectAccesslistAPIKey_SettingCIDRBlock_WideCIDR_SDKMigration(t *testing.T) {
7979
mig.SkipIfVersionBelow(t, "1.14.0") // 1.14.0 is the version when this resource was migrated to the new Atlas SDK
8080

8181
var (
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package advancedcluster_test
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
8+
)
9+
10+
func TestMain(m *testing.M) {
11+
cleanup := acc.SetupSharedResources()
12+
exitCode := m.Run()
13+
cleanup()
14+
os.Exit(exitCode)
15+
}

internal/service/advancedcluster/resource_advanced_cluster_migration_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/mig"
1212
)
1313

14-
func TestAccMigrationAdvancedCluster_singleAWSProvider(t *testing.T) {
14+
func TestMigAdvancedCluster_singleAWSProvider(t *testing.T) {
1515
var (
1616
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
1717
projectName = acc.RandomProjectName()
@@ -40,7 +40,7 @@ func TestAccMigrationAdvancedCluster_singleAWSProvider(t *testing.T) {
4040
})
4141
}
4242

43-
func TestAccMigrationAdvancedCluster_multiCloud(t *testing.T) {
43+
func TestMigAdvancedCluster_multiCloud(t *testing.T) {
4444
var (
4545
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
4646
projectName = acc.RandomProjectName()
@@ -69,7 +69,7 @@ func TestAccMigrationAdvancedCluster_multiCloud(t *testing.T) {
6969
})
7070
}
7171

72-
func TestAccMigrationAdvancedCluster_partialAdvancedConf(t *testing.T) {
72+
func TestMigAdvancedCluster_partialAdvancedConf(t *testing.T) {
7373
var (
7474
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
7575
projectName = acc.RandomProjectName()

internal/service/advancedcluster/resource_advanced_cluster_state_upgrader_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
1010
)
1111

12-
func TestAccMigrationAdvancedCluster_empty_advancedConfig(t *testing.T) {
12+
func TestMigAdvancedCluster_empty_advancedConfig(t *testing.T) {
1313
acc.SkipInUnitTest(t) // needed because TF test infra is not used
1414
v0State := map[string]any{
1515
"project_id": "test-id",
@@ -62,7 +62,7 @@ func TestAccMigrationAdvancedCluster_empty_advancedConfig(t *testing.T) {
6262
}
6363
}
6464

65-
func TestAccMigrationAdvancedCluster_v0StateUpgrade_ReplicationSpecs(t *testing.T) {
65+
func TestMigAdvancedCluster_v0StateUpgrade_ReplicationSpecs(t *testing.T) {
6666
acc.SkipInUnitTest(t) // needed because TF test infra is not used
6767
v0State := map[string]any{
6868
"project_id": "test-id",

internal/service/alertconfiguration/data_source_alert_configuration_test.go

+54-86
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@ package alertconfiguration_test
22

33
import (
44
"fmt"
5-
"os"
65
"testing"
76

87
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
98
"github.com/mongodb/terraform-provider-mongodbatlas/internal/testutil/acc"
10-
"go.mongodb.org/atlas-sdk/v20231115007/admin"
119
)
1210

1311
func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
1412
var (
15-
alert = &admin.GroupAlertsConfig{}
16-
dataSourceName = "data.mongodbatlas_alert_configuration.test"
17-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
18-
projectName = acc.RandomProjectName()
13+
projectID = acc.ProjectIDExecution(t)
1914
)
2015

2116
resource.ParallelTest(t, resource.TestCase{
@@ -24,10 +19,10 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
2419
CheckDestroy: checkDestroy,
2520
Steps: []resource.TestStep{
2621
{
27-
Config: configBasicDS(orgID, projectName),
22+
Config: configBasicDS(projectID),
2823
Check: resource.ComposeTestCheckFunc(
29-
checkExists(dataSourceName, alert),
30-
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
24+
checkExists(dataSourceName),
25+
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
3126
resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"),
3227
resource.TestCheckResourceAttrSet(dataSourceName, "notification.0.notifier_id"),
3328
resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"),
@@ -41,10 +36,7 @@ func TestAccConfigDSAlertConfiguration_basic(t *testing.T) {
4136

4237
func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
4338
var (
44-
alert = &admin.GroupAlertsConfig{}
45-
dataSourceName = "data.mongodbatlas_alert_configuration.test"
46-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
47-
projectName = acc.RandomProjectName()
39+
projectID = acc.ProjectIDExecution(t)
4840
)
4941

5042
resource.ParallelTest(t, resource.TestCase{
@@ -53,11 +45,10 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
5345
CheckDestroy: checkDestroy,
5446
Steps: []resource.TestStep{
5547
{
56-
Config: configWithThreshold(orgID, projectName, true, 1),
48+
Config: configWithThreshold(projectID, true, 1),
5749
Check: resource.ComposeTestCheckFunc(
58-
checkExists(dataSourceName, alert),
59-
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
60-
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
50+
checkExists(dataSourceName),
51+
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
6152
resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"),
6253
resource.TestCheckResourceAttr(dataSourceName, "matcher.#", "1"),
6354
resource.TestCheckResourceAttr(dataSourceName, "metric_threshold_config.#", "0"),
@@ -70,11 +61,8 @@ func TestAccConfigDSAlertConfiguration_withThreshold(t *testing.T) {
7061

7162
func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
7263
var (
73-
alert = &admin.GroupAlertsConfig{}
74-
dataSourceName = "data.mongodbatlas_alert_configuration.test"
75-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
76-
projectName = acc.RandomProjectName()
77-
outputLabel = "resource_import"
64+
projectID = acc.ProjectIDExecution(t)
65+
outputLabel = "resource_import"
7866
)
7967

8068
resource.ParallelTest(t, resource.TestCase{
@@ -83,11 +71,10 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
8371
CheckDestroy: checkDestroy,
8472
Steps: []resource.TestStep{
8573
{
86-
Config: configWithOutputs(orgID, projectName, outputLabel),
74+
Config: configWithOutputs(projectID, outputLabel),
8775
Check: resource.ComposeTestCheckFunc(
88-
checkExists(dataSourceName, alert),
89-
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
90-
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
76+
checkExists(dataSourceName),
77+
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
9178
resource.TestCheckResourceAttr(dataSourceName, "notification.#", "1"),
9279
resource.TestCheckResourceAttr(dataSourceName, "output.0.label", outputLabel),
9380
resource.TestCheckResourceAttr(dataSourceName, "output.0.type", "resource_import"),
@@ -103,37 +90,30 @@ func TestAccConfigDSAlertConfiguration_withOutput(t *testing.T) {
10390

10491
func TestAccConfigDSAlertConfiguration_withPagerDuty(t *testing.T) {
10592
var (
106-
alert = &admin.GroupAlertsConfig{}
107-
dataSourceName = "data.mongodbatlas_alert_configuration.test"
108-
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
109-
projectName = acc.RandomProjectName()
110-
serviceKey = dummy32CharKey
93+
projectID = acc.ProjectIDExecution(t)
94+
serviceKey = dummy32CharKey
11195
)
11296

113-
resource.Test(t, resource.TestCase{
97+
resource.ParallelTest(t, resource.TestCase{
11498
PreCheck: func() { acc.PreCheckBasic(t) },
11599
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
116100
CheckDestroy: checkDestroy,
117101
Steps: []resource.TestStep{
118102
{
119-
Config: configWithPagerDutyDS(orgID, projectName, serviceKey, true),
103+
Config: configWithPagerDutyDS(projectID, serviceKey, true),
120104
Check: resource.ComposeTestCheckFunc(
121-
checkExists(dataSourceName, alert),
122-
resource.TestCheckResourceAttrSet(dataSourceName, "project_id"),
105+
checkExists(dataSourceName),
106+
resource.TestCheckResourceAttr(dataSourceName, "project_id", projectID),
123107
),
124108
},
125109
},
126110
})
127111
}
128112

129-
func configBasicDS(orgID, projectName string) string {
113+
func configBasicDS(projectID string) string {
130114
return fmt.Sprintf(`
131-
resource "mongodbatlas_project" "test" {
132-
name = %[2]q
133-
org_id = %[1]q
134-
}
135115
resource "mongodbatlas_alert_configuration" "test" {
136-
project_id = mongodbatlas_project.test.id
116+
project_id = %[1]q
137117
event_type = "OUTSIDE_METRIC_THRESHOLD"
138118
enabled = true
139119
@@ -161,22 +141,18 @@ func configBasicDS(orgID, projectName string) string {
161141
}
162142
163143
data "mongodbatlas_alert_configuration" "test" {
164-
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
165-
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
144+
project_id = mongodbatlas_alert_configuration.test.project_id
145+
alert_configuration_id = mongodbatlas_alert_configuration.test.id
166146
}
167-
`, orgID, projectName)
147+
`, projectID)
168148
}
169149

170-
func configWithThreshold(orgID, projectName string, enabled bool, threshold float64) string {
150+
func configWithThreshold(projectID string, enabled bool, threshold float64) string {
171151
return fmt.Sprintf(`
172-
resource "mongodbatlas_project" "test" {
173-
name = %[2]q
174-
org_id = %[1]q
175-
}
176152
resource "mongodbatlas_alert_configuration" "test" {
177-
project_id = mongodbatlas_project.test.id
153+
project_id = %[1]q
154+
enabled = %[2]t
178155
event_type = "REPLICATION_OPLOG_WINDOW_RUNNING_OUT"
179-
enabled = "%[3]t"
180156
181157
notification {
182158
type_name = "GROUP"
@@ -196,25 +172,21 @@ func configWithThreshold(orgID, projectName string, enabled bool, threshold floa
196172
threshold_config {
197173
operator = "LESS_THAN"
198174
units = "HOURS"
199-
threshold = %[4]f
175+
threshold = %[3]f
200176
}
201177
}
202178
203179
data "mongodbatlas_alert_configuration" "test" {
204-
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
205-
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
180+
project_id = mongodbatlas_alert_configuration.test.project_id
181+
alert_configuration_id = mongodbatlas_alert_configuration.test.id
206182
}
207-
`, orgID, projectName, enabled, threshold)
183+
`, projectID, enabled, threshold)
208184
}
209185

210-
func configWithOutputs(orgID, projectName, outputLabel string) string {
186+
func configWithOutputs(projectID, outputLabel string) string {
211187
return fmt.Sprintf(`
212-
resource "mongodbatlas_project" "test" {
213-
name = %[2]q
214-
org_id = %[1]q
215-
}
216188
resource "mongodbatlas_alert_configuration" "test" {
217-
project_id = mongodbatlas_project.test.id
189+
project_id = %[1]q
218190
219191
event_type = "NO_PRIMARY"
220192
enabled = true
@@ -230,42 +202,38 @@ func configWithOutputs(orgID, projectName, outputLabel string) string {
230202
}
231203
232204
data "mongodbatlas_alert_configuration" "test" {
233-
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
234-
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
205+
project_id = mongodbatlas_alert_configuration.test.project_id
206+
alert_configuration_id = mongodbatlas_alert_configuration.test.id
235207
236208
output {
237209
type = "resource_import"
238-
label = %[3]q
210+
label = %[2]q
239211
}
240212
output {
241213
type = "resource_hcl"
242-
label = %[3]q
214+
label = %[2]q
243215
}
244216
}
245-
`, orgID, projectName, outputLabel)
217+
`, projectID, outputLabel)
246218
}
247219

248-
func configWithPagerDutyDS(orgID, projectName, serviceKey string, enabled bool) string {
220+
func configWithPagerDutyDS(projectID, serviceKey string, enabled bool) string {
249221
return fmt.Sprintf(`
250-
resource "mongodbatlas_project" "test" {
251-
name = %[2]q
252-
org_id = %[1]q
253-
}
254-
resource "mongodbatlas_alert_configuration" "test" {
255-
project_id = mongodbatlas_project.test.id
256-
event_type = "NO_PRIMARY"
257-
enabled = "%[4]t"
222+
resource "mongodbatlas_alert_configuration" "test" {
223+
project_id = %[1]q
224+
enabled = "%[3]t"
225+
event_type = "NO_PRIMARY"
258226
259-
notification {
260-
type_name = "PAGER_DUTY"
261-
service_key = %[3]q
262-
delay_min = 0
263-
}
264-
}
227+
notification {
228+
type_name = "PAGER_DUTY"
229+
service_key = %[2]q
230+
delay_min = 0
231+
}
232+
}
265233
266-
data "mongodbatlas_alert_configuration" "test" {
267-
project_id = "${mongodbatlas_alert_configuration.test.project_id}"
268-
alert_configuration_id = "${mongodbatlas_alert_configuration.test.id}"
269-
}
270-
`, orgID, projectName, serviceKey, enabled)
234+
data "mongodbatlas_alert_configuration" "test" {
235+
project_id = mongodbatlas_alert_configuration.test.project_id
236+
alert_configuration_id = mongodbatlas_alert_configuration.test.id
237+
}
238+
`, projectID, serviceKey, enabled)
271239
}

0 commit comments

Comments
 (0)