@@ -19,6 +19,7 @@ import (
19
19
"github.com/coder/coder/v2/coderd/database"
20
20
"github.com/coder/coder/v2/coderd/database/dbauthz"
21
21
"github.com/coder/coder/v2/coderd/notifications"
22
+ "github.com/coder/coder/v2/coderd/notifications/notificationstest"
22
23
"github.com/coder/coder/v2/coderd/schedule"
23
24
"github.com/coder/coder/v2/coderd/schedule/cron"
24
25
"github.com/coder/coder/v2/coderd/util/ptr"
@@ -116,7 +117,7 @@ func TestExecutorAutostartTemplateUpdated(t *testing.T) {
116
117
tickCh = make (chan time.Time )
117
118
statsCh = make (chan autobuild.Stats )
118
119
logger = slogtest .Make (t , & slogtest.Options {IgnoreErrors : ! tc .expectStart }).Leveled (slog .LevelDebug )
119
- enqueuer = testutil. FakeNotificationsEnqueuer {}
120
+ enqueuer = notificationstest. FakeEnqueuer {}
120
121
client = coderdtest .New (t , & coderdtest.Options {
121
122
AutobuildTicker : tickCh ,
122
123
IncludeProvisionerDaemon : true ,
@@ -202,17 +203,18 @@ func TestExecutorAutostartTemplateUpdated(t *testing.T) {
202
203
}
203
204
204
205
if tc .expectNotification {
205
- require .Len (t , enqueuer .Sent , 1 )
206
- require .Equal (t , enqueuer .Sent [0 ].UserID , workspace .OwnerID )
207
- require .Contains (t , enqueuer .Sent [0 ].Targets , workspace .TemplateID )
208
- require .Contains (t , enqueuer .Sent [0 ].Targets , workspace .ID )
209
- require .Contains (t , enqueuer .Sent [0 ].Targets , workspace .OrganizationID )
210
- require .Contains (t , enqueuer .Sent [0 ].Targets , workspace .OwnerID )
211
- require .Equal (t , newVersion .Name , enqueuer .Sent [0 ].Labels ["template_version_name" ])
212
- require .Equal (t , "autobuild" , enqueuer .Sent [0 ].Labels ["initiator" ])
213
- require .Equal (t , "autostart" , enqueuer .Sent [0 ].Labels ["reason" ])
206
+ sent := enqueuer .Sent ()
207
+ require .Len (t , sent , 1 )
208
+ require .Equal (t , sent [0 ].UserID , workspace .OwnerID )
209
+ require .Contains (t , sent [0 ].Targets , workspace .TemplateID )
210
+ require .Contains (t , sent [0 ].Targets , workspace .ID )
211
+ require .Contains (t , sent [0 ].Targets , workspace .OrganizationID )
212
+ require .Contains (t , sent [0 ].Targets , workspace .OwnerID )
213
+ require .Equal (t , newVersion .Name , sent [0 ].Labels ["template_version_name" ])
214
+ require .Equal (t , "autobuild" , sent [0 ].Labels ["initiator" ])
215
+ require .Equal (t , "autostart" , sent [0 ].Labels ["reason" ])
214
216
} else {
215
- require .Len (t , enqueuer .Sent , 0 )
217
+ require .Empty (t , enqueuer .Sent () )
216
218
}
217
219
})
218
220
}
@@ -1073,7 +1075,7 @@ func TestNotifications(t *testing.T) {
1073
1075
var (
1074
1076
ticker = make (chan time.Time )
1075
1077
statCh = make (chan autobuild.Stats )
1076
- notifyEnq = testutil. FakeNotificationsEnqueuer {}
1078
+ notifyEnq = notificationstest. FakeEnqueuer {}
1077
1079
timeTilDormant = time .Minute
1078
1080
client = coderdtest .New (t , & coderdtest.Options {
1079
1081
AutobuildTicker : ticker ,
@@ -1107,6 +1109,7 @@ func TestNotifications(t *testing.T) {
1107
1109
_ = coderdtest .AwaitWorkspaceBuildJobCompleted (t , userClient , workspace .LatestBuild .ID )
1108
1110
1109
1111
// Wait for workspace to become dormant
1112
+ notifyEnq .Clear ()
1110
1113
ticker <- workspace .LastUsedAt .Add (timeTilDormant * 3 )
1111
1114
_ = testutil .RequireRecvCtx (testutil .Context (t , testutil .WaitShort ), t , statCh )
1112
1115
@@ -1115,14 +1118,14 @@ func TestNotifications(t *testing.T) {
1115
1118
require .NotNil (t , workspace .DormantAt )
1116
1119
1117
1120
// Check that a notification was enqueued
1118
- require . Len ( t , notifyEnq .Sent , 2 )
1119
- // notifyEnq.Sent[0] is an event for created user account
1120
- require .Equal (t , notifyEnq . Sent [ 1 ].UserID , workspace .OwnerID )
1121
- require .Equal (t , notifyEnq . Sent [ 1 ].TemplateID , notifications .TemplateWorkspaceDormant )
1122
- require .Contains (t , notifyEnq . Sent [ 1 ].Targets , template .ID )
1123
- require .Contains (t , notifyEnq . Sent [ 1 ].Targets , workspace .ID )
1124
- require .Contains (t , notifyEnq . Sent [ 1 ].Targets , workspace .OrganizationID )
1125
- require .Contains (t , notifyEnq . Sent [ 1 ].Targets , workspace .OwnerID )
1121
+ sent := notifyEnq .Sent ( )
1122
+ require . Len ( t , sent , 1 )
1123
+ require .Equal (t , sent [ 0 ].UserID , workspace .OwnerID )
1124
+ require .Equal (t , sent [ 0 ].TemplateID , notifications .TemplateWorkspaceDormant )
1125
+ require .Contains (t , sent [ 0 ].Targets , template .ID )
1126
+ require .Contains (t , sent [ 0 ].Targets , workspace .ID )
1127
+ require .Contains (t , sent [ 0 ].Targets , workspace .OrganizationID )
1128
+ require .Contains (t , sent [ 0 ].Targets , workspace .OwnerID )
1126
1129
})
1127
1130
}
1128
1131
@@ -1168,7 +1171,7 @@ func mustSchedule(t *testing.T, s string) *cron.Schedule {
1168
1171
}
1169
1172
1170
1173
func mustWorkspaceParameters (t * testing.T , client * codersdk.Client , workspaceID uuid.UUID ) {
1171
- ctx := context . Background ( )
1174
+ ctx := testutil . Context ( t , testutil . WaitShort )
1172
1175
buildParameters , err := client .WorkspaceBuildParameters (ctx , workspaceID )
1173
1176
require .NoError (t , err )
1174
1177
require .NotEmpty (t , buildParameters )
0 commit comments