@@ -23,19 +23,21 @@ import (
23
23
24
24
var (
25
25
// use fixed IDs so logs are easier to read
26
- templateID = uuid .MustParse ("12341234-0000-0000-0001-000000000000" )
27
- activeVersionID = uuid .MustParse ("12341234-0000-0000-0002-000000000000" )
28
- inactiveVersionID = uuid .MustParse ("12341234-0000-0000-0003-000000000000" )
29
- activeJobID = uuid .MustParse ("12341234-0000-0000-0004-000000000000" )
30
- inactiveJobID = uuid .MustParse ("12341234-0000-0000-0005-000000000000" )
31
- orgID = uuid .MustParse ("12341234-0000-0000-0006-000000000000" )
32
- workspaceID = uuid .MustParse ("12341234-0000-0000-0007-000000000000" )
33
- userID = uuid .MustParse ("12341234-0000-0000-0008-000000000000" )
34
- activeFileID = uuid .MustParse ("12341234-0000-0000-0009-000000000000" )
35
- inactiveFileID = uuid .MustParse ("12341234-0000-0000-000a-000000000000" )
36
- lastBuildID = uuid .MustParse ("12341234-0000-0000-000b-000000000000" )
37
- lastBuildJobID = uuid .MustParse ("12341234-0000-0000-000c-000000000000" )
38
- otherUserID = uuid .MustParse ("12341234-0000-0000-000d-000000000000" )
26
+ templateID = uuid .MustParse ("12341234-0000-0000-0001-000000000000" )
27
+ activeVersionID = uuid .MustParse ("12341234-0000-0000-0002-000000000000" )
28
+ inactiveVersionID = uuid .MustParse ("12341234-0000-0000-0003-000000000000" )
29
+ activeJobID = uuid .MustParse ("12341234-0000-0000-0004-000000000000" )
30
+ inactiveJobID = uuid .MustParse ("12341234-0000-0000-0005-000000000000" )
31
+ orgID = uuid .MustParse ("12341234-0000-0000-0006-000000000000" )
32
+ workspaceID = uuid .MustParse ("12341234-0000-0000-0007-000000000000" )
33
+ userID = uuid .MustParse ("12341234-0000-0000-0008-000000000000" )
34
+ activeFileID = uuid .MustParse ("12341234-0000-0000-0009-000000000000" )
35
+ inactiveFileID = uuid .MustParse ("12341234-0000-0000-000a-000000000000" )
36
+ lastBuildID = uuid .MustParse ("12341234-0000-0000-000b-000000000000" )
37
+ lastBuildJobID = uuid .MustParse ("12341234-0000-0000-000c-000000000000" )
38
+ otherUserID = uuid .MustParse ("12341234-0000-0000-000d-000000000000" )
39
+ notReplacedParamID = uuid .MustParse ("12341234-0000-0000-000e-000000000000" )
40
+ replacedParamID = uuid .MustParse ("12341234-0000-0000-000f-000000000000" )
39
41
)
40
42
41
43
func TestBuilder_NoOptions (t * testing.T ) {
@@ -53,7 +55,7 @@ func TestBuilder_NoOptions(t *testing.T) {
53
55
withTemplate ,
54
56
withInactiveVersion (nil ),
55
57
withLastBuildFound ,
56
- withRichParameters (nil ),
58
+ withRichParameters (nil ), withLegacyParameters ( nil ),
57
59
58
60
// Outputs
59
61
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {
@@ -101,7 +103,7 @@ func TestBuilder_Initiator(t *testing.T) {
101
103
withTemplate ,
102
104
withInactiveVersion (nil ),
103
105
withLastBuildFound ,
104
- withRichParameters (nil ),
106
+ withRichParameters (nil ), withLegacyParameters ( nil ),
105
107
106
108
// Outputs
107
109
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {
@@ -133,7 +135,7 @@ func TestBuilder_Reason(t *testing.T) {
133
135
withTemplate ,
134
136
withInactiveVersion (nil ),
135
137
withLastBuildFound ,
136
- withRichParameters (nil ),
138
+ withRichParameters (nil ), withLegacyParameters ( nil ),
137
139
138
140
// Outputs
139
141
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {
@@ -164,6 +166,7 @@ func TestBuilder_ActiveVersion(t *testing.T) {
164
166
withTemplate ,
165
167
withActiveVersion (nil ),
166
168
withLastBuildNotFound ,
169
+ withLegacyParameters (nil ),
167
170
// previous rich parameters are not queried because there is no previous build.
168
171
169
172
// Outputs
@@ -240,7 +243,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
240
243
withTemplate ,
241
244
withInactiveVersion (richParameters ),
242
245
withLastBuildFound ,
243
- withRichParameters (initialBuildParameters ),
246
+ withRichParameters (initialBuildParameters ), withLegacyParameters ( nil ),
244
247
245
248
// Outputs
246
249
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
@@ -280,7 +283,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
280
283
withTemplate ,
281
284
withInactiveVersion (richParameters ),
282
285
withLastBuildFound ,
283
- withRichParameters (initialBuildParameters ),
286
+ withRichParameters (initialBuildParameters ), withLegacyParameters ( nil ),
284
287
285
288
// Outputs
286
289
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
@@ -301,6 +304,40 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
301
304
req .NoError (err )
302
305
})
303
306
307
+ t .Run ("StartWorkspaceWithLegacyParameterValues" , func (t * testing.T ) {
308
+ t .Parallel ()
309
+
310
+ req := require .New (t )
311
+ asrt := assert .New (t )
312
+
313
+ ctx , cancel := context .WithCancel (context .Background ())
314
+ defer cancel ()
315
+
316
+ oldParams := []database.ParameterValue {
317
+ {Name : "not-replaced" , SourceValue : "nr" , ID : notReplacedParamID },
318
+ {Name : "replaced" , SourceValue : "r" , ID : replacedParamID },
319
+ }
320
+
321
+ mDB := expectDB (t ,
322
+ // Inputs
323
+ withTemplate ,
324
+ withInactiveVersion (richParameters ),
325
+ withLastBuildFound ,
326
+ withRichParameters (nil ), withLegacyParameters (oldParams ),
327
+
328
+ // Outputs
329
+ expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
330
+ expectBuild (func (bld database.InsertWorkspaceBuildParams ) {}),
331
+ )
332
+
333
+ ws := database.Workspace {ID : workspaceID , TemplateID : templateID , OwnerID : userID }
334
+ uut := wsbuilder .New (ws , database .WorkspaceTransitionStart )
335
+ _ , _ , err := uut .Build (ctx , mDB , nil )
336
+ bldErr := wsbuilder.BuildError {}
337
+ req .ErrorAs (err , & bldErr )
338
+ asrt .Equal (http .StatusBadRequest , bldErr .Status )
339
+ })
340
+
304
341
t .Run ("DoNotModifyImmutables" , func (t * testing.T ) {
305
342
t .Parallel ()
306
343
@@ -319,7 +356,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
319
356
withTemplate ,
320
357
withInactiveVersion (richParameters ),
321
358
withLastBuildFound ,
322
- withRichParameters (initialBuildParameters ),
359
+ withRichParameters (initialBuildParameters ), withLegacyParameters ( nil ),
323
360
324
361
// Outputs
325
362
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
@@ -370,7 +407,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
370
407
withTemplate ,
371
408
withActiveVersion (version2params ),
372
409
withLastBuildFound ,
373
- withRichParameters (initialBuildParameters ),
410
+ withRichParameters (initialBuildParameters ), withLegacyParameters ( nil ),
374
411
375
412
// Outputs
376
413
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
@@ -427,7 +464,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
427
464
withTemplate ,
428
465
withActiveVersion (version2params ),
429
466
withLastBuildFound ,
430
- withRichParameters (initialBuildParameters ),
467
+ withRichParameters (initialBuildParameters ), withLegacyParameters ( nil ),
431
468
432
469
// Outputs
433
470
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
@@ -482,7 +519,7 @@ func TestWorkspaceBuildWithRichParameters(t *testing.T) {
482
519
withTemplate ,
483
520
withActiveVersion (version2params ),
484
521
withLastBuildFound ,
485
- withRichParameters (initialBuildParameters ),
522
+ withRichParameters (initialBuildParameters ), withLegacyParameters ( nil ),
486
523
487
524
// Outputs
488
525
expectProvisionerJob (func (job database.InsertProvisionerJobParams ) {}),
@@ -659,6 +696,23 @@ func withLastBuildNotFound(mTx *dbmock.MockStore) {
659
696
Return (database.WorkspaceBuild {}, sql .ErrNoRows )
660
697
}
661
698
699
+ func withLegacyParameters (params []database.ParameterValue ) func (mTx * dbmock.MockStore ) {
700
+ return func (mTx * dbmock.MockStore ) {
701
+ c := mTx .EXPECT ().ParameterValues (
702
+ gomock .Any (),
703
+ database.ParameterValuesParams {
704
+ Scopes : []database.ParameterScope {database .ParameterScopeWorkspace },
705
+ ScopeIds : []uuid.UUID {workspaceID },
706
+ }).
707
+ Times (1 )
708
+ if len (params ) > 0 {
709
+ c .Return (params , nil )
710
+ } else {
711
+ c .Return (nil , sql .ErrNoRows )
712
+ }
713
+ }
714
+ }
715
+
662
716
func withRichParameters (params []database.WorkspaceBuildParameter ) func (mTx * dbmock.MockStore ) {
663
717
return func (mTx * dbmock.MockStore ) {
664
718
c := mTx .EXPECT ().GetWorkspaceBuildParameters (gomock .Any (), lastBuildID ).
0 commit comments