(t *testing.T)
| 230 | } |
| 231 | |
| 232 | func TestLogSender_SanitizeOutput(t *testing.T) { |
| 233 | t.Parallel() |
| 234 | testCtx := testutil.Context(t, testutil.WaitShort) |
| 235 | ctx, cancel := context.WithCancel(testCtx) |
| 236 | logger := testutil.Logger(t) |
| 237 | fDest := newFakeLogDest() |
| 238 | uut := NewLogSender(logger) |
| 239 | |
| 240 | t0 := dbtime.Now() |
| 241 | ls1 := uuid.UUID{0x11} |
| 242 | |
| 243 | uut.Enqueue(ls1, |
| 244 | Log{ |
| 245 | CreatedAt: t0, |
| 246 | Output: "test log 0, src 1\x00\xc3\x28", |
| 247 | Level: codersdk.LogLevelInfo, |
| 248 | }, |
| 249 | Log{ |
| 250 | CreatedAt: t0, |
| 251 | Output: "test log 1, src 1", |
| 252 | Level: codersdk.LogLevelInfo, |
| 253 | }) |
| 254 | |
| 255 | loopErr := make(chan error, 1) |
| 256 | go func() { |
| 257 | err := uut.SendLoop(ctx, fDest) |
| 258 | loopErr <- err |
| 259 | }() |
| 260 | |
| 261 | req := testutil.TryReceive(ctx, t, fDest.reqs) |
| 262 | require.NotNil(t, req) |
| 263 | require.Len(t, req.Logs, 2, "it should sanitize invalid output, but still send") |
| 264 | // The sanitizer replaces the NUL byte and invalid UTF-8 with ❌ while |
| 265 | // preserving the valid "(" byte that follows 0xc3. |
| 266 | require.Equal(t, "test log 0, src 1❌❌(", req.Logs[0].GetOutput()) |
| 267 | require.Equal(t, proto.Log_INFO, req.Logs[0].GetLevel()) |
| 268 | require.Equal(t, "test log 1, src 1", req.Logs[1].GetOutput()) |
| 269 | require.Equal(t, proto.Log_INFO, req.Logs[1].GetLevel()) |
| 270 | testutil.RequireSend(ctx, t, fDest.resps, &proto.BatchCreateLogsResponse{}) |
| 271 | |
| 272 | cancel() |
| 273 | err := testutil.TryReceive(testCtx, t, loopErr) |
| 274 | require.ErrorIs(t, err, context.Canceled) |
| 275 | } |
| 276 | |
| 277 | func TestLogSender_Batch(t *testing.T) { |
| 278 | t.Parallel() |
nothing calls this directly
no test coverage detected