Skip to content

Commit 40d3dfe

Browse files
committed
coderd/wsbuilder: improve test coverage of workspace tags
1 parent c6fe518 commit 40d3dfe

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

coderd/wsbuilder/wsbuilder.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,12 @@ func (b *Builder) getProvisionerTags() (map[string]string, error) {
712712
}
713713
varsM := make(map[string]string)
714714
for _, tv := range tvs {
715-
varsM[tv.Name] = tv.Value
715+
// FIXME: do this in Terraform? This is a bit of a hack.
716+
if tv.Value == "" {
717+
varsM[tv.Name] = tv.DefaultValue
718+
} else {
719+
varsM[tv.Name] = tv.Value
720+
}
716721
}
717722
parameterNames, parameterValues, err := b.getParameters()
718723
if err != nil {

coderd/wsbuilder/wsbuilder_test.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,14 @@ func TestWorkspaceBuildWithTags(t *testing.T) {
301301
Key: "is_debug_build",
302302
Value: `data.coder_parameter.is_debug_build.value == "true" ? "in-debug-mode" : "no-debug"`,
303303
},
304+
{
305+
Key: "variable_tag",
306+
Value: `var.tag`,
307+
},
308+
{
309+
Key: "another_variable_tag",
310+
Value: `var.tag2`,
311+
},
304312
}
305313

306314
richParameters := []database.TemplateVersionParameter{
@@ -312,6 +320,11 @@ func TestWorkspaceBuildWithTags(t *testing.T) {
312320
{Name: "number_of_oranges", Type: "number", Description: "This is fifth parameter", Mutable: false, DefaultValue: "6", Options: json.RawMessage("[]")},
313321
}
314322

323+
templateVersionVariables := []database.TemplateVersionVariable{
324+
{Name: "tag", Description: "This is a variable tag", TemplateVersionID: inactiveVersionID, Type: "string", DefaultValue: "default-value", Value: "my-value"},
325+
{Name: "tag2", Description: "This is another variable tag", TemplateVersionID: inactiveVersionID, Type: "string", DefaultValue: "default-value-2", Value: ""},
326+
}
327+
315328
buildParameters := []codersdk.WorkspaceBuildParameter{
316329
{Name: "project", Value: "foobar-foobaz"},
317330
{Name: "is_debug_build", Value: "true"},
@@ -326,24 +339,26 @@ func TestWorkspaceBuildWithTags(t *testing.T) {
326339
withTemplate,
327340
withInactiveVersion(richParameters),
328341
withLastBuildFound,
329-
withTemplateVersionVariables(inactiveVersionID, nil),
342+
withTemplateVersionVariables(inactiveVersionID, templateVersionVariables),
330343
withRichParameters(nil),
331344
withParameterSchemas(inactiveJobID, nil),
332345
withWorkspaceTags(inactiveVersionID, workspaceTags),
333346
withProvisionerDaemons([]database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow{}),
334347

335348
// Outputs
336349
expectProvisionerJob(func(job database.InsertProvisionerJobParams) {
337-
asrt.Len(job.Tags, 10)
350+
asrt.Len(job.Tags, 12)
338351

339352
expected := database.StringMap{
340-
"actually_no": "false",
341-
"cluster_tag": "best_developers",
342-
"fruits_tag": "10",
343-
"is_debug_build": "in-debug-mode",
344-
"project_tag": "foobar-foobaz+12345",
345-
"team_tag": "godzilla",
346-
"yes_or_no": "true",
353+
"actually_no": "false",
354+
"cluster_tag": "best_developers",
355+
"fruits_tag": "10",
356+
"is_debug_build": "in-debug-mode",
357+
"project_tag": "foobar-foobaz+12345",
358+
"team_tag": "godzilla",
359+
"yes_or_no": "true",
360+
"variable_tag": "my-value",
361+
"another_variable_tag": "default-value-2",
347362

348363
"scope": "user",
349364
"version": "inactive",

0 commit comments

Comments
 (0)