Skip to content

Commit

Permalink
Fixed Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMoyles committed Sep 11, 2024
1 parent 431cac6 commit b4e9ebe
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
23 changes: 15 additions & 8 deletions genesyscloud/routing_queue/genesyscloud_routing_queue_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var internalProxy *RoutingQueueProxy

type GetAllRoutingQueuesFunc func(ctx context.Context, p *RoutingQueueProxy, name string) (*[]platformclientv2.Queue, *platformclientv2.APIResponse, error)
type createRoutingQueueFunc func(ctx context.Context, p *RoutingQueueProxy, createReq *platformclientv2.Createqueuerequest) (*platformclientv2.Queue, *platformclientv2.APIResponse, error)
type getRoutingQueueByIdFunc func(ctx context.Context, p *RoutingQueueProxy, queueId string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error)
type getRoutingQueueByIdFunc func(ctx context.Context, p *RoutingQueueProxy, queueId string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error)
type getRoutingQueueByNameFunc func(ctx context.Context, p *RoutingQueueProxy, name string) (string, *platformclientv2.APIResponse, bool, error)
type updateRoutingQueueFunc func(ctx context.Context, p *RoutingQueueProxy, queueId string, updateReq *platformclientv2.Queuerequest) (*platformclientv2.Queue, *platformclientv2.APIResponse, error)
type deleteRoutingQueueFunc func(ctx context.Context, p *RoutingQueueProxy, queueId string, forceDelete bool) (*platformclientv2.APIResponse, error)
Expand Down Expand Up @@ -101,8 +101,8 @@ func (p *RoutingQueueProxy) createRoutingQueue(ctx context.Context, createReq *p
return p.createRoutingQueueAttr(ctx, p, createReq)
}

func (p *RoutingQueueProxy) getRoutingQueueById(ctx context.Context, queueId string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
return p.getRoutingQueueByIdAttr(ctx, p, queueId)
func (p *RoutingQueueProxy) getRoutingQueueById(ctx context.Context, queueId string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
return p.getRoutingQueueByIdAttr(ctx, p, queueId, checkCache)
}

func (p *RoutingQueueProxy) getRoutingQueueByName(ctx context.Context, name string) (string, *platformclientv2.APIResponse, bool, error) {
Expand Down Expand Up @@ -187,10 +187,12 @@ func createRoutingQueueFn(ctx context.Context, p *RoutingQueueProxy, createReq *
}

// getRoutingQueueByIdFn is the implementation for retrieving a routing queues in Genesys Cloud
func getRoutingQueueByIdFn(ctx context.Context, p *RoutingQueueProxy, queueId string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
queue := rc.GetCacheItem(p.RoutingQueueCache, queueId)
if queue != nil {
return queue, nil, nil
func getRoutingQueueByIdFn(ctx context.Context, p *RoutingQueueProxy, queueId string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
if checkCache {
queue := rc.GetCacheItem(p.RoutingQueueCache, queueId)
if queue != nil {
return queue, nil, nil
}
}

return p.routingApi.GetRoutingQueue(queueId)
Expand Down Expand Up @@ -220,7 +222,12 @@ func updateRoutingQueueFn(ctx context.Context, p *RoutingQueueProxy, queueId str
}

func deleteRoutingQueueFn(ctx context.Context, p *RoutingQueueProxy, queueID string, forceDelete bool) (*platformclientv2.APIResponse, error) {
return p.routingApi.DeleteRoutingQueue(queueID, forceDelete)
resp, err := p.routingApi.DeleteRoutingQueue(queueID, forceDelete)
if err != nil {
return resp, err
}
rc.DeleteCacheItem(p.RoutingQueueCache, queueID)
return resp, nil
}

func getAllRoutingQueueWrapupCodesFn(ctx context.Context, p *RoutingQueueProxy, queueId string) (*[]platformclientv2.Wrapupcode, *platformclientv2.APIResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func readRoutingQueue(ctx context.Context, d *schema.ResourceData, meta interfac
log.Printf("Reading queue %s", d.Id())

return util.WithRetriesForRead(ctx, d, func() *retry.RetryError {
currentQueue, resp, getErr := proxy.getRoutingQueueById(ctx, d.Id())
currentQueue, resp, getErr := proxy.getRoutingQueueById(ctx, d.Id(), true)
if getErr != nil {
if util.IsStatus404(resp) {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read queue %s | error: %s", d.Id(), getErr), resp))
Expand Down Expand Up @@ -362,7 +362,7 @@ they are being removed when the parent queue is updated since the update body do
If the independent resources are enabled, pass in the current OEA and/or CGR to the update queue so they are not removed
*/
func addCGRAndOEA(proxy *RoutingQueueProxy, d *schema.ResourceData, queue *platformclientv2.Queuerequest) diag.Diagnostics {
currentQueue, resp, err := proxy.getRoutingQueueById(ctx, d.Id())
currentQueue, resp, err := proxy.getRoutingQueueById(ctx, d.Id(), true)
if err != nil {
return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to get queue %s for update, error: %s", *queue.Name, err), resp)
}
Expand All @@ -378,7 +378,7 @@ func addCGRAndOEA(proxy *RoutingQueueProxy, d *schema.ResourceData, queue *platf
queue.ConditionalGroupRouting = currentQueue.ConditionalGroupRouting

// remove queue_id from first CGR rule to avoid api error
if len(*queue.ConditionalGroupRouting.Rules) > 0 {
if queue.ConditionalGroupRouting != nil && len(*queue.ConditionalGroupRouting.Rules) > 0 {
(*queue.ConditionalGroupRouting.Rules)[0].Queue = nil
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func deleteRoutingQueue(ctx context.Context, d *schema.ResourceData, meta interf

//DEVTOOLING-238- Increasing this to a 120 seconds to see if we can temporarily mitigate a problem for a customer
return util.WithRetries(ctx, 120*time.Second, func() *retry.RetryError {
_, resp, err := proxy.getRoutingQueueById(ctx, d.Id())
_, resp, err := proxy.getRoutingQueueById(ctx, d.Id(), false)
if err != nil {
if util.IsStatus404(resp) {
// Queue deleted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func getRoutingQueueMembers(queueID string, memberBy string, sdkConfig *platform
var members []platformclientv2.Queuemember

// Need to call this method to find the member count for a queue. GetRoutingQueueMembers does not return a `total` property for us to use.
queue, resp, err := proxy.getRoutingQueueById(ctx, queueID)
queue, resp, err := proxy.getRoutingQueueById(ctx, queueID, true)
if err != nil {
return nil, util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to find queue %s error: %s", queueID, err), resp)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestUnitResourceRoutingQueueCreate(t *testing.T) {
testRoutingQueue := generateRoutingQueueData(tId, tName)

queueProxy := &RoutingQueueProxy{}
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, p *RoutingQueueProxy, queueId string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, p *RoutingQueueProxy, queueId string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, queueId)
routingQueue := &testRoutingQueue

Expand Down Expand Up @@ -99,7 +99,7 @@ func TestUnitResourceRoutingQueueRead(t *testing.T) {
testRoutingQueue := generateRoutingQueueData(tId, tName)

queueProxy := &RoutingQueueProxy{}
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, proxy *RoutingQueueProxy, id string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, proxy *RoutingQueueProxy, id string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
routingQueue := &testRoutingQueue

Expand Down Expand Up @@ -177,7 +177,7 @@ func TestUnitResourceRoutingQueueUpdate(t *testing.T) {
testRoutingQueue := generateRoutingQueueData(tId, tName)

queueProxy := &RoutingQueueProxy{}
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, proxy *RoutingQueueProxy, id string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, proxy *RoutingQueueProxy, id string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)
routingQueue := &testRoutingQueue

Expand Down Expand Up @@ -267,7 +267,7 @@ func TestUnitResourceRoutingQueueDelete(t *testing.T) {
return apiResponse, nil
}

queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, proxy *RoutingQueueProxy, id string) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
queueProxy.getRoutingQueueByIdAttr = func(ctx context.Context, proxy *RoutingQueueProxy, id string, checkCache bool) (*platformclientv2.Queue, *platformclientv2.APIResponse, error) {
assert.Equal(t, tId, id)

apiResponse := &platformclientv2.APIResponse{StatusCode: http.StatusNotFound}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func TestAccResourceTfExportIncludeFilterResourcesByRegEx(t *testing.T) {
})
}

// TestAccResourceTfExportIncludeFilterResourcesByRegExAndSanitizedNames will create 3 queues (two with foo bar, one to be excluded).
// TestAccResourceTfExportIncludeFilterResourcesByRegExAndSanitizedNames will create 3 queues (twoc with foo bar, one to be excluded).
// The test ensures that resources can be exported directly by their actual name or their sanitized names.
func TestAccResourceTfExportIncludeFilterResourcesByRegExAndSanitizedNames(t *testing.T) {
var (
Expand Down Expand Up @@ -1124,6 +1124,8 @@ func TestAccResourceTfExportQueueAsHCL(t *testing.T) {
util.TrueValue,
util.FalseValue,
strconv.Quote("TimestampAndPriority"),
util.NullValue,
util.NullValue,
routingQueue.GenerateMediaSettings("media_settings_call", alertTimeoutSec, util.FalseValue, slPercentage, slDurationMs),
routingQueue.GenerateRoutingRules(rrOperator, rrThreshold, rrWaitSeconds),
routingQueue.GenerateDefaultScriptIDs(chatScriptID, emailScriptID),
Expand Down

0 comments on commit b4e9ebe

Please sign in to comment.