Skip to content

Commit a3b4de5

Browse files
authored
Merge pull request #31 from osodevops/fix/organization-role-acceptance-check
test: support for_each acceptance state checks
2 parents 2313bb7 + c2cd0f7 commit a3b4de5

1 file changed

Lines changed: 28 additions & 8 deletions

File tree

internal/provider/resource_organization_role_test.go

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,39 @@ func TestAccOrganizationRoleResource_Concurrent(t *testing.T) {
9191
Steps: []resource.TestStep{
9292
{
9393
Config: testAccOrganizationRoleResourceConcurrentConfig(orgName, slugPrefix),
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-
),
94+
Check: testCheckConcurrentOrganizationRoles,
10295
},
10396
},
10497
})
10598
}
10699

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+
107127
func testAccOrganizationRoleResourceConfig(orgName, slug, name, description string) string {
108128
return fmt.Sprintf(`
109129
resource "workos_organization" "test" {

0 commit comments

Comments
 (0)