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