Skip to content

Commit

Permalink
updated resource testcase and added datasource testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutisuryawanshigenesys committed Jul 16, 2024
1 parent 7e63b40 commit c384a7f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package supported_content

import (
"fmt"
"strings"
"testing"

"github.com/google/uuid"
Expand All @@ -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{
Expand All @@ -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,
Expand All @@ -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(
Expand Down

0 comments on commit c384a7f

Please sign in to comment.