Skip to content

Commit

Permalink
change description plan logic
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickcping committed May 31, 2024
1 parent 627c51b commit c2bf0bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion internal/acctest/flows/full-minimal.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"currentVersion": 4,
"customerId": "db5f4450b2bd8a56ce076dec0c358a9a",
"deployedDate": 1707837221226,
"description": "Imported on Wed Jan 31 2024 13:29:13 GMT+0000 (Coordinated Universal Time)",
"description": "This is a fallback description",
"flowStatus": "enabled",
"isOutputSchemaSaved": false,
"name": "simple",
Expand Down
18 changes: 12 additions & 6 deletions internal/service/davinci/resource_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,14 @@ func (p *FlowResourceModel) expand(ctx context.Context) (*davinci.FlowImport, di
return nil, diags
}

if data.Name == nil {
data.Name = &data.FlowInfo.Name
}

if data.Description == nil && data.FlowInfo.Description != nil {
data.Description = data.FlowInfo.Description
}

data.FlowNameMapping = map[string]string{
data.FlowInfo.FlowID: p.Name.ValueString(),
}
Expand Down Expand Up @@ -1038,13 +1046,11 @@ func (p *FlowResourceModel) expandUpdate(state FlowResourceModel) (*davinci.Flow
}

if !p.Name.IsNull() {
name := p.Name.ValueString()
data.Name = &name
data.Name = p.Name.ValueStringPointer()
}

if !p.Description.IsNull() {
description := p.Description.ValueString()
data.Description = &description
data.Description = p.Description.ValueStringPointer()
}

err = davinci.Unmarshal([]byte(state.FlowConfigurationJSON.ValueString()), &stateData, davinci.ExportCmpOpts{})
Expand Down Expand Up @@ -1113,8 +1119,8 @@ func (p *FlowResourceModel) toState(apiObject *davinci.Flow) diag.Diagnostics {

p.Name = framework.StringToTF(apiObject.Name)

if apiObject.Description != nil {
p.Description = framework.StringToTF(*apiObject.Description)
if v := apiObject.Description; v != nil {
p.Description = framework.StringToTF(*v)
}

var d diag.Diagnostics
Expand Down
23 changes: 4 additions & 19 deletions internal/service/davinci/resource_flow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,7 @@ func testAccResourceFlow_Basic(t *testing.T, withBootstrapConfig bool) {
resource.TestMatchResourceAttr(resourceFullName, "id", verify.P1DVResourceIDRegexpFullString),
resource.TestMatchResourceAttr(resourceFullName, "environment_id", verify.P1ResourceIDRegexpFullString),
resource.TestCheckResourceAttr(resourceFullName, "name", "simple"),
resource.TestMatchResourceAttr(resourceFullName, "description", regexp.MustCompile(`^Imported on `)),
resource.TestCheckResourceAttr(resourceFullName, "flow_json", fmt.Sprintf("%s\n", minimalStepJson)),
resource.TestCheckResourceAttr(resourceFullName, "connection_link.#", "1"),
resource.TestCheckResourceAttr(resourceFullName, "deploy", "true"),
resource.TestCheckResourceAttr(resourceFullName, "subflow_link.#", "0"),
resource.TestCheckResourceAttr(resourceFullName, "flow_variables.#", "0"),
),
}

updateStep := resource.TestStep{
Config: minimalStepHcl,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(resourceFullName, "id", verify.P1DVResourceIDRegexpFullString),
resource.TestMatchResourceAttr(resourceFullName, "environment_id", verify.P1ResourceIDRegexpFullString),
resource.TestCheckResourceAttr(resourceFullName, "name", "simple"),
resource.TestMatchResourceAttr(resourceFullName, "description", regexp.MustCompile(`^$`)),
resource.TestCheckResourceAttr(resourceFullName, "description", "This is a fallback description"),
resource.TestCheckResourceAttr(resourceFullName, "flow_json", fmt.Sprintf("%s\n", minimalStepJson)),
resource.TestCheckResourceAttr(resourceFullName, "connection_link.#", "1"),
resource.TestCheckResourceAttr(resourceFullName, "deploy", "true"),
Expand All @@ -184,21 +169,21 @@ func testAccResourceFlow_Basic(t *testing.T, withBootstrapConfig bool) {
ErrorCheck: acctest.ErrorCheck(t),
CheckDestroy: davinci.Flow_CheckDestroy(),
Steps: []resource.TestStep{
// Create from scratch
// Create full from scratch
fullStep,
{
Config: fullStepHcl,
Destroy: true,
},
// Create from scratch
// Create minimal from scratch
minimalStep,
{
Config: minimalStepHcl,
Destroy: true,
},
// Test updates
fullStep,
updateStep,
minimalStep,
fullStep,
// Test importing the resource
{
Expand Down

0 comments on commit c2bf0bf

Please sign in to comment.