-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
59665bb
commit 696c9cc
Showing
9 changed files
with
367 additions
and
104 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
...oud/knowledge_document_variation/data_source_genesyscloud_knowledge_document_variation.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,38 @@ | ||
package knowledgedocumentvariation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"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" | ||
"strings" | ||
"terraform-provider-genesyscloud/genesyscloud/provider" | ||
"terraform-provider-genesyscloud/genesyscloud/util" | ||
"time" | ||
) | ||
|
||
func dataSourceKnowledgeDocumentVariationRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
sdkConfig := meta.(*provider.ProviderMeta).ClientConfig | ||
proxy := newVariationRequestProxy(sdkConfig) | ||
|
||
name := d.Get("name").(string) | ||
knowledgeBaseID := d.Get("knowledge_base_id").(string) | ||
fullID := d.Get("knowledge_document_id").(string) | ||
knowledgeDocumentId := strings.Split(fullID, ",")[0] | ||
|
||
return util.WithRetries(ctx, 15*time.Second, func() *retry.RetryError { | ||
documentVariationRequestId, resp, retryable, err := proxy.getVariationRequestIdByName(ctx, name, knowledgeBaseID, knowledgeDocumentId) | ||
|
||
if err != nil && !retryable { | ||
return retry.NonRetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("Error searching variation request %s | error: %s", name, err), resp)) | ||
} | ||
|
||
if retryable { | ||
return retry.RetryableError(util.BuildWithRetriesApiDiagnosticError(ResourceType, fmt.Sprintf("No variation request found with name %s", name), resp)) | ||
} | ||
|
||
d.SetId(documentVariationRequestId) | ||
return nil | ||
}) | ||
} |
151 changes: 151 additions & 0 deletions
151
...nowledge_document_variation/data_source_genesyscloud_knowledge_document_variation_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,151 @@ | ||
package knowledgedocumentvariation | ||
|
||
import ( | ||
"fmt" | ||
"github.com/google/uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"github.com/stretchr/testify/assert" | ||
"strings" | ||
gcloud "terraform-provider-genesyscloud/genesyscloud" | ||
"terraform-provider-genesyscloud/genesyscloud/provider" | ||
"terraform-provider-genesyscloud/genesyscloud/util" | ||
"testing" | ||
) | ||
|
||
func TestAccDataSourceVariationRequest(t *testing.T) { | ||
var ( | ||
// Knowledge Base | ||
knowledgeBaseResourceLabel1 = "test-knowledgebase1" | ||
knowledgeBaseName1 = uuid.NewString() | ||
knowledgeBaseDescription1 = "test-knowledgebase-description1" | ||
coreLanguage1 = "en-US" | ||
|
||
// Knowledge Document | ||
knowledgeDocumentResourceLabel1 = "test-knowledge-document1" | ||
title = "Terraform Knowledge Document" | ||
visible = true | ||
docPublished = false | ||
phrase = "Terraform Knowledge Document" | ||
autocomplete = true | ||
|
||
// Knowledge Document Variation | ||
variationResourceLabel = "test-variation" | ||
published = true | ||
bodyBlockType = "Paragraph" | ||
contentBlockType1 = "Text" | ||
imageUrl = "https://example.com/image" | ||
hyperlink = "https://example.com/hyperlink" | ||
videoUrl = "https://example.com/video" | ||
listType = "ListItem" | ||
documentText = "stuff" | ||
marks = []string{"Bold", "Italic", "Underline"} | ||
name = "Terraform Test Knowledge Document Variation" | ||
contextId = uuid.NewString() | ||
valueId = uuid.NewString() | ||
paragraphTestProperties = map[string]string{ | ||
"fSize": "Large", | ||
"fType": "Heading1", | ||
"tColor": "#FFFFFF", | ||
"bgColor": "#000000", | ||
"align": "Right", | ||
"indent": "3.14", | ||
} | ||
) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { util.TestAccPreCheck(t) }, | ||
ProviderFactories: provider.GetProviderFactories(providerResources, providerDataSources), | ||
Steps: []resource.TestStep{ | ||
{ | ||
// Create Type List | ||
Config: gcloud.GenerateKnowledgeKnowledgebaseResource( | ||
knowledgeBaseResourceLabel1, | ||
knowledgeBaseName1, | ||
knowledgeBaseDescription1, | ||
coreLanguage1, | ||
) + | ||
generateKnowledgeDocumentBasic( | ||
knowledgeDocumentResourceLabel1, | ||
knowledgeBaseResourceLabel1, | ||
title, | ||
visible, | ||
docPublished, | ||
phrase, | ||
autocomplete, | ||
) + generateKnowledgeDocumentVariation( | ||
variationResourceLabel, | ||
knowledgeBaseResourceLabel1, | ||
knowledgeDocumentResourceLabel1, | ||
published, | ||
bodyBlockType, | ||
contentBlockType1, | ||
imageUrl, | ||
hyperlink, | ||
videoUrl, | ||
listType, | ||
documentText, | ||
marks, | ||
name, | ||
contextId, | ||
valueId, | ||
paragraphTestProperties, | ||
) + generateKnowledgeDocumentVariationDataSource( | ||
variationResourceLabel, | ||
name, | ||
knowledgeBaseResourceLabel1, | ||
knowledgeDocumentResourceLabel1, | ||
), | ||
Check: resource.ComposeTestCheckFunc( | ||
// As the ID is a concatenation of multiple IDs, this function will be used to test the ids | ||
func(state *terraform.State) error { | ||
|
||
// Get the Resource ID | ||
rs, ok := state.RootModule().Resources[ResourceType+"."+variationResourceLabel] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", ResourceType+"."+variationResourceLabel) | ||
} | ||
id := rs.Primary.ID | ||
|
||
// Split the IDs | ||
resourceIDs, err := parseResourceIDs(id) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Get the Data Source ID | ||
rs2, ok := state.RootModule().Resources["data."+ResourceType+"."+variationResourceLabel] | ||
if !ok { | ||
return fmt.Errorf("not found: %s", ResourceType+"."+variationResourceLabel) | ||
} | ||
|
||
variationID := rs2.Primary.ID | ||
knowledgeBaseID := rs2.Primary.Attributes["knowledge_base_id"] | ||
KnowledgeDocumentID := strings.Split(rs2.Primary.Attributes["knowledge_document_id"], ",")[0] | ||
|
||
// Ensure IDs are equal | ||
assert.Equal(t, resourceIDs.variationID, variationID, "Variation ID should be equal") | ||
assert.Equal(t, resourceIDs.knowledgeBaseID, knowledgeBaseID, "Knowledge Base ID should be equal") | ||
assert.Equal(t, resourceIDs.knowledgeDocumentID, KnowledgeDocumentID, "Knowledge Document ID should be equal") | ||
return nil | ||
}, | ||
), | ||
}, | ||
{ | ||
// Import/Read | ||
ResourceName: ResourceType + "." + variationResourceLabel, | ||
ImportState: true, | ||
ImportStateVerify: true, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func generateKnowledgeDocumentVariationDataSource(resourceLabel, variationName, knowledgeBaseID, knowledgeDocumentID string) string { | ||
return fmt.Sprintf(`data "genesyscloud_knowledge_document_variation" "%s" { | ||
knowledge_base_id = genesyscloud_knowledge_knowledgebase.%s.id | ||
knowledge_document_id = genesyscloud_knowledge_document.%s.id | ||
name = "%s" | ||
} | ||
`, resourceLabel, knowledgeBaseID, knowledgeDocumentID, variationName) | ||
} |
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
Oops, something went wrong.