Skip to content

Commit 67da56a

Browse files
committed
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.
1 parent 7d69e96 commit 67da56a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

cli/create_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,8 @@ func TestCreateWithRichParameters(t *testing.T) {
384384
inputParameters []param
385385
// expectedParameters defaults to inputParameters.
386386
expectedParameters []param
387+
// withDefaults sets DefaultValue to each parameter's value.
388+
withDefaults bool
387389
}{
388390
{
389391
name: "ValuesFromPrompt",
@@ -528,6 +530,21 @@ func TestCreateWithRichParameters(t *testing.T) {
528530
return "other-workspace"
529531
},
530532
},
533+
{
534+
name: "ValuesFromTemplateDefaults",
535+
handlePty: func(pty *ptytest.PTY) {
536+
// Simply accept the defaults.
537+
for _, param := range params {
538+
pty.ExpectMatch(param.name)
539+
pty.ExpectMatch(`Enter a value (default: "` + param.value + `")`)
540+
pty.WriteLine("")
541+
}
542+
// Confirm the creation.
543+
pty.ExpectMatch("Confirm create?")
544+
pty.WriteLine("yes")
545+
},
546+
withDefaults: true,
547+
},
531548
}
532549

533550
for _, tt := range tests {
@@ -542,11 +559,16 @@ func TestCreateWithRichParameters(t *testing.T) {
542559
// Convert parameters for the echo provisioner response.
543560
var rparams []*proto.RichParameter
544561
for i, param := range parameters {
562+
defaultValue := ""
563+
if tt.withDefaults {
564+
defaultValue = param.value
565+
}
545566
rparams = append(rparams, &proto.RichParameter{
546-
Name: param.name,
547-
Type: param.ptype,
548-
Mutable: param.mutable,
549-
Order: int32(i), //nolint:gosec
567+
Name: param.name,
568+
Type: param.ptype,
569+
Mutable: param.mutable,
570+
DefaultValue: defaultValue,
571+
Order: int32(i), //nolint:gosec
550572
})
551573
}
552574

provisioner/echo/serve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ data "coder_parameter" "{{ .Name }}" {
465465
ephemeral = {{ .Ephemeral }}
466466
order = {{ .Order }}
467467
{{- if .DefaultValue }}
468-
default = {{ .DefaultValue }}
468+
default = "{{ .DefaultValue }}"
469469
{{- end }}
470470
{{- if .Type }}
471471
type = "{{ .Type }}"

0 commit comments

Comments
 (0)