(t *testing.T)
| 274 | } |
| 275 | |
| 276 | func 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 | }) |
nothing calls this directly
no test coverage detected