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

Function TestNotifier_FetchHelpers

coderd/notifications/fetcher_internal_test.go:16–83  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestNotifier_FetchHelpers(t *testing.T) {
17 t.Parallel()
18
19 t.Run("ok", func(t *testing.T) {
20 t.Parallel()
21
22 ctrl := gomock.NewController(t)
23 dbmock := dbmock.NewMockStore(ctrl)
24
25 n := &notifier{
26 store: dbmock,
27 helpers: template.FuncMap{},
28 }
29
30 dbmock.EXPECT().GetApplicationName(gomock.Any()).Return("ACME Inc.", nil)
31 dbmock.EXPECT().GetLogoURL(gomock.Any()).Return("https://example.com/logo.png", nil)
32
33 ctx := context.Background()
34 helpers, err := n.fetchHelpers(ctx)
35 require.NoError(t, err)
36
37 appName, ok := helpers["app_name"].(func() string)
38 require.True(t, ok)
39 require.Equal(t, "ACME Inc.", appName())
40
41 logoURL, ok := helpers["logo_url"].(func() string)
42 require.True(t, ok)
43 require.Equal(t, "https://example.com/logo.png", logoURL())
44 })
45
46 t.Run("failed to fetch app name", func(t *testing.T) {
47 t.Parallel()
48
49 ctrl := gomock.NewController(t)
50 dbmock := dbmock.NewMockStore(ctrl)
51
52 n := &notifier{
53 store: dbmock,
54 helpers: template.FuncMap{},
55 }
56
57 dbmock.EXPECT().GetApplicationName(gomock.Any()).Return("", xerrors.New("internal error"))
58
59 ctx := context.Background()
60 _, err := n.fetchHelpers(ctx)
61 require.Error(t, err)
62 require.ErrorContains(t, err, "get application name")
63 })
64
65 t.Run("failed to fetch logo URL", func(t *testing.T) {
66 t.Parallel()
67
68 ctrl := gomock.NewController(t)
69 dbmock := dbmock.NewMockStore(ctrl)
70
71 n := &notifier{
72 store: dbmock,
73 helpers: template.FuncMap{},

Callers

nothing calls this directly

Calls 8

EXPECTMethod · 0.95
fetchHelpersMethod · 0.95
RunMethod · 0.65
GetApplicationNameMethod · 0.65
GetLogoURLMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected