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

Function TestStartupLogsSender

codersdk/agentsdk/logs_test.go:276–418  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

274}
275
276func TestStartupLogsSender(t *testing.T) {
277 t.Parallel()
278
279 tests := []struct {
280 name string
281 sendCount int
282 discard []int
283 patchResp func(req agentsdk.PatchLogs) error
284 }{
285 {
286 name: "single log",
287 sendCount: 1,
288 },
289 {
290 name: "multiple logs",
291 sendCount: 995,
292 },
293 {
294 name: "too large",
295 sendCount: 1,
296 discard: []int{1},
297 patchResp: func(req agentsdk.PatchLogs) error {
298 return statusError(http.StatusRequestEntityTooLarge)
299 },
300 },
301 }
302 for _, tt := range tests {
303 t.Run(tt.name, func(t *testing.T) {
304 t.Parallel()
305
306 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitMedium)
307 defer cancel()
308
309 got := []agentsdk.Log{}
310 patchLogs := func(_ context.Context, req agentsdk.PatchLogs) error {
311 if tt.patchResp != nil {
312 err := tt.patchResp(req)
313 if err != nil {
314 return err
315 }
316 }
317 got = append(got, req.Logs...)
318 return nil
319 }
320
321 sendLog, flushAndClose := agentsdk.LogsSender(uuid.New(), patchLogs, testutil.Logger(t))
322 defer func() {
323 err := flushAndClose(ctx)
324 require.NoError(t, err)
325 }()
326
327 var want []agentsdk.Log
328 for i := 0; i < tt.sendCount; i++ {
329 want = append(want, agentsdk.Log{
330 CreatedAt: time.Now(),
331 Level: codersdk.LogLevelInfo,
332 Output: fmt.Sprintf("hello world %d", i),
333 })

Callers

nothing calls this directly

Calls 11

LogsSenderFunction · 0.92
LoggerFunction · 0.92
LogsSenderFlushTimeoutFunction · 0.92
statusErrorTypeAlias · 0.70
RunMethod · 0.65
NewMethod · 0.65
DeleteMethod · 0.65
EqualMethod · 0.45
FailMethod · 0.45
ErrorMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected