Skip to content

Commit fa00932

Browse files
author
Cristina Sánchez Sánchez
committed
Fixed migration test
1 parent 8690f0e commit fa00932

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

internal/service/clouduserprojectassignment/resource_migration_test.go

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ func TestMigCloudUserProjectAssignmentRS_migrationJourney(t *testing.T) {
2828
orgID = os.Getenv("MONGODB_ATLAS_ORG_ID")
2929
username = acc.RandomEmail()
3030
projectName = fmt.Sprintf("mig_user_project_%s", acc.RandomName())
31-
roles = []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_ADMIN"}
32-
rolesStr = `"` + strings.Join(roles, `", "`) + `"`
31+
roles = []string{"GROUP_READ_ONLY", "GROUP_DATA_ACCESS_READ_ONLY"}
3332
)
3433

3534
resource.ParallelTest(t, resource.TestCase{
@@ -38,11 +37,11 @@ func TestMigCloudUserProjectAssignmentRS_migrationJourney(t *testing.T) {
3837
Steps: []resource.TestStep{
3938
{
4039
ExternalProviders: mig.ExternalProviders(),
41-
Config: originalConfigFirst(username, projectName, orgID, rolesStr),
40+
Config: originalConfigFirst(username, projectName, orgID, roles),
4241
},
4342
{
4443
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
45-
Config: userProjectAssignmentConfigSecond(username, projectName, orgID, rolesStr),
44+
Config: userProjectAssignmentConfigSecond(username, projectName, orgID, roles),
4645
Check: checksSecond(username, projectName, roles),
4746
},
4847
{
@@ -52,18 +51,19 @@ func TestMigCloudUserProjectAssignmentRS_migrationJourney(t *testing.T) {
5251
plancheck.ExpectResourceAction(resourceInvitationName, plancheck.ResourceActionDestroy),
5352
},
5453
},
55-
Config: removeProjectInvitationConfigThird(username, projectName, orgID, rolesStr),
54+
Config: removeProjectInvitationConfigThird(username, projectName, orgID, roles),
5655
},
57-
mig.TestStepCheckEmptyPlan(removeProjectInvitationConfigThird(username, projectName, orgID, rolesStr)),
56+
mig.TestStepCheckEmptyPlan(removeProjectInvitationConfigThird(username, projectName, orgID, roles)),
5857
},
5958
})
6059
}
6160

62-
func originalConfigFirst(username, projectName, orgID, roles string) string {
63-
return fmt.Sprintf(`
61+
func originalConfigFirst(username, projectName, orgID string, roles []string) string {
62+
rolesStr := `"` + strings.Join(roles, `", "`) + `"`
63+
config := fmt.Sprintf(`
6464
locals {
6565
username = %[1]q
66-
roles = [%[2]q]
66+
roles = [%[2]s]
6767
}
6868
6969
resource "mongodbatlas_project" "mig_test" {
@@ -76,14 +76,16 @@ func originalConfigFirst(username, projectName, orgID, roles string) string {
7676
username = local.username
7777
roles = local.roles
7878
}
79-
`, username, roles, projectName, orgID)
79+
`, username, rolesStr, projectName, orgID)
80+
return config
8081
}
8182

82-
func userProjectAssignmentConfigSecond(username, projectName, orgID, roles string) string {
83+
func userProjectAssignmentConfigSecond(username, projectName, orgID string, roles []string) string {
84+
rolesStr := `"` + strings.Join(roles, `", "`) + `"`
8385
return fmt.Sprintf(`
8486
locals {
8587
username = %[1]q
86-
roles = [%[2]q]
88+
roles = [%[2]s]
8789
}
8890
8991
resource "mongodbatlas_project" "mig_test" {
@@ -102,14 +104,15 @@ func userProjectAssignmentConfigSecond(username, projectName, orgID, roles strin
102104
username = local.username
103105
roles = local.roles
104106
}
105-
`, username, roles, projectName, orgID)
107+
`, username, rolesStr, projectName, orgID)
106108
}
107109

108-
func removeProjectInvitationConfigThird(username, projectName, orgID, roles string) string {
110+
func removeProjectInvitationConfigThird(username, projectName, orgID string, roles []string) string {
111+
rolesStr := `"` + strings.Join(roles, `", "`) + `"`
109112
return fmt.Sprintf(`
110113
locals {
111114
username = %[1]q
112-
roles = [%[2]q]
115+
roles = [%[2]s]
113116
}
114117
115118
resource "mongodbatlas_project" "mig_test" {
@@ -122,7 +125,7 @@ func removeProjectInvitationConfigThird(username, projectName, orgID, roles stri
122125
username = local.username
123126
roles = local.roles
124127
}
125-
`, username, roles, projectName, orgID)
128+
`, username, rolesStr, projectName, orgID)
126129
}
127130

128131
func checksSecond(username, projectName string, roles []string) resource.TestCheckFunc {
@@ -131,10 +134,5 @@ func checksSecond(username, projectName string, roles []string) resource.TestChe
131134
resource.TestCheckResourceAttrSet(resourceUserProjectAssignmentName, "project_id"),
132135
resource.TestCheckResourceAttr(resourceUserProjectAssignmentName, "roles.#", fmt.Sprintf("%d", len(roles))),
133136
}
134-
135-
for i, role := range roles {
136-
checkFuncs = append(checkFuncs, resource.TestCheckResourceAttr(resourceUserProjectAssignmentName, fmt.Sprintf("roles.%d", i), role))
137-
}
138-
139137
return resource.ComposeAggregateTestCheckFunc(checkFuncs...)
140138
}

0 commit comments

Comments
 (0)