Skip to content

Commit

Permalink
Devtooling 485 fix group delete v2 (#927)
Browse files Browse the repository at this point in the history
* DEVTOOLING-485: Refactored group into package and then fixed bug

* DEVTOOLING-485: Added caching

* DEVTOOLING-485: Added caching

* DEVTOOLING-485: Fixing the group delete
  • Loading branch information
carnellj-genesys authored Mar 25, 2024
1 parent fd5620c commit 067a152
Show file tree
Hide file tree
Showing 30 changed files with 1,220 additions and 760 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
inboundCall:
name: Terraform Flow Test-b9eac7f8-cbf3-4a7f-95fc-f088c95deb6c
name: Terraform Flow Test-e74202b4-a83b-4247-a7d1-b1e94e752344
description: test description 1
defaultLanguage: en-us
startUpRef: ./menus/menu[mainMenu]
initialGreeting:
Expand Down
41 changes: 17 additions & 24 deletions examples/resources/genesyscloud_flow/inboundcall_flow_example2.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
inboundEmail:
name: Terraform Flow Test-4598b11f-bbf0-4533-96bc-cc271ac1d5a3
division: New Home
startUpRef: "/inboundEmail/states/state[Initial State_10]"
defaultLanguage: en-us
supportedLanguages:
en-us:
defaultLanguageSkill:
noValue: true
settingsInboundEmailHandling:
emailHandling:
disconnect:
none: true
settingsErrorHandling:
errorHandling:
disconnect:
none: true
states:
- state:
name: Initial State
refId: Initial State_10
actions:
- disconnect:
name: Disconnect
inboundCall:
name: Terraform Flow Test-e74202b4-a83b-4247-a7d1-b1e94e752344
description: test description 2
defaultLanguage: en-us
startUpRef: ./menus/menu[mainMenu]
initialGreeting:
tts: Archy says hi!!!!!
menus:
- menu:
name: Main Menu
audio:
tts: You are at the Main Menu, press 9 to disconnect.
refId: mainMenu
choices:
- menuDisconnect:
name: Disconnect
dtmf: digit_9
40 changes: 24 additions & 16 deletions examples/resources/genesyscloud_flow/inboundcall_flow_example3.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
inboundCall:
name: Terraform Flow Test-09cb1249-e934-4fb7-b35b-a96940f494c7
defaultLanguage: en-us
startUpRef: ./menus/menu[mainMenu]
initialGreeting:
tts: Archy says hi!!!!!
menus:
- menu:
name: Main Menu
audio:
tts: You are at the Main Menu, press 9 to disconnect.
refId: mainMenu
choices:
- menuDisconnect:
name: Disconnect
dtmf: digit_9
inboundEmail:
name: Terraform Flow Test-e74202b4-a83b-4247-a7d1-b1e94e752344
description: test description 1
startUpRef: "/inboundEmail/states/state[Initial State_10]"
defaultLanguage: en-us
supportedLanguages:
en-us:
defaultLanguageSkill:
noValue: true
settingsInboundEmailHandling:
emailHandling:
disconnect:
none: true
settingsErrorHandling:
errorHandling:
disconnect:
none: true
states:
- state:
name: Initial State
refId: Initial State_10
actions:
- disconnect:
name: Disconnect
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workflow:
name: terraform-provider-test-97450725-2830-42de-a230-5d763ecce39f
name: terraform-provider-test-72a265af-6a5d-4843-85f9-49a97ec5b77c
division: New Home
startUpRef: "/workflow/states/state[Initial State_10]"
defaultLanguage: en-us
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genesyscloud
package group

import (
"context"
Expand All @@ -11,47 +11,26 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/mypurecloud/platform-client-sdk-go/v125/platformclientv2"
)

func DataSourceGroup() *schema.Resource {
return &schema.Resource{
Description: "Data source for Genesys Cloud Groups. Select a group by name.",
ReadContext: provider.ReadWithPooledClient(dataSourceGroupRead),
Schema: map[string]*schema.Schema{
"name": {
Description: "Group name.",
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
groupsAPI := platformclientv2.NewGroupsApiWithConfig(sdkConfig)
gp := getGroupProxy(sdkConfig)

exactSearchType := "EXACT"
nameField := "name"
nameStr := d.Get("name").(string)

searchCriteria := platformclientv2.Groupsearchcriteria{
VarType: &exactSearchType,
Value: &nameStr,
Fields: &[]string{nameField},
}

return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError {
groups, _, getErr := groupsAPI.PostGroupsSearch(platformclientv2.Groupsearchrequest{
Query: &[]platformclientv2.Groupsearchcriteria{searchCriteria},
})
groups, _, getErr := gp.getGroupsByName(ctx, nameStr)
if getErr != nil {
return retry.NonRetryableError(fmt.Errorf("Error requesting group %s: %s", nameStr, getErr))
}

if *groups.Total > 1 {
return retry.NonRetryableError(fmt.Errorf("Multiple groups found with name %s ", nameStr))
}

if *groups.Total == 0 {
return retry.RetryableError(fmt.Errorf("No groups found with search criteria %v ", searchCriteria))
return retry.RetryableError(fmt.Errorf("No groups found with name %s ", nameStr))
}

// Select first group in the list
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genesyscloud
package group

import (
"fmt"
Expand Down Expand Up @@ -26,8 +26,8 @@ func TestAccDataSourceGroup(t *testing.T) {
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: []resource.TestStep{
{
Config: GenerateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) +
generateGroupResource(
Config: generateUserWithCustomAttrs(testUserResource, testUserEmail, testUserName) +
GenerateGroupResource(
groupResource,
groupName,
util.NullValue, // No description
Expand Down
56 changes: 56 additions & 0 deletions genesyscloud/group/genesyscloud_group_init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package group

import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"sync"
"terraform-provider-genesyscloud/genesyscloud"
"testing"
)

var providerDataSources map[string]*schema.Resource

// providerResources holds a map of all registered resources
var providerResources map[string]*schema.Resource

type registerTestInstance struct {
resourceMapMutex sync.RWMutex
datasourceMapMutex sync.RWMutex
}

// registerTestResources registers all resources used in the tests
func (r *registerTestInstance) registerTestResources() {
r.resourceMapMutex.Lock()
defer r.resourceMapMutex.Unlock()

providerResources[resourceName] = ResourceGroup()
providerResources["genesyscloud_user"] = genesyscloud.ResourceUser()

}

// registerTestDataSources registers all data sources used in the tests.
func (r *registerTestInstance) registerTestDataSources() {
r.datasourceMapMutex.Lock()
defer r.datasourceMapMutex.Unlock()

providerDataSources[resourceName] = DataSourceGroup()
}

// initTestResources initializes all test resources and data sources.
func initTestResources() {
providerDataSources = make(map[string]*schema.Resource)
providerResources = make(map[string]*schema.Resource)

regInstance := &registerTestInstance{}

regInstance.registerTestResources()
regInstance.registerTestDataSources()
}

// TestMain is a "setup" function called by the testing framework when run the test
func TestMain(m *testing.M) {
// Run setup function before starting the test suite for the flow_outcome package
initTestResources()

// Run the test suite for the flow_outcome package
m.Run()
}
Loading

0 comments on commit 067a152

Please sign in to comment.