Skip to content

Commit

Permalink
Fixing other unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charliecon committed Jul 26, 2024
1 parent 2d4fb78 commit 40edb27
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"
"os"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
"testing"

Expand All @@ -20,16 +21,14 @@ func TestUnitResourceRoutingQueueConditionalGroupRoutingUpdate(t *testing.T) {
tRules := generateRuleData()
tId := tQueueId + "/rules"

if !featureToggles.CSGToggleExists() {
if err := os.Setenv(featureToggles.CSGToggleName(), "true"); err != nil {
t.Errorf("failed to set env var: %v", err)
}
defer func(key string) {
if err := os.Unsetenv(key); err != nil {
t.Logf("failed to unset env var: %v", err)
}
}(featureToggles.CSGToggleName())
if err := util.SetEnvVariableIfNotSet(featureToggles.CSGToggleName(), "true"); err != nil {
t.Error(err)
}
defer func(key string) {
if err := os.Unsetenv(key); err != nil {
t.Logf("failed to unset env var: %v", err)
}
}(featureToggles.CSGToggleName())

groupRoutingProxy := &routingQueueConditionalGroupRoutingProxy{}
groupRoutingProxy.updateRoutingQueueConditionRoutingAttr = func(ctx context.Context, p *routingQueueConditionalGroupRoutingProxy, queueId string, rules *[]platformclientv2.Conditionalgrouproutingrule) (*[]platformclientv2.Conditionalgrouproutingrule, *platformclientv2.APIResponse, error) {
Expand Down Expand Up @@ -70,6 +69,15 @@ func TestUnitResourceRoutingQueueConditionalGroupRoutingRead(t *testing.T) {
tRules := generateRuleData()
tId := tQueueId + "/rules"

if err := util.SetEnvVariableIfNotSet(featureToggles.CSGToggleName(), "true"); err != nil {
t.Error(err)
}
defer func(key string) {
if err := os.Unsetenv(key); err != nil {
t.Logf("failed to unset env var: %v", err)
}
}(featureToggles.CSGToggleName())

groupRoutingProxy := &routingQueueConditionalGroupRoutingProxy{}

groupRoutingProxy.getRoutingQueueConditionRoutingAttr = func(ctx context.Context, p *routingQueueConditionalGroupRoutingProxy, queueId string) (*[]platformclientv2.Conditionalgrouproutingrule, *platformclientv2.APIResponse, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package routing_queue_outbound_email_address
import (
"context"
"net/http"
"os"
"terraform-provider-genesyscloud/genesyscloud/provider"
"terraform-provider-genesyscloud/genesyscloud/util"
featureToggles "terraform-provider-genesyscloud/genesyscloud/util/feature_toggles"
"testing"

"github.com/google/uuid"
Expand All @@ -19,6 +22,15 @@ func TestUnitResourceRoutingQueueOutboundEmailAddressUpdate(t *testing.T) {

tId := tQueueId

if err := util.SetEnvVariableIfNotSet(featureToggles.OEAToggleName(), "true"); err != nil {
t.Error(err)
}
defer func(key string) {
if err := os.Unsetenv(key); err != nil {
t.Logf("failed to unset env var: %v", err)
}
}(featureToggles.OEAToggleName())

groupRoutingProxy := &routingQueueOutboundEmailAddressProxy{}
groupRoutingProxy.updateRoutingQueueOutboundEmailAddressAttr = func(ctx context.Context, p *routingQueueOutboundEmailAddressProxy, queueId string, address *platformclientv2.Queueemailaddress) (*platformclientv2.Queueemailaddress, *platformclientv2.APIResponse, error) {
assert.Equal(t, tDomainId, *address.Domain.Id)
Expand Down Expand Up @@ -71,6 +83,15 @@ func TestUnitResourceRoutingQueueOutboundEmailAddressRead(t *testing.T) {
tRouteId := uuid.NewString()
tId := tQueueId

if err := util.SetEnvVariableIfNotSet(featureToggles.OEAToggleName(), "true"); err != nil {
t.Error(err)
}
defer func(key string) {
if err := os.Unsetenv(key); err != nil {
t.Logf("failed to unset env var: %v", err)
}
}(featureToggles.OEAToggleName())

groupRoutingProxy := &routingQueueOutboundEmailAddressProxy{}

groupRoutingProxy.getRoutingQueueOutboundEmailAddressAttr = func(ctx context.Context, p *routingQueueOutboundEmailAddressProxy, queueId string) (*platformclientv2.Queueemailaddress, *platformclientv2.APIResponse, error) {
Expand Down
10 changes: 10 additions & 0 deletions genesyscloud/util/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ func TestAccPreCheck(t *testing.T) {
}
}

func SetEnvVariableIfNotSet(key string, value string) error {
_, exists := os.LookupEnv(key)
if !exists {
if err := os.Setenv(key, value); err != nil {
return fmt.Errorf("failed to set env var: %v", err)
}
}
return nil
}

// VerifyAttributeInArrayOfPotentialValues For fields such as genesyscloud_outbound_campaign.campaign_status, which use a diff suppress func,
// and may return as "on", or "complete" depending on how long the operation takes
func VerifyAttributeInArrayOfPotentialValues(resource string, key string, potentialValues []string) resource.TestCheckFunc {
Expand Down

0 comments on commit 40edb27

Please sign in to comment.