Skip to content

Commit

Permalink
Fix MapFromSelectOptions: Use correct object type and proper slice in…
Browse files Browse the repository at this point in the history
…itialization
  • Loading branch information
HuyPhanNguyen committed Aug 19, 2024
1 parent 51a1f5d commit 4547720
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
71 changes: 71 additions & 0 deletions octopusdeploy_framework/resource_library_variable_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,77 @@ func TestAccOctopusDeployLibraryVariableSetWithUpdate(t *testing.T) {
})
}

func TestAccOctopusDeployLibraryVariableSetWithVariable(t *testing.T) {
localName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
prefix := "octopusdeploy_library_variable_set." + localName

variableLocalName := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
variablePrefix := "octopusdeploy_variable." + variableLocalName

name := acctest.RandStringFromCharSet(20, acctest.CharSetAlpha)
description := "Test variable set"
variableName := "Test.Variable " + name

resource.Test(t, resource.TestCase{
CheckDestroy: testLibraryVariableSetDestroy,
PreCheck: func() { TestAccPreCheck(t) },
ProtoV6ProviderFactories: ProtoV6ProviderFactories(),
Steps: []resource.TestStep{
{
Config: testLibraryVariableSetWithVariable(localName, variableLocalName, name, description, variableName),
Check: resource.ComposeTestCheckFunc(
testAccCheckOctopusDeployLibraryVariableSetExists(prefix),
resource.TestCheckResourceAttr(prefix, "name", name),
resource.TestCheckResourceAttr(prefix, "description", description),
resource.TestCheckResourceAttr(variablePrefix, "name", variableName),
resource.TestCheckResourceAttr(variablePrefix, "type", "String"),
resource.TestCheckResourceAttr(variablePrefix, "description", "Test variable"),
resource.TestCheckResourceAttr(variablePrefix, "is_sensitive", "false"),
resource.TestCheckResourceAttr(variablePrefix, "is_editable", "true"),
resource.TestCheckResourceAttr(variablePrefix, "value", "True"),
resource.TestCheckResourceAttr(variablePrefix, "prompt.0.description", "test description"),
resource.TestCheckResourceAttr(variablePrefix, "prompt.0.label", "test label"),
resource.TestCheckResourceAttr(variablePrefix, "prompt.0.is_required", "true"),
resource.TestCheckResourceAttr(variablePrefix, "prompt.0.display_settings.0.control_type", "Select"),
resource.TestCheckResourceAttr(variablePrefix, "prompt.0.display_settings.0.select_option.0.display_name", "hi"),
resource.TestCheckResourceAttr(variablePrefix, "prompt.0.display_settings.0.select_option.0.value", "there"),
),
},
},
})
}

func testLibraryVariableSetWithVariable(localName, variableLocalName, name, description, variableName string) string {
return fmt.Sprintf(`
resource "octopusdeploy_library_variable_set" "%s" {
name = "%s"
description = "%s"
}
resource "octopusdeploy_variable" "%s" {
name = "%s"
type = "String"
description = "Test variable"
is_sensitive = false
is_editable = true
owner_id = octopusdeploy_library_variable_set.%s.id
value = "True"
prompt {
description = "test description"
label = "test label"
is_required = true
display_settings {
control_type = "Select"
select_option {
display_name = "hi"
value = "there"
}
}
}
}
`, localName, name, description, variableLocalName, variableName, localName)
}
func testLibraryVariableSetBasic(localName string, name string) string {
return fmt.Sprintf(`resource "octopusdeploy_library_variable_set" "%s" {
name = "%s"
Expand Down
4 changes: 2 additions & 2 deletions octopusdeploy_framework/schemas/variable_prompt_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ func MapFromDisplaySettings(displaySettings *resources.DisplaySettings) attr.Val
}

func MapFromSelectOptions(selectOptions []*resources.SelectOption) []attr.Value {
options := make([]attr.Value, len(selectOptions))
options := make([]attr.Value, 0, len(selectOptions))
for _, option := range selectOptions {
options = append(options, types.ObjectValueMust(
VariableDisplaySettingsObjectType(),
VariableSelectOptionsObjectType(),
map[string]attr.Value{
VariableSchemaAttributeNames.Value: types.StringValue(option.Value),
VariableSchemaAttributeNames.DisplayName: types.StringValue(option.DisplayName),
Expand Down

0 comments on commit 4547720

Please sign in to comment.