-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added supported content default resource
- Loading branch information
1 parent
8b72c71
commit 134f291
Showing
9 changed files
with
343 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
3 changes: 3 additions & 0 deletions
3
...resources/genesyscloud_conversations_messaging_supportedcontent_default/apis.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* [PUT /api/v2/conversations/messaging/supportedcontent/default](https://developer.genesys.cloud/devapps/api-explorer#put-api-v2-conversations-messaging-supportedcontent-default) | ||
* [GET /api/v2/conversations/messaging/supportedcontent/default](https://developer.genesys.cloud/devapps/api-explorer#get-api-v2-conversations-messaging-supportedcontent-default) | ||
|
Empty file.
54 changes: 54 additions & 0 deletions
54
...ontent_default/genesyscloud_conversations_messaging_supportedcontent_default_init_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"sync" | ||
"testing" | ||
|
||
cmSupportedContent "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_supportedcontent" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
/* | ||
The genesyscloud_conversations_messaging_supportedcontent_default_init_test.go file is used to initialize the data sources and resources | ||
used in testing the conversations_messaging_supportedcontent_default 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[resourceName] = ResourceConversationsMessagingSupportedcontentDefault() | ||
providerResources["genesyscloud_conversations_messaging_supportedcontent"] = cmSupportedContent.ResourceSupportedContent() | ||
} | ||
|
||
// initTestResources initializes all test resources and data sources. | ||
func initTestResources() { | ||
providerDataSources = make(map[string]*schema.Resource) | ||
providerResources = make(map[string]*schema.Resource) | ||
|
||
regInstance := ®isterTestInstance{} | ||
|
||
regInstance.registerTestResources() | ||
} | ||
|
||
// 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 conversations_messaging_supportedcontent_default package | ||
initTestResources() | ||
|
||
// Run the test suite for the conversations_messaging_supportedcontent_default package | ||
m.Run() | ||
} |
69 changes: 69 additions & 0 deletions
69
...tedcontent_default/genesyscloud_conversations_messaging_supportedcontent_default_proxy.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" | ||
) | ||
|
||
/* | ||
The genesyscloud_conversations_messaging_supportedcontent_default_proxy.go file contains the proxy structures and methods that interact | ||
with the Genesys Cloud SDK. We use composition here for each function on the proxy so individual functions can be stubbed | ||
out during testing. | ||
*/ | ||
|
||
// internalProxy holds a proxy instance that can be used throughout the package | ||
var internalProxy *conversationsMessagingSupportedcontentDefaultProxy | ||
|
||
// Type definitions for each func on our proxy so we can easily mock them out later | ||
type getConversationsMessagingSupportedcontentDefaultFunc func(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) | ||
type updateConversationsMessagingSupportedcontentDefaultFunc func(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy, id string, supportedContentReference *platformclientv2.Supportedcontentreference) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) | ||
|
||
// conversationsMessagingSupportedcontentDefaultProxy contains all of the methods that call genesys cloud APIs. | ||
type conversationsMessagingSupportedcontentDefaultProxy struct { | ||
clientConfig *platformclientv2.Configuration | ||
conversationsApi *platformclientv2.ConversationsApi | ||
getConversationsMessagingSupportedcontentDefaultAttr getConversationsMessagingSupportedcontentDefaultFunc | ||
updateConversationsMessagingSupportedcontentDefaultAttr updateConversationsMessagingSupportedcontentDefaultFunc | ||
} | ||
|
||
// newConversationsMessagingSupportedcontentDefaultProxy initializes the conversations messaging supportedcontent default proxy with all of the data needed to communicate with Genesys Cloud | ||
func newConversationsMessagingSupportedcontentDefaultProxy(clientConfig *platformclientv2.Configuration) *conversationsMessagingSupportedcontentDefaultProxy { | ||
api := platformclientv2.NewConversationsApiWithConfig(clientConfig) | ||
return &conversationsMessagingSupportedcontentDefaultProxy{ | ||
clientConfig: clientConfig, | ||
conversationsApi: api, | ||
getConversationsMessagingSupportedcontentDefaultAttr: getConversationsMessagingSupportedcontentDefaultFn, | ||
updateConversationsMessagingSupportedcontentDefaultAttr: updateConversationsMessagingSupportedcontentDefaultFn, | ||
} | ||
} | ||
|
||
// getConversationsMessagingSupportedcontentDefaultProxy acts as a singleton to for the internalProxy. It also ensures | ||
// that we can still proxy our tests by directly setting internalProxy package variable | ||
func getConversationsMessagingSupportedcontentDefaultProxy(clientConfig *platformclientv2.Configuration) *conversationsMessagingSupportedcontentDefaultProxy { | ||
if internalProxy == nil { | ||
internalProxy = newConversationsMessagingSupportedcontentDefaultProxy(clientConfig) | ||
} | ||
|
||
return internalProxy | ||
} | ||
|
||
// getConversationsMessagingSupportedcontentDefault retrieves all Genesys Cloud conversations messaging supportedcontent default | ||
func (p *conversationsMessagingSupportedcontentDefaultProxy) getConversationsMessagingSupportedcontentDefault(ctx context.Context) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.getConversationsMessagingSupportedcontentDefaultAttr(ctx, p) | ||
} | ||
|
||
// updateConversationsMessagingSupportedcontentDefault updates a Genesys Cloud conversations messaging supportedcontent default | ||
func (p *conversationsMessagingSupportedcontentDefaultProxy) updateConversationsMessagingSupportedcontentDefault(ctx context.Context, id string, conversationsMessagingSupportedcontentDefault *platformclientv2.Supportedcontentreference) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.updateConversationsMessagingSupportedcontentDefaultAttr(ctx, p, id, conversationsMessagingSupportedcontentDefault) | ||
} | ||
|
||
// getConversationsMessagingSupportedcontentDefaultFn is the implementation for retrieving all conversations messaging supportedcontent default in Genesys Cloud | ||
func getConversationsMessagingSupportedcontentDefaultFn(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.conversationsApi.GetConversationsMessagingSupportedcontentDefault() | ||
} | ||
|
||
// updateConversationsMessagingSupportedcontentDefaultFn is an implementation of the function to update a Genesys Cloud conversations messaging supportedcontent default | ||
func updateConversationsMessagingSupportedcontentDefaultFn(ctx context.Context, p *conversationsMessagingSupportedcontentDefaultProxy, id string, conversationsMessagingSupportedcontentDefault *platformclientv2.Supportedcontentreference) (*platformclientv2.Supportedcontent, *platformclientv2.APIResponse, error) { | ||
return p.conversationsApi.PutConversationsMessagingSupportedcontentDefault(*conversationsMessagingSupportedcontentDefault) | ||
} |
76 changes: 76 additions & 0 deletions
76
...content_default/resource_genesyscloud_conversations_messaging_supportedcontent_default.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"terraform-provider-genesyscloud/genesyscloud/consistency_checker" | ||
"terraform-provider-genesyscloud/genesyscloud/provider" | ||
"terraform-provider-genesyscloud/genesyscloud/util" | ||
"terraform-provider-genesyscloud/genesyscloud/util/constants" | ||
"terraform-provider-genesyscloud/genesyscloud/util/resourcedata" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/mypurecloud/platform-client-sdk-go/v133/platformclientv2" | ||
) | ||
|
||
/* | ||
The resource_genesyscloud_conversations_messaging_supportedcontent_default.go contains all of the methods that perform the core logic for a resource. | ||
*/ | ||
|
||
// createConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to create Genesys cloud conversations messaging supportedcontent default | ||
func createConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
d.SetId("supported_content_default") | ||
return updateConversationsMessagingSupportedcontentDefault(ctx, d, meta) | ||
} | ||
|
||
// readConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to read an conversations messaging supportedcontent default from genesys cloud | ||
func readConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig | ||
proxy := getConversationsMessagingSupportedcontentDefaultProxy(sdkConfig) | ||
cc := consistency_checker.NewConsistencyCheck(ctx, d, meta, ResourceConversationsMessagingSupportedcontentDefault(), constants.DefaultConsistencyChecks, resourceName) | ||
|
||
log.Printf("Reading conversations supported content default %s", d.Id()) | ||
|
||
return util.WithRetriesForRead(ctx, d, func() *retry.RetryError { | ||
supportedContentDefault, resp, err := proxy.getConversationsMessagingSupportedcontentDefault(ctx) | ||
if err != nil { | ||
if util.IsStatus404(resp) { | ||
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read conversations supported content default %s: %s", d.Id(), err), resp)) | ||
} | ||
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(resourceName, fmt.Sprintf("Failed to read conversations supported content default %s: %s", d.Id(), err), resp)) | ||
} | ||
|
||
resourcedata.SetNillableValue(d, "content_id", supportedContentDefault.Id) | ||
|
||
log.Printf("Read conversations supported content default %s %s", d.Id(), *supportedContentDefault.Id) | ||
return cc.CheckState(d) | ||
}) | ||
} | ||
|
||
// updateConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to update an conversations messaging supportedcontent default in Genesys Cloud | ||
func updateConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig | ||
proxy := getConversationsMessagingSupportedcontentDefaultProxy(sdkConfig) | ||
supportedContentId := d.Get("content_id").(string) | ||
|
||
conversationsMessagingSupportedcontentDefault := platformclientv2.Supportedcontentreference{ | ||
Id: &supportedContentId, | ||
} | ||
|
||
log.Printf("Updating conversations messaging supportedcontent default %s", supportedContentId) | ||
supportedContentReference, resp, err := proxy.updateConversationsMessagingSupportedcontentDefault(ctx, d.Id(), &conversationsMessagingSupportedcontentDefault) | ||
if err != nil { | ||
return util.BuildAPIDiagnosticError(resourceName, fmt.Sprintf("Failed to update conversations messaging supportedcontent default: %s", err), resp) | ||
} | ||
|
||
log.Printf("Updated conversations messaging supportedcontent default %s", *supportedContentReference.Id) | ||
return readConversationsMessagingSupportedcontentDefault(ctx, d, meta) | ||
} | ||
|
||
// deleteConversationsMessagingSupportedcontentDefault is used by the conversations_messaging_supportedcontent_default resource to delete an conversations messaging supportedcontent default from Genesys cloud | ||
func deleteConversationsMessagingSupportedcontentDefault(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
return nil | ||
} |
46 changes: 46 additions & 0 deletions
46
..._default/resource_genesyscloud_conversations_messaging_supportedcontent_default_schema.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
"terraform-provider-genesyscloud/genesyscloud/provider" | ||
registrar "terraform-provider-genesyscloud/genesyscloud/resource_register" | ||
) | ||
|
||
/* | ||
resource_genesycloud_conversations_messaging_supportedcontent_default_schema.go holds four functions within it: | ||
1. The registration code that registers the Datasource, Resource and Exporter for the package. | ||
2. The resource schema definitions for the conversations_messaging_supportedcontent_default resource. | ||
3. The datasource schema definitions for the conversations_messaging_supportedcontent_default datasource. | ||
4. The resource exporter configuration for the conversations_messaging_supportedcontent_default exporter. | ||
*/ | ||
const resourceName = "genesyscloud_conversations_messaging_supportedcontent_default" | ||
|
||
// SetRegistrar registers all of the resources, datasources and exporters in the package | ||
func SetRegistrar(regInstance registrar.Registrar) { | ||
regInstance.RegisterResource(resourceName, ResourceConversationsMessagingSupportedcontentDefault()) | ||
} | ||
|
||
// ResourceConversationsMessagingSupportedcontentDefault registers the genesyscloud_conversations_messaging_supportedcontent_default resource with Terraform | ||
func ResourceConversationsMessagingSupportedcontentDefault() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: `Genesys Cloud conversations messaging supportedcontent default`, | ||
|
||
CreateContext: provider.CreateWithPooledClient(createConversationsMessagingSupportedcontentDefault), | ||
ReadContext: provider.ReadWithPooledClient(readConversationsMessagingSupportedcontentDefault), | ||
UpdateContext: provider.UpdateWithPooledClient(updateConversationsMessagingSupportedcontentDefault), | ||
DeleteContext: provider.DeleteWithPooledClient(deleteConversationsMessagingSupportedcontentDefault), | ||
Importer: &schema.ResourceImporter{ | ||
StateContext: schema.ImportStatePassthroughContext, | ||
}, | ||
SchemaVersion: 1, | ||
Schema: map[string]*schema.Schema{ | ||
`content_id`: { | ||
Description: `The SupportedContent unique identifier associated with this integration`, | ||
Required: true, | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...nt_default/resource_genesyscloud_conversations_messaging_supportedcontent_default_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package conversations_messaging_supportedcontent_default | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"terraform-provider-genesyscloud/genesyscloud/provider" | ||
"terraform-provider-genesyscloud/genesyscloud/util" | ||
|
||
supportedContent "terraform-provider-genesyscloud/genesyscloud/conversations_messaging_supportedcontent" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
/* | ||
The resource_genesyscloud_conversations_messaging_supportedcontent_default_test.go contains all of the test cases for running the resource | ||
tests for conversations_messaging_supportedcontent_default. | ||
*/ | ||
|
||
func TestAccResourceConversationsMessagingSupportedcontentDefault(t *testing.T) { | ||
t.Parallel() | ||
var ( | ||
defaultResource = "testSupportedDefaultContent" | ||
|
||
name = "Terraform Supported Content - " + uuid.NewString() | ||
resourceId = "testSupportedContent" | ||
inboundType = "*/*" | ||
outboundType = "*/*" | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { util.TestAccPreCheck(t) }, | ||
ProviderFactories: provider.GetProviderFactories(providerResources, nil), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: supportedContent.GenerateSupportedContentResource( | ||
"genesyscloud_conversations_messaging_supportedcontent", | ||
resourceId, | ||
name, | ||
supportedContent.GenerateInboundTypeBlock(inboundType), | ||
supportedContent.GenerateOutboundTypeBlock(outboundType), | ||
), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "name", name), | ||
resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.inbound.0.type", inboundType), | ||
resource.TestCheckResourceAttr("genesyscloud_conversations_messaging_supportedcontent."+resourceId, "media_types.0.allow.0.outbound.0.type", outboundType), | ||
), | ||
}, | ||
{ | ||
Config: supportedContent.GenerateSupportedContentResource( | ||
"genesyscloud_conversations_messaging_supportedcontent", | ||
resourceId, | ||
name, | ||
supportedContent.GenerateInboundTypeBlock(inboundType), | ||
supportedContent.GenerateOutboundTypeBlock(outboundType), | ||
) + | ||
GenerateSupportedContentDefaultResource( | ||
defaultResource, | ||
"genesyscloud_conversations_messaging_supportedcontent."+resourceId+".id", | ||
), | ||
|
||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair("genesyscloud_conversations_messaging_supportedcontent_default."+defaultResource, "content_id", "genesyscloud_conversations_messaging_supportedcontent."+resourceId, "id"), | ||
), | ||
}, | ||
{ | ||
// Import/Read | ||
ResourceName: "genesyscloud_conversations_messaging_supportedcontent_default." + defaultResource, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
CheckDestroy: testVerifyConversationsMessagingSupportedcontentDefaultDestroyed, | ||
}) | ||
} | ||
|
||
func GenerateSupportedContentDefaultResource( | ||
resourceId string, | ||
id string, | ||
) string { | ||
return fmt.Sprintf(` | ||
resource "genesyscloud_conversations_messaging_supportedcontent_default" "%s" { | ||
content_id = %s | ||
} | ||
`, resourceId, id) | ||
} | ||
|
||
func testVerifyConversationsMessagingSupportedcontentDefaultDestroyed(state *terraform.State) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters