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

Function TestLogSender_SanitizeOutput

codersdk/agentsdk/logs_internal_test.go:232–275  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

230}
231
232func 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
277func TestLogSender_Batch(t *testing.T) {
278 t.Parallel()

Callers

nothing calls this directly

Calls 13

EnqueueMethod · 0.95
SendLoopMethod · 0.95
ContextFunction · 0.92
LoggerFunction · 0.92
NowFunction · 0.92
TryReceiveFunction · 0.92
RequireSendFunction · 0.92
newFakeLogDestFunction · 0.85
NewLogSenderFunction · 0.85
LenMethod · 0.45
EqualMethod · 0.45
GetOutputMethod · 0.45

Tested by

no test coverage detected