(t *testing.T)
| 157 | } |
| 158 | |
| 159 | func TestRunWithSMTP(t *testing.T) { |
| 160 | t.Parallel() |
| 161 | |
| 162 | ctx := testutil.Context(t, testutil.WaitLong) |
| 163 | logger := testutil.Logger(t) |
| 164 | db, ps := dbtestutil.NewDB(t) |
| 165 | |
| 166 | inboxHandler := dispatch.NewInboxHandler(logger.Named("inbox"), db, ps) |
| 167 | |
| 168 | client := coderdtest.New(t, &coderdtest.Options{ |
| 169 | Database: db, |
| 170 | Pubsub: ps, |
| 171 | }) |
| 172 | firstUser := coderdtest.CreateFirstUser(t, client) |
| 173 | |
| 174 | smtpAPIMux := http.NewServeMux() |
| 175 | smtpAPIMux.HandleFunc("/messages", func(w http.ResponseWriter, r *http.Request) { |
| 176 | summaries := []smtpmock.EmailSummary{ |
| 177 | { |
| 178 | Subject: "TemplateUserAccountCreated", |
| 179 | Date: time.Now(), |
| 180 | NotificationTemplateID: notificationsLib.TemplateUserAccountCreated, |
| 181 | }, |
| 182 | { |
| 183 | Subject: "TemplateUserAccountDeleted", |
| 184 | Date: time.Now(), |
| 185 | NotificationTemplateID: notificationsLib.TemplateUserAccountDeleted, |
| 186 | }, |
| 187 | } |
| 188 | |
| 189 | w.Header().Set("Content-Type", "application/json") |
| 190 | _ = json.NewEncoder(w).Encode(summaries) |
| 191 | }) |
| 192 | |
| 193 | smtpAPIServer := httptest.NewServer(smtpAPIMux) |
| 194 | defer smtpAPIServer.Close() |
| 195 | |
| 196 | const numReceivingUsers = 2 |
| 197 | const numRegularUsers = 2 |
| 198 | dialBarrier := new(sync.WaitGroup) |
| 199 | receivingWatchBarrier := new(sync.WaitGroup) |
| 200 | dialBarrier.Add(numReceivingUsers + numRegularUsers) |
| 201 | receivingWatchBarrier.Add(numReceivingUsers) |
| 202 | metrics := notifications.NewMetrics(prometheus.NewRegistry()) |
| 203 | |
| 204 | eg, runCtx := errgroup.WithContext(ctx) |
| 205 | |
| 206 | expectedNotificationsIDs := map[uuid.UUID]struct{}{ |
| 207 | notificationsLib.TemplateUserAccountCreated: {}, |
| 208 | notificationsLib.TemplateUserAccountDeleted: {}, |
| 209 | } |
| 210 | |
| 211 | mClock := quartz.NewMock(t) |
| 212 | smtpTrap := mClock.Trap().TickerFunc("smtp") |
| 213 | defer smtpTrap.Close() |
| 214 | |
| 215 | httpClient := &http.Client{} |
| 216 |
nothing calls this directly
no test coverage detected