Skip to content

Commit

Permalink
[Entity] Handle undefined array type as string (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tankilevitch authored Jun 20, 2024
1 parent 30dc7bc commit 8b4f177
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
4 changes: 2 additions & 2 deletions port/entity/refreshEntityToState.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func refreshArrayEntityState(ctx context.Context, state *EntityModel, arrayPrope
for k, t := range arrayProperties {

switch blueprint.Schema.Properties[k].Items["type"] {
case "string":
// array without items type is array of string by default
case "string", nil:
if t != nil {
for _, item := range t {
stringItem := item.(string)
Expand Down Expand Up @@ -80,7 +81,6 @@ func refreshArrayEntityState(ctx context.Context, state *EntityModel, arrayPrope
mapObjectItems[k] = nil
}
state.Properties.ArrayProps.ObjectItems, _ = types.MapValueFrom(ctx, types.ListType{ElemType: types.StringType}, mapObjectItems)

}
}
}
Expand Down
55 changes: 55 additions & 0 deletions port/entity/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -769,5 +769,60 @@ func TestAccPortEntityUpdateBlueprintIdentifier(t *testing.T) {
},
},
})
}

func TestAccPortEntityWithDefaultArrayProp(t *testing.T) {
identifier := utils.GenID()
entityIdentifier := utils.GenID()
var testAccActionConfigCreate = fmt.Sprintf(`
resource "port_blueprint" "microservice" {
title = "TF Provider Test BP0"
icon = "Terraform"
identifier = "%s"
properties = {
"array_props" = {
"myArrayIdentifier" = {
"title" = "My Array Identifier"
}
}
}
}
resource "port_entity" "microservice" {
title = "TF Provider Test Entity0"
blueprint = port_blueprint.microservice.identifier
identifier = "%s"
properties = {
array_props = {
string_items = {
"myArrayIdentifier" = ["My Array Value", "My Array Value2"]
}
}
}
}`, identifier, entityIdentifier)

resource.Test(t, resource.TestCase{
PreCheck: func() { acctest.TestAccPreCheck(t) },
ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories,

Steps: []resource.TestStep{
{
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_entity.microservice", "title", "TF Provider Test Entity0"),
resource.TestCheckResourceAttr("port_entity.microservice", "blueprint", identifier),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.0", "My Array Value"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.1", "My Array Value2"),
),
},
{
Config: acctest.ProviderConfig + testAccActionConfigCreate,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("port_entity.microservice", "title", "TF Provider Test Entity0"),
resource.TestCheckResourceAttr("port_entity.microservice", "blueprint", identifier),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.0", "My Array Value"),
resource.TestCheckResourceAttr("port_entity.microservice", "properties.array_props.string_items.myArrayIdentifier.1", "My Array Value2"),
),
},
},
})
}

0 comments on commit 8b4f177

Please sign in to comment.