Skip to content

Commit

Permalink
Fix failed acceptance testcases (#1162)
Browse files Browse the repository at this point in the history
* Modify order of testcase

* fix division deletion

* Fix testcases

* Fix testcases

* Fix outbound campaign

* Fix ExternralTrunkBaseSettingsInboundSite testcase

* Fix skipped testcases

* Fix skipped testcases

* Fix skipped testcases

* Fix failing tests

* Fix failing tests

* Fix testcases

* Fix testcases

* Fixing test & report

* fix testcases

* fix testcases

* fix testcases

* fix tests

* Fix testcase

* Fix testcase

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* Fix tests

* fix tests

* fix tests

* Resolve comments

---------

Co-authored-by: Monisha Padmavathi Ragavan <mpadmava@DWH3D21RYH-D.local>
  • Loading branch information
monishapadmavathi and Monisha Padmavathi Ragavan authored Jul 17, 2024
1 parent d5b6e2e commit 651e9b8
Show file tree
Hide file tree
Showing 31 changed files with 1,288 additions and 642 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
inboundCall:
name: Terraform Test Flow log level f79fc952-6a58-4d00-996e-2c3873e1871a
name: Terraform Emergency Test Flow 7fa2e8a9-b1d9-4d78-93b8-05b4465314a7
defaultLanguage: en-us
startUpRef: ./menus/menu[mainMenu]
initialGreeting:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package architect_emergencygroup

import (
"fmt"
"os"
"strconv"
"strings"
"terraform-provider-genesyscloud/genesyscloud/architect_flow"
Expand Down Expand Up @@ -39,6 +40,10 @@ func TestAccResourceArchitectEmergencyGroups(t *testing.T) {
// TODO: Create the IVR inside the test config once emergency group has been moved to its own package.
// Currently, the ivr resource cannot be registered for these tests because of a cyclic dependency issue.
ivrId := "f94e084e-40eb-470b-80d6-0f99cf22d102"
if v := os.Getenv("GENESYSCLOUD_REGION"); v == "tca" {
ivrId = "d37d14fe-1e6c-4ed6-a9bb-b6ef0dd8e9cd"
}

if !ivrExists(config, ivrId) {
t.Skip("Skipping because IVR does not exists in the target org.")
}
Expand Down
38 changes: 33 additions & 5 deletions genesyscloud/data_source_genesyscloud_auth_division_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package genesyscloud

import (
"fmt"
"log"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
Expand All @@ -17,6 +18,7 @@ func TestAccDataSourceAuthDivision(t *testing.T) {
divResource = "auth-division"
divDataSource = "auth-div-data"
divName = "Terraform Divisions-" + uuid.NewString()
divisionID string
)

resource.Test(t, resource.TestCase{
Expand All @@ -27,6 +29,26 @@ func TestAccDataSourceAuthDivision(t *testing.T) {
PreConfig: func() {
time.Sleep(30 * time.Second)
},
Config: GenerateAuthDivisionResource(
divResource,
divName,
util.NullValue,
util.NullValue,
),
Check: resource.ComposeTestCheckFunc(
func(s *terraform.State) error {
rs, ok := s.RootModule().Resources["genesyscloud_auth_division."+divResource]
if !ok {
return fmt.Errorf("not found: %s", "genesyscloud_auth_division."+divResource)
}
divisionID = rs.Primary.ID
log.Printf("Division ID: %s\n", divisionID) // Print ID
return nil
},
),
PreventPostDestroyRefresh: true,
},
{
Config: GenerateAuthDivisionResource(
divResource,
divName,
Expand All @@ -39,14 +61,20 @@ func TestAccDataSourceAuthDivision(t *testing.T) {
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.genesyscloud_auth_division."+divDataSource, "id", "genesyscloud_auth_division."+divResource, "id"),
func(s *terraform.State) error {
time.Sleep(30 * time.Second) // Wait for 30 seconds for proper deletion
return nil
},
),
},
{
// Import/Read
ResourceName: "genesyscloud_auth_division." + divResource,
ImportState: true,
ImportStateVerify: true,
Destroy: true,
},
},
CheckDestroy: func(state *terraform.State) error {
time.Sleep(45 * time.Second)
return testVerifyDivisionsDestroyed(state)
},
CheckDestroy: testVerifyDivisionsDestroyed,
})
}

Expand Down
23 changes: 22 additions & 1 deletion genesyscloud/data_source_genesyscloud_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@ package genesyscloud

import (
"fmt"
"log"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
"testing"
"time"

"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccDataSourceUser(t *testing.T) {
var (
userResource = "test-user"
userDataSource = "test-user-data"
randomString = uuid.NewString()
userEmail = "John_Doe" + randomString + "@example.com"
userEmail = "John_Doe" + randomString + "@exampleuser.com"
userName = "John_Doe" + randomString
userID string
)

resource.Test(t, resource.TestCase{
Expand All @@ -37,6 +41,15 @@ func TestAccDataSourceUser(t *testing.T) {
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.genesyscloud_user."+userDataSource, "id", "genesyscloud_user."+userResource, "id"),
func(s *terraform.State) error {
rs, ok := s.RootModule().Resources["genesyscloud_user."+userResource]
if !ok {
return fmt.Errorf("not found: %s", "genesyscloud_user."+userResource)
}
userID = rs.Primary.ID
log.Printf("User ID: %s\n", userID) // Print user ID
return nil
},
),
},
{
Expand All @@ -53,9 +66,17 @@ func TestAccDataSourceUser(t *testing.T) {
),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data.genesyscloud_user."+userDataSource, "id", "genesyscloud_user."+userResource, "id"),
func(s *terraform.State) error {
time.Sleep(30 * time.Second) // Wait for 30 seconds for proper deletion
return nil
},
),
},
},
CheckDestroy: func(state *terraform.State) error {
time.Sleep(45 * time.Second)
return testVerifyUsersDestroyed(state)
},
})
}

Expand Down
58 changes: 50 additions & 8 deletions genesyscloud/group/data_source_genesyscloud_group_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package group

import (
"context"
"fmt"
"log"
"sync"
Expand All @@ -13,12 +14,12 @@ import (
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

var (
sdkConfig *platformclientv2.Configuration
mu sync.Mutex
mu sync.Mutex
)

func TestAccDataSourceGroup(t *testing.T) {
Expand All @@ -37,6 +38,9 @@ func TestAccDataSourceGroup(t *testing.T) {
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: []resource.TestStep{
{
PreConfig: func() {
time.Sleep(30 * time.Second)
},
Config: generateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) +
GenerateGroupResource(
groupResource,
Expand All @@ -62,16 +66,20 @@ func TestAccDataSourceGroup(t *testing.T) {
return nil
},
),

PreventPostDestroyRefresh: true,
},
{
ResourceName: "genesyscloud_user." + testUserResource,
ImportState: true,
ImportStateVerify: true,
Check: resource.ComposeTestCheckFunc(
checkUserDeleted(userID),
),
Destroy: true,
},
},
CheckDestroy: func(state *terraform.State) error {
time.Sleep(45 * time.Second)
return testVerifyUsersDestroyed(state)
},
})
}

Expand All @@ -89,9 +97,9 @@ func generateGroupDataSource(
}

func checkUserDeleted(id string) resource.TestCheckFunc {
log.Printf("Fetching user with ID: %s\n", id)
return func(s *terraform.State) error {
maxAttempts := 18
maxAttempts := 30
fmt.Printf("Fetching user with ID: %s\n", id)
for i := 0; i < maxAttempts; i++ {

deleted, err := isUserDeleted(id)
Expand All @@ -111,8 +119,9 @@ func isUserDeleted(id string) (bool, error) {
mu.Lock()
defer mu.Unlock()

usersAPI := platformclientv2.NewUsersApiWithConfig(sdkConfig)
usersAPI := platformclientv2.NewUsersApi()
// Attempt to get the user
fmt.Printf("User ID: %s\n", id)
_, response, err := usersAPI.GetUser(id, nil, "", "")

// Check if the user is not found (deleted)
Expand All @@ -129,3 +138,36 @@ func isUserDeleted(id string) (bool, error) {
// If user is found, it means the user is not deleted
return false, nil
}

func testVerifyUsersDestroyed(state *terraform.State) error {
usersAPI := platformclientv2.NewUsersApi()

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 {
continue
}
_, resp, err := usersAPI.GetUser(rs.Primary.ID, nil, "", "")

if err != nil {
if util.IsStatus404(resp) {
continue
}
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_user", 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 nil
})

if diagErr != nil {
return fmt.Errorf(fmt.Sprintf("%v", diagErr))
}

// Success. All users destroyed
return nil
}
Loading

0 comments on commit 651e9b8

Please sign in to comment.