@@ -58,6 +58,7 @@ func TestBuilder_NoOptions(t *testing.T) {
58
58
withTemplate ,
59
59
withInactiveVersion (nil ),
60
60
withLastBuildFound ,
61
+ withTemplateVersionVariables (inactiveVersionID , nil ),
61
62
withRichParameters (nil ),
62
63
withParameterSchemas (inactiveJobID , nil ),
63
64
withWorkspaceTags (inactiveVersionID , nil ),
@@ -113,6 +114,7 @@ func TestBuilder_Initiator(t *testing.T) {
113
114
withTemplate ,
114
115
withInactiveVersion (nil ),
115
116
withLastBuildFound ,
117
+ withTemplateVersionVariables (inactiveVersionID , nil ),
116
118
withRichParameters (nil ),
117
119
withParameterSchemas (inactiveJobID , nil ),
118
120
withWorkspaceTags (inactiveVersionID , nil ),
@@ -158,6 +160,7 @@ func TestBuilder_Baggage(t *testing.T) {
158
160
withTemplate ,
159
161
withInactiveVersion (nil ),
160
162
withLastBuildFound ,
163
+ withTemplateVersionVariables (inactiveVersionID , nil ),
161
164
withRichParameters (nil ),
162
165
withParameterSchemas (inactiveJobID , nil ),
163
166
withWorkspaceTags (inactiveVersionID , nil ),
@@ -195,6 +198,7 @@ func TestBuilder_Reason(t *testing.T) {
195
198
withTemplate ,
196
199
withInactiveVersion (nil ),
197
200
withLastBuildFound ,
201
+ withTemplateVersionVariables (inactiveVersionID , nil ),
198
202
withRichParameters (nil ),
199
203
withParameterSchemas (inactiveJobID , nil ),
200
204
withWorkspaceTags (inactiveVersionID , nil ),
@@ -232,6 +236,7 @@ func TestBuilder_ActiveVersion(t *testing.T) {
232
236
withTemplate ,
233
237
withActiveVersion (nil ),
234
238
withLastBuildNotFound ,
239
+ withTemplateVersionVariables (activeVersionID , nil ),
235
240
withParameterSchemas (activeJobID , nil ),
236
241
withWorkspaceTags (activeVersionID , nil ),
237
242
withProvisionerDaemons ([]database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow {}),
@@ -296,6 +301,14 @@ func TestWorkspaceBuildWithTags(t *testing.T) {
296
301
Key : "is_debug_build" ,
297
302
Value : `data.coder_parameter.is_debug_build.value == "true" ? "in-debug-mode" : "no-debug"` ,
298
303
},
304
+ {
305
+ Key : "variable_tag" ,
306
+ Value : `var.tag` ,
307
+ },
308
+ {
309
+ Key : "another_variable_tag" ,
310
+ Value : `var.tag2` ,
311
+ },
299
312
}
300
313
301
314
richParameters := []database.TemplateVersionParameter {
@@ -307,6 +320,11 @@ func TestWorkspaceBuildWithTags(t *testing.T) {
307
320
{Name : "number_of_oranges" , Type : "number" , Description : "This is fifth parameter" , Mutable : false , DefaultValue : "6" , Options : json .RawMessage ("[]" )},
308
321
}
309
322
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
+
310
328
buildParameters := []codersdk.WorkspaceBuildParameter {
311
329
{Name : "project" , Value : "foobar-foobaz" },
312
330
{Name : "is_debug_build" , Value : "true" },
@@ -321,23 +339,26 @@ func TestWorkspaceBuildWithTags(t *testing.T) {
321
339
withTemplate ,
322
340
withInactiveVersion (richParameters ),
323
341
withLastBuildFound ,
342
+ withTemplateVersionVariables (inactiveVersionID , templateVersionVariables ),
324
343
withRichParameters (nil ),
325
344
withParameterSchemas (inactiveJobID , nil ),
326
345
withWorkspaceTags (inactiveVersionID , workspaceTags ),
327
346
withProvisionerDaemons ([]database.GetEligibleProvisionerDaemonsByProvisionerJobIDsRow {}),
328
347
329
348
// Outputs
330
349
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {
331
- asrt .Len (job .Tags , 10 )
350
+ asrt .Len (job .Tags , 12 )
332
351
333
352
expected := database.StringMap {
334
- "actually_no" : "false" ,
335
- "cluster_tag" : "best_developers" ,
336
- "fruits_tag" : "10" ,
337
- "is_debug_build" : "in-debug-mode" ,
338
- "project_tag" : "foobar-foobaz+12345" ,
339
- "team_tag" : "godzilla" ,
340
- "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" ,
341
362
342
363
"scope" : "user" ,
343
364
"version" : "inactive" ,
@@ -413,6 +434,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
413
434
withTemplate ,
414
435
withInactiveVersion (richParameters ),
415
436
withLastBuildFound ,
437
+ withTemplateVersionVariables (inactiveVersionID , nil ),
416
438
withRichParameters (initialBuildParameters ),
417
439
withParameterSchemas (inactiveJobID , nil ),
418
440
withWorkspaceTags (inactiveVersionID , nil ),
@@ -459,6 +481,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
459
481
withTemplate ,
460
482
withInactiveVersion (richParameters ),
461
483
withLastBuildFound ,
484
+ withTemplateVersionVariables (inactiveVersionID , nil ),
462
485
withRichParameters (initialBuildParameters ),
463
486
withParameterSchemas (inactiveJobID , nil ),
464
487
withWorkspaceTags (inactiveVersionID , nil ),
@@ -511,6 +534,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
511
534
withTemplate ,
512
535
withInactiveVersion (richParameters ),
513
536
withLastBuildFound ,
537
+ withTemplateVersionVariables (inactiveVersionID , nil ),
514
538
withRichParameters (nil ),
515
539
withParameterSchemas (inactiveJobID , schemas ),
516
540
withWorkspaceTags (inactiveVersionID , nil ),
@@ -542,6 +566,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
542
566
withTemplate ,
543
567
withInactiveVersion (richParameters ),
544
568
withLastBuildFound ,
569
+ withTemplateVersionVariables (inactiveVersionID , nil ),
545
570
withRichParameters (initialBuildParameters ),
546
571
withParameterSchemas (inactiveJobID , nil ),
547
572
withWorkspaceTags (inactiveVersionID , nil ),
@@ -593,6 +618,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
593
618
withTemplate ,
594
619
withActiveVersion (version2params ),
595
620
withLastBuildFound ,
621
+ withTemplateVersionVariables (activeVersionID , nil ),
596
622
withRichParameters (initialBuildParameters ),
597
623
withParameterSchemas (activeJobID , nil ),
598
624
withWorkspaceTags (activeVersionID , nil ),
@@ -655,6 +681,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
655
681
withTemplate ,
656
682
withActiveVersion (version2params ),
657
683
withLastBuildFound ,
684
+ withTemplateVersionVariables (activeVersionID , nil ),
658
685
withRichParameters (initialBuildParameters ),
659
686
withParameterSchemas (activeJobID , nil ),
660
687
withWorkspaceTags (activeVersionID , nil ),
@@ -715,6 +742,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
715
742
withTemplate ,
716
743
withActiveVersion (version2params ),
717
744
withLastBuildFound ,
745
+ withTemplateVersionVariables (activeVersionID , nil ),
718
746
withRichParameters (initialBuildParameters ),
719
747
withParameterSchemas (activeJobID , nil ),
720
748
withWorkspaceTags (activeVersionID , nil ),
@@ -921,6 +949,18 @@ func withParameterSchemas(jobID uuid.UUID, schemas []database.ParameterSchema) f
921
949
}
922
950
}
923
951
952
+ func withTemplateVersionVariables (versionID uuid.UUID , params []database.TemplateVersionVariable ) func (mTx * dbmock.MockStore ) {
953
+ return func (mTx * dbmock.MockStore ) {
954
+ c := mTx .EXPECT ().GetTemplateVersionVariables (gomock .Any (), versionID ).
955
+ Times (1 )
956
+ if len (params ) > 0 {
957
+ c .Return (params , nil )
958
+ } else {
959
+ c .Return (nil , sql .ErrNoRows )
960
+ }
961
+ }
962
+ }
963
+
924
964
func withRichParameters (params []database.WorkspaceBuildParameter ) func (mTx * dbmock.MockStore ) {
925
965
return func (mTx * dbmock.MockStore ) {
926
966
c := mTx .EXPECT ().GetWorkspaceBuildParameters (gomock .Any (), lastBuildID ).
0 commit comments