@@ -15,11 +15,11 @@ import (
1515 "github.com/stretchr/testify/assert"
1616 "github.com/stretchr/testify/require"
1717
18+ "cdr.dev/slog"
19+ "cdr.dev/slog/sloggers/slogtest"
1820 "github.com/coder/quartz"
19-
2021 "github.com/coder/serpent"
2122
22- "github.com/coder/coder/v2/coderd/coderdtest"
2323 "github.com/coder/coder/v2/coderd/database"
2424 "github.com/coder/coder/v2/coderd/database/dbauthz"
2525 "github.com/coder/coder/v2/coderd/database/dbtestutil"
@@ -39,7 +39,8 @@ func TestMetrics(t *testing.T) {
3939
4040 // nolint:gocritic // Unit test.
4141 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 )
4344
4445 reg := prometheus .NewRegistry ()
4546 metrics := notifications .NewMetrics (reg )
@@ -59,7 +60,7 @@ func TestMetrics(t *testing.T) {
5960 cfg .RetryInterval = serpent .Duration (time .Millisecond * 50 )
6061 cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 ) // Twice as long as fetch interval to ensure we catch pending updates.
6162
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" ))
6364 require .NoError (t , err )
6465 t .Cleanup (func () {
6566 assert .NoError (t , mgr .Stop (ctx ))
@@ -69,10 +70,10 @@ func TestMetrics(t *testing.T) {
6970 method : handler ,
7071 })
7172
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 ())
7374 require .NoError (t , err )
7475
75- user := createSampleUser (t , api . Database )
76+ user := createSampleUser (t , store )
7677
7778 // Build fingerprints for the two different series we expect.
7879 methodTemplateFP := fingerprintLabels (notifications .LabelMethod , string (method ), notifications .LabelTemplateID , template .String ())
@@ -212,7 +213,8 @@ func TestPendingUpdatesMetric(t *testing.T) {
212213 // SETUP
213214 // nolint:gocritic // Unit test.
214215 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 )
216218
217219 reg := prometheus .NewRegistry ()
218220 metrics := notifications .NewMetrics (reg )
@@ -225,12 +227,12 @@ func TestPendingUpdatesMetric(t *testing.T) {
225227 cfg .RetryInterval = serpent .Duration (time .Hour ) // Delay retries so they don't interfere.
226228 cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 )
227229
228- syncer := & syncInterceptor {Store : api . Database }
230+ syncer := & syncInterceptor {Store : store }
229231 interceptor := newUpdateSignallingInterceptor (syncer )
230232 mClock := quartz .NewMock (t )
231233 trap := mClock .Trap ().NewTicker ("Manager" , "storeSync" )
232234 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" ),
234236 notifications .WithTestClock (mClock ))
235237 require .NoError (t , err )
236238 t .Cleanup (func () {
@@ -241,10 +243,10 @@ func TestPendingUpdatesMetric(t *testing.T) {
241243 method : handler ,
242244 })
243245
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 ())
245247 require .NoError (t , err )
246248
247- user := createSampleUser (t , api . Database )
249+ user := createSampleUser (t , store )
248250
249251 // WHEN: 2 notifications are enqueued, one of which will fail and one which will succeed
250252 _ , 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) {
296298 // SETUP
297299 // nolint:gocritic // Unit test.
298300 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 )
300303
301304 reg := prometheus .NewRegistry ()
302305 metrics := notifications .NewMetrics (reg )
@@ -311,7 +314,7 @@ func TestInflightDispatchesMetric(t *testing.T) {
311314 cfg .RetryInterval = serpent .Duration (time .Hour ) // Delay retries so they don't interfere.
312315 cfg .StoreSyncInterval = serpent .Duration (time .Millisecond * 100 )
313316
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" ))
315318 require .NoError (t , err )
316319 t .Cleanup (func () {
317320 assert .NoError (t , mgr .Stop (ctx ))
@@ -326,10 +329,10 @@ func TestInflightDispatchesMetric(t *testing.T) {
326329 method : barrier ,
327330 })
328331
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 ())
330333 require .NoError (t , err )
331334
332- user := createSampleUser (t , api . Database )
335+ user := createSampleUser (t , store )
333336
334337 // WHEN: notifications are enqueued which will succeed (and be delayed during dispatch)
335338 for i := 0 ; i < msgCount ; i ++ {
@@ -374,7 +377,8 @@ func TestCustomMethodMetricCollection(t *testing.T) {
374377
375378 // nolint:gocritic // Unit test.
376379 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 )
378382
379383 var (
380384 reg = prometheus .NewRegistry ()
@@ -389,7 +393,7 @@ func TestCustomMethodMetricCollection(t *testing.T) {
389393 )
390394
391395 // 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 {
393397 ID : template ,
394398 Method : database.NullNotificationMethod {NotificationMethod : customMethod , Valid : true },
395399 })
@@ -398,7 +402,7 @@ func TestCustomMethodMetricCollection(t *testing.T) {
398402
399403 // WHEN: two notifications (each with different templates) are enqueued.
400404 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" ))
402406 require .NoError (t , err )
403407 t .Cleanup (func () {
404408 assert .NoError (t , mgr .Stop (ctx ))
@@ -411,10 +415,10 @@ func TestCustomMethodMetricCollection(t *testing.T) {
411415 customMethod : webhookHandler ,
412416 })
413417
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 ())
415419 require .NoError (t , err )
416420
417- user := createSampleUser (t , api . Database )
421+ user := createSampleUser (t , store )
418422
419423 _ , err = enq .Enqueue (ctx , user .ID , template , map [string ]string {"type" : "success" }, "test" )
420424 require .NoError (t , err )
0 commit comments