Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a0e0f2

Browse files
committed
CI
Signed-off-by: Danny Kopping <danny@coder.com>
1 parentb7c9ca8 commit4a0e0f2

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

‎codersdk/notifications.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ func (c *Client) PutNotificationsSettings(ctx context.Context, settings Notifica
6161

6262
// UpdateNotificationTemplateMethod modifies a notification template to use a specific notification method, overriding
6363
// the method set in the deployment configuration.
64-
func (c*Client)UpdateNotificationTemplateMethod(ctx context.Context,notificationTemplateId uuid.UUID,methodstring)error {
64+
func (c*Client)UpdateNotificationTemplateMethod(ctx context.Context,notificationTemplateID uuid.UUID,methodstring)error {
6565
res,err:=c.Request(ctx,http.MethodPut,
66-
fmt.Sprintf("/api/v2/notifications/templates/%s/method",notificationTemplateId),
66+
fmt.Sprintf("/api/v2/notifications/templates/%s/method",notificationTemplateID),
6767
UpdateNotificationTemplateMethod{Method:method},
6868
)
6969
iferr!=nil {

‎enterprise/coderd/notifications_test.go

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,14 @@ import (
1919
"github.com/coder/coder/v2/testutil"
2020
)
2121

22-
funccreateOpts(t*testing.T,usePostgresbool)*coderdenttest.Options {
22+
funccreateOpts(t*testing.T)*coderdenttest.Options {
2323
t.Helper()
2424

25-
ifusePostgres {
26-
if!dbtestutil.WillUsePostgres() {
27-
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
28-
}
29-
}
30-
31-
db,ps:=dbtestutil.NewDB(t)
32-
3325
dt:=coderdtest.DeploymentValues(t)
3426
dt.Experiments= []string{string(codersdk.ExperimentNotifications)}
3527
return&coderdenttest.Options{
3628
Options:&coderdtest.Options{
3729
DeploymentValues:dt,
38-
Database:db,
39-
Pubsub:ps,
4030
},
4131
}
4232
}
@@ -47,16 +37,20 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
4737
t.Run("Happy path",func(t*testing.T) {
4838
t.Parallel()
4939

40+
if!dbtestutil.WillUsePostgres() {
41+
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
42+
}
43+
5044
ctx:=testutil.Context(t,testutil.WaitSuperLong)
51-
api,_:=coderdenttest.New(t,createOpts(t,true))
45+
api,_:=coderdenttest.New(t,createOpts(t))
5246

5347
var (
5448
method=string(database.NotificationMethodSmtp)
5549
templateID=notifications.TemplateWorkspaceDeleted
5650
)
5751

5852
// Given: a template whose method is initially empty (i.e. deferring to the global method value).
59-
template,err:=getTemplateById(t,ctx,api,templateID)
53+
template,err:=getTemplateByID(t,ctx,api,templateID)
6054
require.NoError(t,err)
6155
require.NotNil(t,template)
6256
require.Empty(t,template.Method)
@@ -65,7 +59,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
6559
require.NoError(t,api.UpdateNotificationTemplateMethod(ctx,notifications.TemplateWorkspaceDeleted,method),"initial request to set the method failed")
6660

6761
// Then: the method should be set.
68-
template,err=getTemplateById(t,ctx,api,templateID)
62+
template,err=getTemplateByID(t,ctx,api,templateID)
6963
require.NoError(t,err)
7064
require.NotNil(t,template)
7165
require.Equal(t,method,template.Method)
@@ -74,10 +68,14 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
7468
t.Run("Insufficient permissions",func(t*testing.T) {
7569
t.Parallel()
7670

71+
if!dbtestutil.WillUsePostgres() {
72+
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
73+
}
74+
7775
ctx:=testutil.Context(t,testutil.WaitSuperLong)
7876

7977
// Given: the first user which has an "owner" role, and another user which does not.
80-
api,firstUser:=coderdenttest.New(t,createOpts(t,false))
78+
api,firstUser:=coderdenttest.New(t,createOpts(t))
8179
anotherClient,_:=coderdtest.CreateAnotherUser(t,api,firstUser.OrganizationID)
8280

8381
// When: calling the API as an unprivileged user.
@@ -94,13 +92,19 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
9492
t.Run("Invalid notification method",func(t*testing.T) {
9593
t.Parallel()
9694

95+
if!dbtestutil.WillUsePostgres() {
96+
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
97+
}
98+
9799
ctx:=testutil.Context(t,testutil.WaitSuperLong)
98100

99101
// Given: the first user which has an "owner" role
100-
api,_:=coderdenttest.New(t,createOpts(t,true))
102+
api,_:=coderdenttest.New(t,createOpts(t))
101103

102104
// When: calling the API with an invalid method.
103105
constmethod="nope"
106+
107+
// nolint:gocritic // Using an owner-scope user is kinda the point.
104108
err:=api.UpdateNotificationTemplateMethod(ctx,notifications.TemplateWorkspaceDeleted,method)
105109

106110
// Then: the request is invalid because of the unacceptable method.
@@ -117,15 +121,19 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
117121
t.Run("Not modified",func(t*testing.T) {
118122
t.Parallel()
119123

124+
if!dbtestutil.WillUsePostgres() {
125+
t.Skip("This test requires postgres; it relies on read from and writing to the notification_templates table")
126+
}
127+
120128
ctx:=testutil.Context(t,testutil.WaitSuperLong)
121-
api,_:=coderdenttest.New(t,createOpts(t,true))
129+
api,_:=coderdenttest.New(t,createOpts(t))
122130

123131
var (
124132
method=string(database.NotificationMethodSmtp)
125133
templateID=notifications.TemplateWorkspaceDeleted
126134
)
127135

128-
template,err:=getTemplateById(t,ctx,api,templateID)
136+
template,err:=getTemplateByID(t,ctx,api,templateID)
129137
require.NoError(t,err)
130138
require.NotNil(t,template)
131139

@@ -134,38 +142,39 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
134142

135143
// When: calling the API to update the method, it should set it.
136144
require.NoError(t,api.UpdateNotificationTemplateMethod(ctx,notifications.TemplateWorkspaceDeleted,method),"initial request to set the method failed")
137-
template,err=getTemplateById(t,ctx,api,templateID)
145+
template,err=getTemplateByID(t,ctx,api,templateID)
138146
require.NoError(t,err)
139147
require.NotNil(t,template)
140148
require.Equal(t,method,template.Method)
141149

142150
// Then: when calling the API again with the same method, the method will remain unchanged.
143151
require.NoError(t,api.UpdateNotificationTemplateMethod(ctx,notifications.TemplateWorkspaceDeleted,method),"second request to set the method failed")
144-
template,err=getTemplateById(t,ctx,api,templateID)
152+
template,err=getTemplateByID(t,ctx,api,templateID)
145153
require.NoError(t,err)
146154
require.NotNil(t,template)
147155
require.Equal(t,method,template.Method)
148156
})
149157
}
150158

151-
funcgetTemplateById(t*testing.T,ctx context.Context,api*codersdk.Client,id uuid.UUID) (*codersdk.NotificationTemplate,error) {
159+
// nolint:revive // t takes precedence.
160+
funcgetTemplateByID(t*testing.T,ctx context.Context,api*codersdk.Client,id uuid.UUID) (*codersdk.NotificationTemplate,error) {
152161
t.Helper()
153162

154-
vartemplate*codersdk.NotificationTemplate
163+
vartemplate codersdk.NotificationTemplate
155164
templates,err:=api.GetSystemNotificationTemplates(ctx)
156165
iferr!=nil {
157166
returnnil,err
158167
}
159168

160169
for_,tmpl:=rangetemplates {
161170
iftmpl.ID==id {
162-
template=&tmpl
171+
template=tmpl
163172
}
164173
}
165174

166-
iftemplate==nil {
175+
iftemplate.ID==uuid.Nil {
167176
returnnil,xerrors.Errorf("template not found: %q",id.String())
168177
}
169178

170-
returntemplate,nil
179+
return&template,nil
171180
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp