Skip to content

Commit

Permalink
feature/DEVTOOLING-167
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshperiyappan committed Jan 21, 2025
1 parent 789c2f9 commit eaec031
Show file tree
Hide file tree
Showing 17 changed files with 1,298 additions and 663 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"terraform-provider-genesyscloud/genesyscloud/architect_schedulegroups"
"terraform-provider-genesyscloud/genesyscloud/architect_schedules"
authDivision "terraform-provider-genesyscloud/genesyscloud/auth_division"
"terraform-provider-genesyscloud/genesyscloud/journey_segment"
"terraform-provider-genesyscloud/genesyscloud/provider"
"testing"

Expand Down Expand Up @@ -46,7 +47,7 @@ func (r *registerTestInstance) registerTestResources() {
providerResources[architect_schedules.ResourceType] = architect_schedules.ResourceArchitectSchedules()
providerResources[architect_schedulegroups.ResourceType] = architect_schedulegroups.ResourceArchitectSchedulegroups()
providerResources[architect_flow.ResourceType] = architect_flow.ResourceArchitectFlow()
providerResources["genesyscloud_journey_segment"] = gcloud.ResourceJourneySegment()
providerResources[journey_segment.ResourceType] = journey_segment.ResourceJourneySegment()
providerResources["genesyscloud_journey_outcome"] = gcloud.ResourceJourneyOutcome()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package journey_action_template
import (
"log"
"sync"
gcloud "terraform-provider-genesyscloud/genesyscloud"
"terraform-provider-genesyscloud/genesyscloud/journey_action_map"
"terraform-provider-genesyscloud/genesyscloud/journey_segment"
"terraform-provider-genesyscloud/genesyscloud/provider"
"testing"

Expand Down Expand Up @@ -40,7 +40,7 @@ func (r *registerTestInstance) registerTestResources() {

providerResources[ResourceType] = ResourceJourneyActionTemplate()
providerResources[journey_action_map.ResourceType] = journey_action_map.ResourceJourneyActionMap()
providerResources["genesyscloud_journey_segment"] = gcloud.ResourceJourneySegment()
providerResources[journey_segment.ResourceType] = journey_segment.ResourceJourneySegment()
}

// registerTestDataSources registers all data sources used in the tests.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genesyscloud
package journey_segment

import (
"context"
Expand All @@ -14,20 +14,6 @@ import (
"github.com/mypurecloud/platform-client-sdk-go/v150/platformclientv2"
)

func dataSourceJourneySegment() *schema.Resource {
return &schema.Resource{
Description: "Data source for Genesys Cloud Journey Segment. Select a journey segment by name",
ReadContext: provider.ReadWithPooledClient(dataSourceJourneySegmentRead),
Schema: map[string]*schema.Schema{
"name": {
Description: "Journey Segment name.",
Type: schema.TypeString,
Required: true,
},
},
}
}

func dataSourceJourneySegmentRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
sdkConfig := m.(*provider.ProviderMeta).ClientConfig
journeyApi := platformclientv2.NewJourneyApiWithConfig(sdkConfig)
Expand All @@ -41,13 +27,13 @@ func dataSourceJourneySegmentRead(ctx context.Context, d *schema.ResourceData, m
const pageSize = 100
journeySegments, resp, getErr := journeyApi.GetJourneySegments("", pageSize, pageNum, true, nil, nil, "")
if getErr != nil {
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_journey_segment", fmt.Sprintf("failed to get page of journey segments: %v", getErr), resp))
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("failed to get page of journey segments: %v", getErr), resp))
}

response = resp

if journeySegments.Entities == nil || len(*journeySegments.Entities) == 0 {
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_journey_segment", fmt.Sprintf("no journey segment found with name %s", name), resp))
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("no journey segment found with name %s", name), resp))
}

for _, journeySegment := range *journeySegments.Entities {
Expand All @@ -59,6 +45,6 @@ func dataSourceJourneySegmentRead(ctx context.Context, d *schema.ResourceData, m

pageCount = *journeySegments.PageCount
}
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError("genesyscloud_journey_segment", fmt.Sprintf("no journey segment found with name %s", name), response))
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("no journey segment found with name %s", name), response))
})
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genesyscloud
package journey_segment

import (
"terraform-provider-genesyscloud/genesyscloud/provider"
Expand All @@ -15,15 +15,14 @@ func TestAccDataSourceJourneySegment(t *testing.T) {
}

func runDataJourneySegmentTestCase(t *testing.T, testCaseName string) {
const resourceType = "genesyscloud_journey_segment"
testObjectName := testrunner.TestObjectIdPrefix + testCaseName
testObjectFullName := resourceType + "." + testObjectName
testObjectFullName := ResourceType + "." + testObjectName
setupJourneySegment(t, testCaseName)

resource.Test(t, resource.TestCase{
PreCheck: func() { util.TestAccPreCheck(t) },
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources),
Steps: testrunner.GenerateDataSourceTestSteps(resourceType, testCaseName, []resource.TestCheckFunc{
Steps: testrunner.GenerateDataSourceTestSteps(ResourceType, testCaseName, []resource.TestCheckFunc{
resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrPair("data."+testObjectFullName, "id", testObjectFullName, "id"),
resource.TestCheckResourceAttr(testObjectFullName, "display_name", testObjectName+"_to_find"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package journey_segment

import (
"log"
"sync"
"terraform-provider-genesyscloud/genesyscloud/provider"
"testing"

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

var (
sdkConfig *platformclientv2.Configuration
err error
)

/*
The genesyscloud_journey_segment_init_test.go file is used to initialize the data sources and resources
used in testing the journey_segment resource.
*/

// providerDataSources holds a map of all registered datasources
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[ResourceType] = ResourceJourneySegment()
}

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

providerDataSources[ResourceType] = DataSourceJourneySegment()
}

// initTestResources initializes all test resources and data sources.
func initTestResources() {
if sdkConfig, err = provider.AuthorizeSdk(); err != nil {
log.Fatal(err)
}
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 journey_segment package
initTestResources()

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

0 comments on commit eaec031

Please sign in to comment.