MCPcopy Index your code
hub / github.com/coder/coder / TestNotificationDispatchMethods

Function TestNotificationDispatchMethods

coderd/notifications_test.go:273–323  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

271}
272
273func TestNotificationDispatchMethods(t *testing.T) {
274 t.Parallel()
275
276 defaultOpts := createOpts(t)
277 webhookOpts := createOpts(t)
278 webhookOpts.DeploymentValues.Notifications.Method = serpent.String(database.NotificationMethodWebhook)
279
280 tests := []struct {
281 name string
282 opts *coderdtest.Options
283 expectedDefault string
284 }{
285 {
286 name: "default",
287 opts: defaultOpts,
288 expectedDefault: string(database.NotificationMethodSmtp),
289 },
290 {
291 name: "non-default",
292 opts: webhookOpts,
293 expectedDefault: string(database.NotificationMethodWebhook),
294 },
295 }
296
297 var allMethods []string
298 for _, nm := range database.AllNotificationMethodValues() {
299 if nm == database.NotificationMethodInbox {
300 continue
301 }
302 allMethods = append(allMethods, string(nm))
303 }
304 slices.Sort(allMethods)
305
306 // nolint:paralleltest // Not since Go v1.22.
307 for _, tc := range tests {
308 t.Run(tc.name, func(t *testing.T) {
309 t.Parallel()
310
311 ctx := testutil.Context(t, testutil.WaitSuperLong)
312 api := coderdtest.New(t, tc.opts)
313 _ = coderdtest.CreateFirstUser(t, api)
314
315 resp, err := api.GetNotificationDispatchMethods(ctx)
316 require.NoError(t, err)
317
318 slices.Sort(resp.AvailableNotificationMethods)
319 require.EqualValues(t, resp.AvailableNotificationMethods, allMethods)
320 require.Equal(t, tc.expectedDefault, resp.DefaultNotificationMethod)
321 })
322 }
323}
324
325func TestNotificationTest(t *testing.T) {
326 t.Parallel()

Callers

nothing calls this directly

Calls 9

ContextFunction · 0.92
NewFunction · 0.92
CreateFirstUserFunction · 0.92
createOptsFunction · 0.70
RunMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected