@@ -689,7 +689,13 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
689
689
t , & slogtest.Options {IgnoreErrors : true },
690
690
).Leveled (slog .LevelDebug )
691
691
db , pubSub := dbtestutil .NewDB (t )
692
- controller := prebuilds .NewStoreReconciler (db , pubSub , cfg , logger , clock , prometheus .NewRegistry (), newNoopEnqueuer ())
692
+ fakeEnqueuer := newFakeEnqueuer ()
693
+ controller := prebuilds .NewStoreReconciler (db , pubSub , cfg , logger , clock , prometheus .NewRegistry (), fakeEnqueuer )
694
+
695
+ // Template admin to receive a notification.
696
+ templateAdmin := dbgen .User (t , db , database.User {
697
+ RBACRoles : []string {codersdk .RoleTemplateAdmin },
698
+ })
693
699
694
700
// Set up test environment with a template, version, and preset
695
701
ownerID := uuid .New ()
@@ -731,13 +737,28 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
731
737
workspaces , err = db .GetWorkspacesByTemplateID (ctx , template .ID )
732
738
require .NoError (t , err )
733
739
734
- if tc .isHardLimitHit {
735
- // When hard limit is reached, no new workspace should be created
736
- require .Equal (t , 1 , len (workspaces ))
737
- } else {
740
+ if ! tc .isHardLimitHit {
738
741
// When hard limit is not reached, a new workspace should be created
739
742
require .Equal (t , 2 , len (workspaces ))
743
+ return
740
744
}
745
+
746
+ // When hard limit is reached, no new workspace should be created
747
+ require .Equal (t , 1 , len (workspaces ))
748
+
749
+ // When hard limit is reached, a notification should be sent.
750
+ matching := fakeEnqueuer .Sent (func (notification * notificationstest.FakeNotification ) bool {
751
+ if ! assert .Equal (t , notification .TemplateID , notifications .PrebuildFailureLimitReached , "unexpected template" ) {
752
+ return false
753
+ }
754
+
755
+ if ! assert .Equal (t , templateAdmin .ID , notification .UserID , "unexpected receiver" ) {
756
+ return false
757
+ }
758
+
759
+ return true
760
+ })
761
+ require .Len (t , matching , 1 )
741
762
})
742
763
}
743
764
}
0 commit comments