@@ -2,6 +2,7 @@ package notifications_test
2
2
3
3
import (
4
4
"context"
5
+ "strconv"
5
6
"testing"
6
7
"time"
7
8
@@ -35,7 +36,9 @@ func TestMetrics(t *testing.T) {
35
36
t .Skip ("This test requires postgres; it relies on business-logic only implemented in the database" )
36
37
}
37
38
38
- ctx , logger , store := setup (t )
39
+ // nolint:gocritic // Unit test.
40
+ ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
41
+ _ , _ , api := coderdtest .NewWithAPI (t , nil )
39
42
40
43
reg := prometheus .NewRegistry ()
41
44
metrics := notifications .NewMetrics (reg )
@@ -55,7 +58,7 @@ func TestMetrics(t *testing.T) {
55
58
cfg .RetryInterval = serpent .Duration (time .Millisecond * 50 )
56
59
cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 ) // Twice as long as fetch interval to ensure we catch pending updates.
57
60
58
- mgr , err := notifications .NewManager (cfg , store , defaultHelpers (), metrics , logger .Named ("manager" ))
61
+ mgr , err := notifications .NewManager (cfg , api . Database , defaultHelpers (), metrics , api . Logger .Named ("manager" ))
59
62
require .NoError (t , err )
60
63
t .Cleanup (func () {
61
64
assert .NoError (t , mgr .Stop (ctx ))
@@ -65,10 +68,10 @@ func TestMetrics(t *testing.T) {
65
68
method : handler ,
66
69
})
67
70
68
- enq , err := notifications .NewStoreEnqueuer (cfg , store , defaultHelpers (), logger .Named ("enqueuer" ), quartz .NewReal ())
71
+ enq , err := notifications .NewStoreEnqueuer (cfg , api . Database , defaultHelpers (), api . Logger .Named ("enqueuer" ), quartz .NewReal ())
69
72
require .NoError (t , err )
70
73
71
- user := createSampleUser (t , store )
74
+ user := createSampleUser (t , api . Database )
72
75
73
76
// Build fingerprints for the two different series we expect.
74
77
methodTemplateFP := fingerprintLabels (notifications .LabelMethod , string (method ), notifications .LabelTemplateID , template .String ())
@@ -206,6 +209,7 @@ func TestPendingUpdatesMetric(t *testing.T) {
206
209
t .Parallel ()
207
210
208
211
// SETUP
212
+ // nolint:gocritic // Unit test.
209
213
ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
210
214
_ , _ , api := coderdtest .NewWithAPI (t , nil )
211
215
@@ -282,6 +286,7 @@ func TestInflightDispatchesMetric(t *testing.T) {
282
286
t .Parallel ()
283
287
284
288
// SETUP
289
+ // nolint:gocritic // Unit test.
285
290
ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
286
291
_ , _ , api := coderdtest .NewWithAPI (t , nil )
287
292
@@ -319,7 +324,7 @@ func TestInflightDispatchesMetric(t *testing.T) {
319
324
// WHEN: notifications are enqueued which will succeed (and be delayed during dispatch)
320
325
const msgCount = 2
321
326
for i := 0 ; i < msgCount ; i ++ {
322
- _ , err = enq .Enqueue (ctx , user .ID , template , map [string ]string {"type" : "success" }, "test" )
327
+ _ , err = enq .Enqueue (ctx , user .ID , template , map [string ]string {"type" : "success" , "i" : strconv . Itoa ( i ) }, "test" )
323
328
require .NoError (t , err )
324
329
}
325
330
@@ -353,7 +358,10 @@ func TestCustomMethodMetricCollection(t *testing.T) {
353
358
// UpdateNotificationTemplateMethodByID only makes sense with a real database.
354
359
t .Skip ("This test requires postgres; it relies on business-logic only implemented in the database" )
355
360
}
356
- ctx , logger , store := setup (t )
361
+
362
+ // nolint:gocritic // Unit test.
363
+ ctx := dbauthz .AsSystemRestricted (testutil .Context (t , testutil .WaitSuperLong ))
364
+ _ , _ , api := coderdtest .NewWithAPI (t , nil )
357
365
358
366
var (
359
367
reg = prometheus .NewRegistry ()
@@ -368,7 +376,7 @@ func TestCustomMethodMetricCollection(t *testing.T) {
368
376
)
369
377
370
378
// GIVEN: a template whose notification method differs from the default.
371
- out , err := store .UpdateNotificationTemplateMethodByID (ctx , database.UpdateNotificationTemplateMethodByIDParams {
379
+ out , err := api . Database .UpdateNotificationTemplateMethodByID (ctx , database.UpdateNotificationTemplateMethodByIDParams {
372
380
ID : template ,
373
381
Method : database.NullNotificationMethod {NotificationMethod : customMethod , Valid : true },
374
382
})
@@ -377,7 +385,7 @@ func TestCustomMethodMetricCollection(t *testing.T) {
377
385
378
386
// WHEN: two notifications (each with different templates) are enqueued.
379
387
cfg := defaultNotificationsConfig (defaultMethod )
380
- mgr , err := notifications .NewManager (cfg , store , defaultHelpers (), metrics , logger .Named ("manager" ))
388
+ mgr , err := notifications .NewManager (cfg , api . Database , defaultHelpers (), metrics , api . Logger .Named ("manager" ))
381
389
require .NoError (t , err )
382
390
t .Cleanup (func () {
383
391
assert .NoError (t , mgr .Stop (ctx ))
@@ -390,10 +398,10 @@ func TestCustomMethodMetricCollection(t *testing.T) {
390
398
customMethod : webhookHandler ,
391
399
})
392
400
393
- enq , err := notifications .NewStoreEnqueuer (cfg , store , defaultHelpers (), logger .Named ("enqueuer" ), quartz .NewReal ())
401
+ enq , err := notifications .NewStoreEnqueuer (cfg , api . Database , defaultHelpers (), api . Logger .Named ("enqueuer" ), quartz .NewReal ())
394
402
require .NoError (t , err )
395
403
396
- user := createSampleUser (t , store )
404
+ user := createSampleUser (t , api . Database )
397
405
398
406
_ , err = enq .Enqueue (ctx , user .ID , template , map [string ]string {"type" : "success" }, "test" )
399
407
require .NoError (t , err )
0 commit comments