diff --git a/genesyscloud/supported_content/data_source_genesyscloud_supported_content_test.go b/genesyscloud/supported_content/data_source_genesyscloud_supported_content_test.go index 73a479e7a..dc9212cef 100644 --- a/genesyscloud/supported_content/data_source_genesyscloud_supported_content_test.go +++ b/genesyscloud/supported_content/data_source_genesyscloud_supported_content_test.go @@ -1,11 +1,13 @@ package supported_content import ( + "fmt" "testing" "terraform-provider-genesyscloud/genesyscloud/provider" "terraform-provider-genesyscloud/genesyscloud/util" + "github.com/google/uuid" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" ) @@ -15,10 +17,48 @@ Test Class for the supported content Data Source func TestAccDataSourceSupportedContent(t *testing.T) { t.Parallel() - var () + var ( + resourceId = "testSupportedContent" + dataSourceId = "testSupportedContent_data" + name = "Terraform Supported Content - " + uuid.NewString() + inboundType = "*/*" + outboundType = "image/*" + ) + resource.Test(t, resource.TestCase{ PreCheck: func() { util.TestAccPreCheck(t) }, ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources), - Steps: []resource.TestStep{}, + Steps: []resource.TestStep{ + { + Config: GenerateSupportedContentResource( + resourceId, + name, + GenerateInboundTypeBlock(inboundType), + GenerateOutboundTypeBlock(outboundType), + ) + + GenerateDataSourceForSupportedContent( + dataSourceId, + name, + "genesyscloud_supported_content."+resourceId), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "name", name), + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "media_types.0.allow.0.inbound.0.type", inboundType), + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "media_types.0.allow.0.outbound.0.type", outboundType), + ), + }, + }, }) } + +func GenerateDataSourceForSupportedContent( + resourceId string, + name string, + dependsOn string, +) string { + return fmt.Sprintf(` + data "genesyscloud_supported_content" "%s" { + name = "%s" + depends_on = [%s] + } + `, resourceId, name, dependsOn) +} diff --git a/genesyscloud/supported_content/resource_genesyscloud_supported_content_test.go b/genesyscloud/supported_content/resource_genesyscloud_supported_content_test.go index 35332449e..0024c4ffe 100644 --- a/genesyscloud/supported_content/resource_genesyscloud_supported_content_test.go +++ b/genesyscloud/supported_content/resource_genesyscloud_supported_content_test.go @@ -2,6 +2,7 @@ package supported_content import ( "fmt" + "strings" "testing" "github.com/google/uuid" @@ -24,8 +25,10 @@ func TestAccResourceSupportedContent(t *testing.T) { var ( resourceId = "testSupportedContent" name = "Terraform Supported Content - " + uuid.NewString() - inboundType = "'*/*" - outboundType = "'*/*" + inboundType = "*/*" + outboundType = "*/*" + inboundType2 = "image/*" + inboundType3 = "video/mpeg" ) resource.Test(t, resource.TestCase{ @@ -45,6 +48,22 @@ func TestAccResourceSupportedContent(t *testing.T) { resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "media_types.0.allow.0.outbound.0.type", outboundType), ), }, + //Update and add inbound block + { + Config: GenerateSupportedContentResource( + resourceId, + name, + GenerateInboundTypeBlock(inboundType2), + GenerateInboundTypeBlock(inboundType3), + GenerateOutboundTypeBlock(outboundType), + ), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "name", name), + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "media_types.0.allow.0.inbound.0.type", inboundType2), + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "media_types.0.allow.0.inbound.1.type", inboundType3), + resource.TestCheckResourceAttr("genesyscloud_supported_content."+resourceId, "media_types.0.allow.0.outbound.0.type", outboundType), + ), + }, { // Import/Read ResourceName: "genesyscloud_supported_content." + resourceId, @@ -59,18 +78,16 @@ func TestAccResourceSupportedContent(t *testing.T) { func GenerateSupportedContentResource( resourceId string, name string, - inboundType string, - outboundType string, + nestedBlocks ...string, ) string { return fmt.Sprintf(`resource "genesyscloud_supported_content" "%s" { name = "%s" media_types { allow { %s - %s } } - } `, resourceId, name, inboundType, outboundType) + } `, resourceId, name, strings.Join(nestedBlocks, "\n")) } func GenerateInboundTypeBlock(