@@ -35,6 +35,7 @@ import (
35
35
"golang.org/x/xerrors"
36
36
37
37
"cdr.dev/slog"
38
+ "cdr.dev/slog/sloggers/sloghuman"
38
39
"github.com/coder/quartz"
39
40
"github.com/coder/serpent"
40
41
@@ -1654,18 +1655,20 @@ func TestDisabledByDefaultBeforeEnqueue(t *testing.T) {
1654
1655
1655
1656
ctx := dbauthz .AsNotifier (testutil .Context (t ,testutil .WaitSuperLong ))
1656
1657
store ,_ := dbtestutil .NewDB (t )
1657
- logger := testutil .Logger (t )
1658
+ logbuf := strings.Builder {}
1659
+ logger := testutil .Logger (t ).AppendSinks (sloghuman .Sink (& logbuf )).Leveled (slog .LevelDebug )
1658
1660
1659
1661
cfg := defaultNotificationsConfig (database .NotificationMethodSmtp )
1660
1662
enq ,err := notifications .NewStoreEnqueuer (cfg ,store ,defaultHelpers (),logger .Named ("enqueuer" ),quartz .NewReal ())
1661
1663
require .NoError (t ,err )
1662
1664
user := createSampleUser (t ,store )
1663
1665
1664
1666
// We want to try enqueuing a notification on a template that is disabled
1665
- // by default. We expect this tofail .
1667
+ // by default. We expect this tobe a no-op that produces a debug log .
1666
1668
templateID := notifications .TemplateWorkspaceManuallyUpdated
1667
1669
_ ,err = enq .Enqueue (ctx ,user .ID ,templateID ,map [string ]string {},"test" )
1668
- require .ErrorIs (t ,err ,notifications .ErrCannotEnqueueDisabledNotification ,"enqueuing did not fail with expected error" )
1670
+ require .NoError (t ,err )
1671
+ require .Contains (t ,logbuf .String (),"not enqueueing disabled notification" )
1669
1672
}
1670
1673
1671
1674
// TestDisabledBeforeEnqueue ensures that notifications cannot be enqueued once a user has disabled that notification template
@@ -1679,7 +1682,8 @@ func TestDisabledBeforeEnqueue(t *testing.T) {
1679
1682
1680
1683
ctx := dbauthz .AsNotifier (testutil .Context (t ,testutil .WaitSuperLong ))
1681
1684
store ,_ := dbtestutil .NewDB (t )
1682
- logger := testutil .Logger (t )
1685
+ logbuf := strings.Builder {}
1686
+ logger := testutil .Logger (t ).AppendSinks (sloghuman .Sink (& logbuf )).Leveled (slog .LevelDebug )
1683
1687
1684
1688
// GIVEN: an enqueuer & a sample user
1685
1689
cfg := defaultNotificationsConfig (database .NotificationMethodSmtp )
@@ -1697,9 +1701,11 @@ func TestDisabledBeforeEnqueue(t *testing.T) {
1697
1701
require .NoError (t ,err ,"failed to set preferences" )
1698
1702
require .EqualValues (t ,1 ,n ,"unexpected number of affected rows" )
1699
1703
1700
- // THEN: enqueuing the "workspace deleted" notification should fail with an error
1704
+ // THEN: enqueuing the "workspace deleted" notification should fail be
1705
+ // a no-op that produces a debug log
1701
1706
_ ,err = enq .Enqueue (ctx ,user .ID ,templateID ,map [string ]string {},"test" )
1702
- require .ErrorIs (t ,err ,notifications .ErrCannotEnqueueDisabledNotification ,"enqueueing did not fail with expected error" )
1707
+ require .NoError (t ,err )
1708
+ require .Contains (t ,logbuf .String (),"not enqueueing disabled notification" )
1703
1709
}
1704
1710
1705
1711
// TestDisabledAfterEnqueue ensures that notifications enqueued before a notification template was disabled will not be
@@ -1909,7 +1915,8 @@ func TestNotificationDuplicates(t *testing.T) {
1909
1915
1910
1916
ctx := dbauthz .AsNotifier (testutil .Context (t ,testutil .WaitSuperLong ))
1911
1917
store ,pubsub := dbtestutil .NewDB (t )
1912
- logger := testutil .Logger (t )
1918
+ logbuf := strings.Builder {}
1919
+ logger := testutil .Logger (t ).AppendSinks (sloghuman .Sink (& logbuf )).Leveled (slog .LevelDebug )
1913
1920
1914
1921
method := database .NotificationMethodSmtp
1915
1922
cfg := defaultNotificationsConfig (method )
@@ -1933,10 +1940,11 @@ func TestNotificationDuplicates(t *testing.T) {
1933
1940
map [string ]string {"initiator" :"danny" },"test" ,user .ID )
1934
1941
require .NoError (t ,err )
1935
1942
1936
- // WHEN: the second is enqueued, the enqueuer will rejectthe request .
1943
+ // WHEN: the second is enqueued, the enqueuer will rejectit as a duplicate .
1937
1944
_ ,err = enq .Enqueue (ctx ,user .ID ,notifications .TemplateWorkspaceDeleted ,
1938
1945
map [string ]string {"initiator" :"danny" },"test" ,user .ID )
1939
- require .ErrorIs (t ,err ,notifications .ErrDuplicate )
1946
+ require .NoError (t ,err )
1947
+ require .Contains (t ,logbuf .String (),"not enqueueing duplicate notification" )
1940
1948
1941
1949
// THEN: when the clock is advanced 24h, the notification will be accepted.
1942
1950
// NOTE: the time is used in the dedupe hash, so by advancing 24h we're creating a distinct notification from the one