Skip to content

Commit 08b18b0

Browse files
test: add a notification test
1 parent b0248c3 commit 08b18b0

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

enterprise/coderd/prebuilds/reconcile_test.go

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,13 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
689689
t, &slogtest.Options{IgnoreErrors: true},
690690
).Leveled(slog.LevelDebug)
691691
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+
})
693699

694700
// Set up test environment with a template, version, and preset
695701
ownerID := uuid.New()
@@ -731,13 +737,28 @@ func TestSkippingHardLimitedPresets(t *testing.T) {
731737
workspaces, err = db.GetWorkspacesByTemplateID(ctx, template.ID)
732738
require.NoError(t, err)
733739

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 {
738741
// When hard limit is not reached, a new workspace should be created
739742
require.Equal(t, 2, len(workspaces))
743+
return
740744
}
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)
741762
})
742763
}
743764
}

0 commit comments

Comments
 (0)