Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions preview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,39 @@ func Test_Extract(t *testing.T) {
"numerical": ap().value("5"),
},
},
{
name: "chain-no-inputs",
dir: "chain",
input: preview.Input{
ParameterValues: map[string]string{},
},
expTags: map[string]string{},
unknownTags: []string{},
params: map[string]assertParam{
"git_repo": apWithDiags().errorDiagnostics("Required"),
},
},
{
name: "chain-inputs",
dir: "chain",
input: preview.Input{
ParameterValues: map[string]string{
"git_repo": "coder/coder",
"ide_selector": `["goland"]`,
"cpu_cores": "4",
},
},
expTags: map[string]string{},
unknownTags: []string{},
params: map[string]assertParam{
"git_repo": ap().
value("coder/coder"),
"ide_selector": ap().
value(`["GoLand"]`),
"cpu_cores": ap().valueType(provider.OptionTypeNumber).
value("4"),
},
},
{
name: "conditional-no-inputs",
dir: "conditional",
Expand Down Expand Up @@ -597,6 +630,12 @@ func (a assertParam) noDiagnostics() assertParam {
})
}

func (a assertParam) valueType(exp provider.OptionType) assertParam {
return a.extend(func(t *testing.T, parameter types.Parameter) {
assert.Equal(t, exp, parameter.Type, "parameter value type equality check")
})
}

func (a assertParam) formType(exp provider.ParameterFormType) assertParam {
return a.extend(func(t *testing.T, parameter types.Parameter) {
assert.Equal(t, exp, parameter.FormType, "parameter form type equality check")
Expand Down
95 changes: 95 additions & 0 deletions testdata/chain/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
terraform {
required_providers {
coder = {
source = "coder/coder"
version = "2.5.3"
}
}
}

locals {
ides = [
"VS Code",
"JetBrains IntelliJ",
"GoLand",
"WebStorm",
"PyCharm",
"Databricks",
"Jupyter Notebook",
]

is_ml_repo = data.coder_parameter.git_repo == "coder/mlkit"

selected = try(jsondecode(data.coder_parameter.ide_selector[0].value), [])
}


data "coder_parameter" "git_repo" {
name = "git_repo"
display_name = "Git repo"
description = "Select a git repo to work on."
order = 1
mutable = true
type = "string"
form_type = "dropdown"

option {
# A Go-heavy repository
name = "coder/coder"
value = "coder/coder"
}

option {
# A python-heavy repository
name = "coder/mlkit"
value = "coder/mlkit"
}
}

data "coder_parameter" "ide_selector" {
count = try(data.coder_parameter.git_repo.value, "") != "" ? 1 : 0
name = "ide_selector"
description = "Choose any IDEs for your workspace."
mutable = true
display_name = "Select mutliple IDEs"
order = 1
default = "[]"

# Allows users to select multiple IDEs from the list.
form_type = "multi-select"
type = "list(string)"


dynamic "option" {
for_each = local.ides
content {
name = option.value
value = option.value
}
}
}


data "coder_parameter" "cpu_cores" {
# Only show this parameter if the previous box is selected.
count = length(local.selected) > 0 ? 1 : 0

name = "cpu_cores"
display_name = "CPU Cores"
type = "number"
form_type = "slider"
default = local.is_ml_repo ? 12 : 6
order = 2
validation {
min = 1
max = local.is_ml_repo ? 16 : 8
}
}

output "selected" {
value = local.selected
}

output "static" {
value = "foo"
}
Loading