Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add test for accepting template defaults
This works already in production, but not in the tests because the
generated Terraform was missing quotes around the default value, which
must have been breaking the parser because it was returning no
parameters.  Then we were removing all non-matching parameters from the
request, which was all of them since the parser returned none.
  • Loading branch information
code-asher committed Dec 5, 2025
commit 91d2269d07e1abecf50ef90db5fdc47a1285329d
30 changes: 26 additions & 4 deletions cli/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,8 @@ func TestCreateWithRichParameters(t *testing.T) {
inputParameters []param
// expectedParameters defaults to inputParameters.
expectedParameters []param
// withDefaults sets DefaultValue to each parameter's value.
withDefaults bool
}{
{
name: "ValuesFromPrompt",
Expand Down Expand Up @@ -528,6 +530,21 @@ func TestCreateWithRichParameters(t *testing.T) {
return "other-workspace"
},
},
{
name: "ValuesFromTemplateDefaults",
handlePty: func(pty *ptytest.PTY) {
// Simply accept the defaults.
for _, param := range params {
pty.ExpectMatch(param.name)
pty.ExpectMatch(`Enter a value (default: "` + param.value + `")`)
pty.WriteLine("")
}
// Confirm the creation.
pty.ExpectMatch("Confirm create?")
pty.WriteLine("yes")
},
withDefaults: true,
},
}

for _, tt := range tests {
Expand All @@ -542,11 +559,16 @@ func TestCreateWithRichParameters(t *testing.T) {
// Convert parameters for the echo provisioner response.
var rparams []*proto.RichParameter
for i, param := range parameters {
defaultValue := ""
if tt.withDefaults {
defaultValue = param.value
}
rparams = append(rparams, &proto.RichParameter{
Name: param.name,
Type: param.ptype,
Mutable: param.mutable,
Order: int32(i), //nolint:gosec
Name: param.name,
Type: param.ptype,
Mutable: param.mutable,
DefaultValue: defaultValue,
Order: int32(i), //nolint:gosec
})
}

Expand Down
8 changes: 8 additions & 0 deletions provisioner/echo/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,15 @@ data "coder_parameter" "{{ .Name }}" {
ephemeral = {{ .Ephemeral }}
order = {{ .Order }}
{{- if .DefaultValue }}
{{- if eq .Type "list(string)" }}
default = jsonencode({{ .DefaultValue }})
{{else if eq .Type "bool"}}
default = {{ .DefaultValue }}
{{else if eq .Type "number"}}
default = {{ .DefaultValue }}
{{else}}
default = "{{ .DefaultValue }}"
{{- end }}
{{- end }}
{{- if .Type }}
type = "{{ .Type }}"
Expand Down