Skip to content

Commit adce338

Browse files
authored
Merge pull request #32 from osodevops/fix/concurrent-organization-role-acceptance
test: use named roles in concurrency acceptance test
2 parents a3b4de5 + 5eb30a3 commit adce338

1 file changed

Lines changed: 22 additions & 45 deletions

File tree

internal/provider/resource_organization_role_test.go

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,19 @@ func TestAccOrganizationRoleResource_Concurrent(t *testing.T) {
9191
Steps: []resource.TestStep{
9292
{
9393
Config: testAccOrganizationRoleResourceConcurrentConfig(orgName, slugPrefix),
94-
Check: testCheckConcurrentOrganizationRoles,
94+
Check: resource.ComposeAggregateTestCheckFunc(
95+
resource.TestCheckResourceAttr("workos_organization_role.concurrent_admin", "name", "Admin"),
96+
resource.TestCheckResourceAttr("workos_organization_role.concurrent_editor", "name", "Editor"),
97+
resource.TestCheckResourceAttr("workos_organization_role.concurrent_viewer", "name", "Viewer"),
98+
resource.TestCheckResourceAttrSet("workos_organization_role.concurrent_admin", "id"),
99+
resource.TestCheckResourceAttrSet("workos_organization_role.concurrent_editor", "id"),
100+
resource.TestCheckResourceAttrSet("workos_organization_role.concurrent_viewer", "id"),
101+
),
95102
},
96103
},
97104
})
98105
}
99106

100-
func testCheckConcurrentOrganizationRoles(state *terraform.State) error {
101-
expectedRoles := []struct {
102-
key string
103-
name string
104-
}{
105-
{key: "admin", name: "Admin"},
106-
{key: "editor", name: "Editor"},
107-
{key: "viewer", name: "Viewer"},
108-
}
109-
110-
for _, expected := range expectedRoles {
111-
address := fmt.Sprintf(`workos_organization_role.concurrent[%q]`, expected.key)
112-
role, ok := state.RootModule().Resources[address]
113-
if !ok {
114-
return fmt.Errorf("resource not found in state: %s", address)
115-
}
116-
if got := role.Primary.Attributes["name"]; got != expected.name {
117-
return fmt.Errorf("expected %s name to be %q, got %q", address, expected.name, got)
118-
}
119-
if role.Primary.Attributes["id"] == "" {
120-
return fmt.Errorf("expected %s id to be set", address)
121-
}
122-
}
123-
124-
return nil
125-
}
126-
127107
func testAccOrganizationRoleResourceConfig(orgName, slug, name, description string) string {
128108
return fmt.Sprintf(`
129109
resource "workos_organization" "test" {
@@ -159,25 +139,22 @@ resource "workos_organization" "concurrent" {
159139
name = %[1]q
160140
}
161141
162-
resource "workos_organization_role" "concurrent" {
163-
for_each = {
164-
admin = {
165-
slug = "%[2]s-admin"
166-
name = "Admin"
167-
}
168-
editor = {
169-
slug = "%[2]s-editor"
170-
name = "Editor"
171-
}
172-
viewer = {
173-
slug = "%[2]s-viewer"
174-
name = "Viewer"
175-
}
176-
}
142+
resource "workos_organization_role" "concurrent_admin" {
143+
organization_id = workos_organization.concurrent.id
144+
slug = "%[2]s-admin"
145+
name = "Admin"
146+
}
147+
148+
resource "workos_organization_role" "concurrent_editor" {
149+
organization_id = workos_organization.concurrent.id
150+
slug = "%[2]s-editor"
151+
name = "Editor"
152+
}
177153
154+
resource "workos_organization_role" "concurrent_viewer" {
178155
organization_id = workos_organization.concurrent.id
179-
slug = each.value.slug
180-
name = each.value.name
156+
slug = "%[2]s-viewer"
157+
name = "Viewer"
181158
}
182159
`, orgName, slugPrefix)
183160
}

0 commit comments

Comments
 (0)