@@ -15,11 +15,11 @@ import (
15
15
"github.com/stretchr/testify/assert"
16
16
"github.com/stretchr/testify/require"
17
17
18
+ "cdr.dev/slog"
19
+ "cdr.dev/slog/sloggers/slogtest"
18
20
"github.com/coder/quartz"
19
-
20
21
"github.com/coder/serpent"
21
22
22
- "github.com/coder/coder/v2/coderd/coderdtest"
23
23
"github.com/coder/coder/v2/coderd/database"
24
24
"github.com/coder/coder/v2/coderd/database/dbauthz"
25
25
"github.com/coder/coder/v2/coderd/database/dbtestutil"
@@ -39,7 +39,8 @@ func TestMetrics(t *testing.T) {
39
39
40
40
// nolint:gocritic // Unit test.
41
41
ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
42
- _ , _ , api := coderdtest .NewWithAPI (t , nil )
42
+ store , _ := dbtestutil .NewDB (t )
43
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
43
44
44
45
reg := prometheus .NewRegistry ()
45
46
metrics := notifications .NewMetrics (reg )
@@ -59,7 +60,7 @@ func TestMetrics(t *testing.T) {
59
60
cfg .RetryInterval = serpent .Duration (time .Millisecond * 50 )
60
61
cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 ) // Twice as long as fetch interval to ensure we catch pending updates.
61
62
62
- mgr , err := notifications .NewManager (cfg , api . Database , defaultHelpers (), metrics , api . Logger .Named ("manager" ))
63
+ mgr , err := notifications .NewManager (cfg , store , defaultHelpers (), metrics , logger .Named ("manager" ))
63
64
require .NoError (t , err )
64
65
t .Cleanup (func () {
65
66
assert .NoError (t , mgr .Stop (ctx ))
@@ -69,10 +70,10 @@ func TestMetrics(t *testing.T) {
69
70
method : handler ,
70
71
})
71
72
72
- enq , err := notifications .NewStoreEnqueuer (cfg , api . Database , defaultHelpers (), api . Logger .Named ("enqueuer" ), quartz .NewReal ())
73
+ enq , err := notifications .NewStoreEnqueuer (cfg , store , defaultHelpers (), logger .Named ("enqueuer" ), quartz .NewReal ())
73
74
require .NoError (t , err )
74
75
75
- user := createSampleUser (t , api . Database )
76
+ user := createSampleUser (t , store )
76
77
77
78
// Build fingerprints for the two different series we expect.
78
79
methodTemplateFP := fingerprintLabels (notifications .LabelMethod , string (method ), notifications .LabelTemplateID , template .String ())
@@ -212,7 +213,8 @@ func TestPendingUpdatesMetric(t *testing.T) {
212
213
// SETUP
213
214
// nolint:gocritic // Unit test.
214
215
ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
215
- _ , _ , api := coderdtest .NewWithAPI (t , nil )
216
+ store , _ := dbtestutil .NewDB (t )
217
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
216
218
217
219
reg := prometheus .NewRegistry ()
218
220
metrics := notifications .NewMetrics (reg )
@@ -225,12 +227,12 @@ func TestPendingUpdatesMetric(t *testing.T) {
225
227
cfg .RetryInterval = serpent .Duration (time .Hour ) // Delay retries so they don't interfere.
226
228
cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 )
227
229
228
- syncer := & syncInterceptor {Store : api . Database }
230
+ syncer := & syncInterceptor {Store : store }
229
231
interceptor := newUpdateSignallingInterceptor (syncer )
230
232
mClock := quartz .NewMock (t )
231
233
trap := mClock .Trap ().NewTicker ("Manager" , "storeSync" )
232
234
defer trap .Close ()
233
- mgr , err := notifications .NewManager (cfg , interceptor , defaultHelpers (), metrics , api . Logger .Named ("manager" ),
235
+ mgr , err := notifications .NewManager (cfg , interceptor , defaultHelpers (), metrics , logger .Named ("manager" ),
234
236
notifications .WithTestClock (mClock ))
235
237
require .NoError (t , err )
236
238
t .Cleanup (func () {
@@ -241,10 +243,10 @@ func TestPendingUpdatesMetric(t *testing.T) {
241
243
method : handler ,
242
244
})
243
245
244
- enq , err := notifications .NewStoreEnqueuer (cfg , api . Database , defaultHelpers (), api . Logger .Named ("enqueuer" ), quartz .NewReal ())
246
+ enq , err := notifications .NewStoreEnqueuer (cfg , store , defaultHelpers (), logger .Named ("enqueuer" ), quartz .NewReal ())
245
247
require .NoError (t , err )
246
248
247
- user := createSampleUser (t , api . Database )
249
+ user := createSampleUser (t , store )
248
250
249
251
// WHEN: 2 notifications are enqueued, one of which will fail and one which will succeed
250
252
_ , err = enq .Enqueue (ctx , user .ID , template , map [string ]string {"type" : "success" }, "test" ) // this will succeed
@@ -296,7 +298,8 @@ func TestInflightDispatchesMetric(t *testing.T) {
296
298
// SETUP
297
299
// nolint:gocritic // Unit test.
298
300
ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
299
- _ , _ , api := coderdtest .NewWithAPI (t , nil )
301
+ store , _ := dbtestutil .NewDB (t )
302
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
300
303
301
304
reg := prometheus .NewRegistry ()
302
305
metrics := notifications .NewMetrics (reg )
@@ -311,7 +314,7 @@ func TestInflightDispatchesMetric(t *testing.T) {
311
314
cfg .RetryInterval = serpent .Duration (time .Hour ) // Delay retries so they don't interfere.
312
315
cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 )
313
316
314
- mgr , err := notifications .NewManager (cfg , api . Database , defaultHelpers (), metrics , api . Logger .Named ("manager" ))
317
+ mgr , err := notifications .NewManager (cfg , store , defaultHelpers (), metrics , logger .Named ("manager" ))
315
318
require .NoError (t , err )
316
319
t .Cleanup (func () {
317
320
assert .NoError (t , mgr .Stop (ctx ))
@@ -326,10 +329,10 @@ func TestInflightDispatchesMetric(t *testing.T) {
326
329
method : barrier ,
327
330
})
328
331
329
- enq , err := notifications .NewStoreEnqueuer (cfg , api . Database , defaultHelpers (), api . Logger .Named ("enqueuer" ), quartz .NewReal ())
332
+ enq , err := notifications .NewStoreEnqueuer (cfg , store , defaultHelpers (), logger .Named ("enqueuer" ), quartz .NewReal ())
330
333
require .NoError (t , err )
331
334
332
- user := createSampleUser (t , api . Database )
335
+ user := createSampleUser (t , store )
333
336
334
337
// WHEN: notifications are enqueued which will succeed (and be delayed during dispatch)
335
338
for i := 0 ; i < msgCount ; i ++ {
@@ -374,7 +377,8 @@ func TestCustomMethodMetricCollection(t *testing.T) {
374
377
375
378
// nolint:gocritic // Unit test.
376
379
ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
377
- _ , _ , api := coderdtest .NewWithAPI (t , nil )
380
+ store , _ := dbtestutil .NewDB (t )
381
+ logger := slogtest .Make (t , nil ).Leveled (slog .LevelDebug )
378
382
379
383
var (
380
384
reg = prometheus .NewRegistry ()
@@ -389,7 +393,7 @@ func TestCustomMethodMetricCollection(t *testing.T) {
389
393
)
390
394
391
395
// GIVEN: a template whose notification method differs from the default.
392
- out , err := api . Database .UpdateNotificationTemplateMethodByID (ctx , database.UpdateNotificationTemplateMethodByIDParams {
396
+ out , err := store .UpdateNotificationTemplateMethodByID (ctx , database.UpdateNotificationTemplateMethodByIDParams {
393
397
ID : template ,
394
398
Method : database.NullNotificationMethod {NotificationMethod : customMethod , Valid : true },
395
399
})
@@ -398,7 +402,7 @@ func TestCustomMethodMetricCollection(t *testing.T) {
398
402
399
403
// WHEN: two notifications (each with different templates) are enqueued.
400
404
cfg := defaultNotificationsConfig (defaultMethod )
401
- mgr , err := notifications .NewManager (cfg , api . Database , defaultHelpers (), metrics , api . Logger .Named ("manager" ))
405
+ mgr , err := notifications .NewManager (cfg , store , defaultHelpers (), metrics , logger .Named ("manager" ))
402
406
require .NoError (t , err )
403
407
t .Cleanup (func () {
404
408
assert .NoError (t , mgr .Stop (ctx ))
@@ -411,10 +415,10 @@ func TestCustomMethodMetricCollection(t *testing.T) {
411
415
customMethod : webhookHandler ,
412
416
})
413
417
414
- enq , err := notifications .NewStoreEnqueuer (cfg , api . Database , defaultHelpers (), api . Logger .Named ("enqueuer" ), quartz .NewReal ())
418
+ enq , err := notifications .NewStoreEnqueuer (cfg , store , defaultHelpers (), logger .Named ("enqueuer" ), quartz .NewReal ())
415
419
require .NoError (t , err )
416
420
417
- user := createSampleUser (t , api . Database )
421
+ user := createSampleUser (t , store )
418
422
419
423
_ , err = enq .Enqueue (ctx , user .ID , template , map [string ]string {"type" : "success" }, "test" )
420
424
require .NoError (t , err )
0 commit comments