Skip to content

Commit 0a66915

Browse files
test: test behaviour
1 parent e6b48c3 commit 0a66915

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5623,14 +5623,14 @@ func (q *FakeQuerier) GetUsersWithAccessToTemplateByID(ctx context.Context, id u
56235623
q.mutex.RLock()
56245624
defer q.mutex.RUnlock()
56255625

5626-
groups := make(map[string]bool, 0)
5626+
groups := make(map[string]struct{}, 0)
56275627
for _, template := range q.templates {
56285628
if template.ID != id {
56295629
continue
56305630
}
56315631

56325632
for group := range template.GroupACL {
5633-
groups[group] = true
5633+
groups[group] = struct{}{}
56345634
}
56355635
}
56365636

enterprise/coderd/templates_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"net/http"
7+
"slices"
78
"testing"
89
"time"
910

@@ -38,17 +39,19 @@ func TestTemplates(t *testing.T) {
3839
t.Run("Deprecated", func(t *testing.T) {
3940
t.Parallel()
4041

42+
notifyEnq := &testutil.FakeNotificationsEnqueuer{}
4143
owner, user := coderdenttest.New(t, &coderdenttest.Options{
4244
Options: &coderdtest.Options{
4345
IncludeProvisionerDaemon: true,
46+
NotificationsEnqueuer: notifyEnq,
4447
},
4548
LicenseOptions: &coderdenttest.LicenseOptions{
4649
Features: license.Features{
4750
codersdk.FeatureAccessControl: 1,
4851
},
4952
},
5053
})
51-
client, _ := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.RoleTemplateAdmin())
54+
client, anotherUser := coderdtest.CreateAnotherUser(t, owner, user.OrganizationID, rbac.RoleTemplateAdmin())
5255
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, nil)
5356
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
5457
coderdtest.AwaitTemplateVersionJobCompleted(t, client, version.ID)
@@ -65,6 +68,25 @@ func TestTemplates(t *testing.T) {
6568
assert.True(t, updated.Deprecated)
6669
assert.NotEmpty(t, updated.DeprecationMessage)
6770

71+
notifs := []*testutil.Notification{}
72+
for _, notif := range notifyEnq.Sent {
73+
if notif.TemplateID == notifications.TemplateTemplateDeprecated {
74+
notifs = append(notifs, notif)
75+
}
76+
}
77+
require.Equal(t, 2, len(notifs))
78+
79+
expectedSentTo := []string{user.UserID.String(), anotherUser.ID.String()}
80+
slices.Sort(expectedSentTo)
81+
82+
sentTo := []string{}
83+
for _, notif := range notifs {
84+
sentTo = append(sentTo, notif.UserID.String())
85+
}
86+
slices.Sort(sentTo)
87+
88+
assert.Equal(t, expectedSentTo, sentTo)
89+
6890
_, err = client.CreateWorkspace(ctx, user.OrganizationID, codersdk.Me, codersdk.CreateWorkspaceRequest{
6991
TemplateID: template.ID,
7092
Name: "foobar",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy