Skip to content

Commit

Permalink
test case no longer calls api direct
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMoyles committed Jul 19, 2024
1 parent 78788c3 commit 4eae994
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 37 deletions.
11 changes: 4 additions & 7 deletions genesyscloud/resource_genesyscloud_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1125,11 +1125,7 @@ func testVerifyUsersDestroyed(state *terraform.State) error {

diagErr := util.WithRetries(context.Background(), 20*time.Second, func() *retry.RetryError {
for _, rs := range state.RootModule().Resources {
if rs.Type != "genesyscloud_user" {
continue
}
err := checkUserDeleted(rs.Primary.ID)(state)
if err != nil {
if rs.Type != resourceName {
continue
}
_, resp, err := usersAPI.GetUser(rs.Primary.ID, nil, "", "")
Expand All @@ -1138,9 +1134,10 @@ func testVerifyUsersDestroyed(state *terraform.State) error {
if util.IsStatus404(resp) {
continue
}
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", fmt.Sprintf("Unexpected error: %s", err), resp))
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Unexpected error: %s", err), resp))
}
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", fmt.Sprintf("User (%s) still exists", rs.Primary.ID), resp))

return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("User (%s) still exists", rs.Primary.ID), resp))
}
return nil
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,11 @@ resource "genesyscloud_routing_skill_group" "%s" {
ResourceName: "genesyscloud_routing_skill_group." + skillGroupResourceId,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"member_division_ids"},
ImportStateVerifyIgnore: []string{"member_divisions"},
Destroy: true,

},
},
CheckDestroy: testVerifySkillGroupDestroyed,
CheckDestroy: testVerifySkillGroupAndUsersDestroyed,
})
}

Expand Down Expand Up @@ -706,34 +705,26 @@ func testVerifySkillGroupDestroyed(state *terraform.State) error {
return nil
}
func testVerifySkillGroupAndUsersDestroyed(state *terraform.State) error {
config, err := provider.AuthorizeSdk()
if err != nil {
return fmt.Errorf("unexpected error while trying to authorize client in testVerifySkillGroupDestroyed : %s", err)
}
routingAPI := platformclientv2.NewRoutingApiWithConfig(config)
usersAPI := platformclientv2.NewUsersApiWithConfig(config)

routingAPI := platformclientv2.NewRoutingApiWithConfig(sdkConfig)
apiClient := &routingAPI.Configuration.APIClient
usersAPI := platformclientv2.NewUsersApiWithConfig(sdkConfig)
// TODO Once this code has been released into the public API we should fix this and use the SDK

headerParams := BuildHeaderParams(routingAPI)
for _, rs := range state.RootModule().Resources {
if rs.Type == "genesyscloud_routing_skill_group" {
path := routingAPI.Configuration.BasePath + "/api/v2/routing/skillgroups/" + rs.Primary.ID
response, err := apiClient.CallAPI(path, "GET", nil, headerParams, nil, nil, "", nil)
group, response, err := routingAPI.GetRoutingSkillgroup(rs.Primary.ID)

skillGroupPayload := make(map[string]interface{})

if err != nil {
if util.IsStatus404(response) {
break
}

return fmt.Errorf("Unexpected error while trying to read skillgroup: %s", err)
if group != nil {
return fmt.Errorf("team (%s) still exists", rs.Primary.ID)
}

json.Unmarshal(response.RawBody, &skillGroupPayload)

if skillGroupPayload["id"] != nil && skillGroupPayload["id"] != "" {
return fmt.Errorf("Skill Group (%s) still exists", rs.Primary.ID)
if util.IsStatus404(response) {
continue
}
return fmt.Errorf("Unexpected error: %s", err)
}

if rs.Type == "genesyscloud_user" {
err := checkUserDeleted(rs.Primary.ID)(state)
if err != nil {
Expand All @@ -743,10 +734,8 @@ func testVerifySkillGroupAndUsersDestroyed(state *terraform.State) error {
if user != nil {
return fmt.Errorf("User Resource (%s) still exists", rs.Primary.ID)
} else if util.IsStatus404(resp) {
// User not found as expected
continue
} else {
// Unexpected error
return fmt.Errorf("Unexpected error: %s", err)
}
}
Expand Down Expand Up @@ -793,10 +782,6 @@ func checkUserDeleted(id string) resource.TestCheckFunc {
}

func isUserDeleted(id string) (bool, error) {
<<<<<<< HEAD

=======
>>>>>>> 67d2d15c (PR)
sdkConfig, _ := provider.AuthorizeSdk()
usersAPI := platformclientv2.NewUsersApiWithConfig(sdkConfig)
// Attempt to get the user
Expand Down

0 comments on commit 4eae994

Please sign in to comment.