@@ -487,6 +487,70 @@ func TestMultiplePresetsPerTemplateVersion(t *testing.T) {
487
487
}
488
488
}
489
489
490
+ func TestInvalidPreset (t * testing.T ) {
491
+ t .Parallel ()
492
+
493
+ if ! dbtestutil .WillUsePostgres () {
494
+ t .Skip ("This test requires postgres" )
495
+ }
496
+
497
+ templateDeleted := false
498
+
499
+ clock := quartz .NewMock (t )
500
+ ctx := testutil .Context (t , testutil .WaitShort )
501
+ cfg := codersdk.PrebuildsConfig {}
502
+ logger := slogtest .Make (
503
+ t , & slogtest.Options {IgnoreErrors : true },
504
+ ).Leveled (slog .LevelDebug )
505
+ db , pubSub := dbtestutil .NewDB (t )
506
+ controller := prebuilds .NewStoreReconciler (db , pubSub , cfg , logger , quartz .NewMock (t ))
507
+
508
+ ownerID := uuid .New ()
509
+ dbgen .User (t , db , database.User {
510
+ ID : ownerID ,
511
+ })
512
+ org , template := setupTestDBTemplate (t , db , ownerID , templateDeleted )
513
+ templateVersionID := setupTestDBTemplateVersion (
514
+ ctx ,
515
+ t ,
516
+ clock ,
517
+ db ,
518
+ pubSub ,
519
+ org .ID ,
520
+ ownerID ,
521
+ template .ID ,
522
+ )
523
+ // Add required param, which is not set in preset. It means that creating of prebuild will constantly fail.
524
+ dbgen .TemplateVersionParameter (t , db , database.TemplateVersionParameter {
525
+ TemplateVersionID : templateVersionID ,
526
+ Name : "required-param" ,
527
+ Description : "required param to make sure creating prebuild will fail" ,
528
+ Type : "bool" ,
529
+ DefaultValue : "" ,
530
+ Required : true ,
531
+ })
532
+ setupTestDBPreset (
533
+ t ,
534
+ db ,
535
+ templateVersionID ,
536
+ 1 ,
537
+ uuid .New ().String (),
538
+ )
539
+
540
+ // Run the reconciliation multiple times to ensure idempotency
541
+ // 8 was arbitrary, but large enough to reasonably trust the result
542
+ for i := 1 ; i <= 8 ; i ++ {
543
+ require .NoErrorf (t , controller .ReconcileAll (ctx ), "failed on iteration %d" , i )
544
+
545
+ workspaces , err := db .GetWorkspacesByTemplateID (ctx , template .ID )
546
+ require .NoError (t , err )
547
+ newPrebuildCount := len (workspaces )
548
+
549
+ // NOTE: we don't have any new prebuilds, because their creation constantly fails.
550
+ require .Equal (t , int32 (0 ), int32 (newPrebuildCount )) // nolint:gosec
551
+ }
552
+ }
553
+
490
554
func TestRunLoop (t * testing.T ) {
491
555
t .Parallel ()
492
556
0 commit comments