Skip to content

Commit 80d2145

Browse files
fix: tests that broke because of new notification
1 parent a6e892a commit 80d2145

File tree

3 files changed

+31
-23
lines changed

3 files changed

+31
-23
lines changed

coderd/autobuild/lifecycle_executor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ func TestExecutorAutostartTemplateUpdated(t *testing.T) {
274274
}
275275

276276
if tc.expectNotification {
277-
sent := enqueuer.Sent()
277+
sent := enqueuer.SentWithTemplateID(notifications.TemplateWorkspaceAutoUpdated)
278278
require.Len(t, sent, 1)
279279
require.Equal(t, sent[0].UserID, workspace.OwnerID)
280280
require.Contains(t, sent[0].Targets, workspace.TemplateID)
@@ -285,7 +285,7 @@ func TestExecutorAutostartTemplateUpdated(t *testing.T) {
285285
require.Equal(t, "autobuild", sent[0].Labels["initiator"])
286286
require.Equal(t, "autostart", sent[0].Labels["reason"])
287287
} else {
288-
require.Empty(t, enqueuer.Sent())
288+
require.Empty(t, enqueuer.SentWithTemplateID(notifications.TemplateWorkspaceAutoUpdated))
289289
}
290290
})
291291
}

coderd/notifications/notificationstest/fake_enqueuer.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,16 @@ func (f *FakeEnqueuer) Sent() []*FakeNotification {
9797
defer f.mu.Unlock()
9898
return append([]*FakeNotification{}, f.sent...)
9999
}
100+
101+
func (f *FakeEnqueuer) SentWithTemplateID(id uuid.UUID) []*FakeNotification {
102+
f.mu.Lock()
103+
defer f.mu.Unlock()
104+
105+
sent := []*FakeNotification{}
106+
for _, notif := range f.sent {
107+
if notif.TemplateID == id {
108+
sent = append(sent, notif)
109+
}
110+
}
111+
return sent
112+
}

coderd/workspaces_test.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,13 @@ func TestPostWorkspacesByOrganization(t *testing.T) {
585585
workspace := coderdtest.CreateWorkspace(t, client, template.ID)
586586
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
587587

588-
var notif *notificationstest.FakeNotification
589-
for _, n := range enqueuer.Sent() {
590-
if n.TemplateID == notifications.TemplateWorkspaceCreated {
591-
notif = n
592-
break
593-
}
594-
}
595-
596-
assert.NotNil(t, notif)
597-
assert.Equal(t, user.UserID, notif.UserID)
598-
assert.Equal(t, notifications.TemplateWorkspaceCreated, notif.TemplateID)
588+
sent := enqueuer.SentWithTemplateID(notifications.TemplateWorkspaceCreated)
589+
require.Len(t, sent, 1)
590+
require.Equal(t, user.UserID, sent[0].UserID)
591+
require.Contains(t, sent[0].Targets, template.ID)
592+
require.Contains(t, sent[0].Targets, workspace.ID)
593+
require.Contains(t, sent[0].Targets, workspace.OrganizationID)
594+
require.Contains(t, sent[0].Targets, workspace.OwnerID)
599595
})
600596

601597
t.Run("CreateWithAuditLogs", func(t *testing.T) {
@@ -3623,15 +3619,14 @@ func TestWorkspaceNotifications(t *testing.T) {
36233619

36243620
// Then
36253621
require.NoError(t, err, "mark workspace as dormant")
3626-
sent := notifyEnq.Sent()
3627-
require.Len(t, sent, 2)
3628-
// notifyEnq.Sent[0] is an event for created user account
3629-
require.Equal(t, sent[1].TemplateID, notifications.TemplateWorkspaceDormant)
3630-
require.Equal(t, sent[1].UserID, workspace.OwnerID)
3631-
require.Contains(t, sent[1].Targets, template.ID)
3632-
require.Contains(t, sent[1].Targets, workspace.ID)
3633-
require.Contains(t, sent[1].Targets, workspace.OrganizationID)
3634-
require.Contains(t, sent[1].Targets, workspace.OwnerID)
3622+
sent := notifyEnq.SentWithTemplateID(notifications.TemplateWorkspaceDormant)
3623+
require.Len(t, sent, 1)
3624+
require.Equal(t, sent[0].TemplateID, notifications.TemplateWorkspaceDormant)
3625+
require.Equal(t, sent[0].UserID, workspace.OwnerID)
3626+
require.Contains(t, sent[0].Targets, template.ID)
3627+
require.Contains(t, sent[0].Targets, workspace.ID)
3628+
require.Contains(t, sent[0].Targets, workspace.OrganizationID)
3629+
require.Contains(t, sent[0].Targets, workspace.OwnerID)
36353630
})
36363631

36373632
t.Run("InitiatorIsOwner", func(t *testing.T) {
@@ -3662,7 +3657,7 @@ func TestWorkspaceNotifications(t *testing.T) {
36623657

36633658
// Then
36643659
require.NoError(t, err, "mark workspace as dormant")
3665-
require.Len(t, notifyEnq.Sent(), 0)
3660+
require.Len(t, notifyEnq.SentWithTemplateID(notifications.TemplateWorkspaceDormant), 0)
36663661
})
36673662

36683663
t.Run("ActivateDormantWorkspace", func(t *testing.T) {

0 commit comments

Comments
 (0)