MCPcopy Create free account
hub / github.com/coder/coder / Test_logFollower_EndOfLogs

Function Test_logFollower_EndOfLogs

coderd/provisionerjobs_internal_test.go:286–391  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

284}
285
286func Test_logFollower_EndOfLogs(t *testing.T) {
287 t.Parallel()
288 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
289 defer cancel()
290 logger := testutil.Logger(t)
291 ctrl := gomock.NewController(t)
292 mDB := dbmock.NewMockStore(ctrl)
293 ps := pubsub.NewInMemory()
294 now := dbtime.Now()
295 job := database.ProvisionerJob{
296 ID: uuid.New(),
297 CreatedAt: now.Add(-10 * time.Second),
298 UpdatedAt: now.Add(-10 * time.Second),
299 StartedAt: sql.NullTime{
300 Time: now.Add(-10 * time.Second),
301 Valid: true,
302 },
303 CanceledAt: sql.NullTime{},
304 CompletedAt: sql.NullTime{},
305 Error: sql.NullString{},
306 JobStatus: database.ProvisionerJobStatusRunning,
307 }
308
309 mockLogger := loggermock.NewMockRequestLogger(ctrl)
310 mockLogger.EXPECT().WriteLog(gomock.Any(), http.StatusAccepted).Times(1)
311 ctx = loggermw.WithRequestLogger(ctx, mockLogger)
312
313 // we need an HTTP server to get a websocket
314 srv := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
315 uut := newLogFollower(ctx, logger, mDB, ps, rw, r, job, 0)
316 uut.follow()
317 }))
318
319 defer srv.Close()
320
321 // job was incomplete when we create the logFollower, and still incomplete when it queries
322 mDB.EXPECT().GetProvisionerJobByID(gomock.Any(), job.ID).Times(1).Return(job, nil)
323
324 // return some historical logs
325 q0 := mDB.EXPECT().GetProvisionerLogsAfterID(gomock.Any(), matchesJobAfter(job.ID, 0)).
326 Times(1).
327 Return(
328 []database.ProvisionerJobLog{
329 {Stage: "One", Output: "One", ID: 1},
330 {Stage: "One", Output: "Two", ID: 2},
331 },
332 nil,
333 )
334 // return some logs from a kick.
335 mDB.EXPECT().GetProvisionerLogsAfterID(gomock.Any(), matchesJobAfter(job.ID, 2)).
336 After(q0).
337 Times(1).
338 Return(
339 []database.ProvisionerJobLog{
340 {Stage: "One", Output: "Three", ID: 3},
341 {Stage: "Two", Output: "One", ID: 4},
342 },
343 nil,

Callers

nothing calls this directly

Calls 15

EXPECTMethod · 0.95
CloseMethod · 0.95
EXPECTMethod · 0.95
LoggerFunction · 0.92
NewMockStoreFunction · 0.92
NewInMemoryFunction · 0.92
NowFunction · 0.92
NewMockRequestLoggerFunction · 0.92
WithRequestLoggerFunction · 0.92
newLogFollowerFunction · 0.85
matchesJobAfterFunction · 0.85

Tested by

no test coverage detected