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

Function TestNotifier_FetchAppName

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

Source from the content-addressed store, hash-verified

83}
84
85func TestNotifier_FetchAppName(t *testing.T) {
86 t.Parallel()
87
88 t.Run("ok", func(t *testing.T) {
89 t.Parallel()
90
91 ctrl := gomock.NewController(t)
92 dbmock := dbmock.NewMockStore(ctrl)
93
94 n := &notifier{
95 store: dbmock,
96 }
97
98 dbmock.EXPECT().GetApplicationName(gomock.Any()).Return("ACME Inc.", nil)
99
100 ctx := context.Background()
101 appName, err := n.fetchAppName(ctx)
102 require.NoError(t, err)
103 require.Equal(t, "ACME Inc.", appName)
104 })
105
106 t.Run("No rows", func(t *testing.T) {
107 t.Parallel()
108 ctrl := gomock.NewController(t)
109 dbmock := dbmock.NewMockStore(ctrl)
110
111 n := &notifier{
112 store: dbmock,
113 }
114
115 dbmock.EXPECT().GetApplicationName(gomock.Any()).Return("", sql.ErrNoRows)
116
117 ctx := context.Background()
118 appName, err := n.fetchAppName(ctx)
119 require.NoError(t, err)
120 require.Equal(t, notificationsDefaultAppName, appName)
121 })
122
123 t.Run("Empty string", func(t *testing.T) {
124 t.Parallel()
125
126 ctrl := gomock.NewController(t)
127 dbmock := dbmock.NewMockStore(ctrl)
128
129 n := &notifier{
130 store: dbmock,
131 }
132
133 dbmock.EXPECT().GetApplicationName(gomock.Any()).Return("", nil)
134
135 ctx := context.Background()
136 appName, err := n.fetchAppName(ctx)
137 require.NoError(t, err)
138 require.Equal(t, notificationsDefaultAppName, appName)
139 })
140
141 t.Run("internal error", func(t *testing.T) {
142 t.Parallel()

Callers

nothing calls this directly

Calls 7

EXPECTMethod · 0.95
fetchAppNameMethod · 0.95
RunMethod · 0.65
GetApplicationNameMethod · 0.65
NewMethod · 0.65
EqualMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected