Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 48ad269

Browse files
committed
Add test to verify notification in lifecycle executor
1 parent 10ff6cf commit 48ad269

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

coderd/autobuild/lifecycle_executor_test.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,15 +1070,15 @@ func TestNotifications(t *testing.T) {
10701070

10711071
// Setup template with dormancy and create a workspace with it
10721072
var (
1073-
ticker = make(chan time.Time)
1074-
statCh = make(chan autobuild.Stats)
1075-
notificationsEnqueuer = testutil.FakeNotificationsEnqueuer{}
1076-
timeTilDormant = time.Minute
1077-
client = coderdtest.New(t, &coderdtest.Options{
1073+
ticker = make(chan time.Time)
1074+
statCh = make(chan autobuild.Stats)
1075+
notifyEnq = testutil.FakeNotificationsEnqueuer{}
1076+
timeTilDormant = time.Minute
1077+
client = coderdtest.New(t, &coderdtest.Options{
10781078
AutobuildTicker: ticker,
10791079
AutobuildStats: statCh,
10801080
IncludeProvisionerDaemon: true,
1081-
NotificationsEnqueuer: &notificationsEnqueuer,
1081+
NotificationsEnqueuer: &notifyEnq,
10821082
TemplateScheduleStore: schedule.MockTemplateScheduleStore{
10831083
GetFn: func(_ context.Context, _ database.Store, _ uuid.UUID) (schedule.TemplateScheduleOptions, error) {
10841084
return schedule.TemplateScheduleOptions{
@@ -1112,6 +1112,15 @@ func TestNotifications(t *testing.T) {
11121112
// Check that the workspace is dormant
11131113
workspace = coderdtest.MustWorkspace(t, client, workspace.ID)
11141114
require.NotNil(t, workspace.DormantAt)
1115+
1116+
// Check that a notification was enqueued
1117+
require.Len(t, notifyEnq.Sent, 1)
1118+
require.Equal(t, notifyEnq.Sent[0].UserID, workspace.OwnerID)
1119+
require.Contains(t, notifyEnq.Sent[0].Targets, template.ID)
1120+
require.Contains(t, notifyEnq.Sent[0].Targets, workspace.ID)
1121+
require.Contains(t, notifyEnq.Sent[0].Targets, workspace.OrganizationID)
1122+
require.Contains(t, notifyEnq.Sent[0].Targets, workspace.OwnerID)
1123+
require.Equal(t, notifyEnq.Sent[0].Labels["initiator"], "autobuild")
11151124
})
11161125
}
11171126

0 commit comments

Comments
 (0)