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

Function TestHeadTailBuffer_RingBufferWraparound

agent/agentproc/headtail_test.go:296–320  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

294}
295
296func TestHeadTailBuffer_RingBufferWraparound(t *testing.T) {
297 t.Parallel()
298
299 // Use a tail of 10 bytes and write enough to wrap
300 // around multiple times.
301 buf := agentproc.NewHeadTailBufferSized(5, 10)
302
303 // Fill head (5 bytes).
304 _, err := buf.Write([]byte("HEADD"))
305 require.NoError(t, err)
306
307 // Write 25 bytes into tail, wrapping 2.5 times.
308 _, err = buf.Write([]byte("0123456789"))
309 require.NoError(t, err)
310 _, err = buf.Write([]byte("abcdefghij"))
311 require.NoError(t, err)
312 _, err = buf.Write([]byte("ABCDE"))
313 require.NoError(t, err)
314
315 out, info := buf.Output()
316 require.NotNil(t, info)
317 // Tail should contain the last 10 bytes: "fghijABCDE".
318 require.True(t, strings.HasSuffix(out, "fghijABCDE"),
319 "expected tail to be last 10 bytes, got: %q", out)
320}
321
322func TestHeadTailBuffer_MultipleLinesTruncated(t *testing.T) {
323 t.Parallel()

Callers

nothing calls this directly

Calls 3

NewHeadTailBufferSizedFunction · 0.92
WriteMethod · 0.65
OutputMethod · 0.65

Tested by

no test coverage detected