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

Function TestHeadTailBuffer_LargeOutputTruncation

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

Source from the content-addressed store, hash-verified

88}
89
90func TestHeadTailBuffer_LargeOutputTruncation(t *testing.T) {
91 t.Parallel()
92
93 // Use small head/tail so truncation is easy to verify.
94 buf := agentproc.NewHeadTailBufferSized(10, 10)
95
96 // Write 100 bytes: head=10, tail=10, omitted=80.
97 data := strings.Repeat("A", 50) + strings.Repeat("Z", 50)
98 n, err := buf.Write([]byte(data))
99 require.NoError(t, err)
100 require.Equal(t, 100, n)
101
102 out, info := buf.Output()
103 require.NotNil(t, info)
104 require.Equal(t, 100, info.OriginalBytes)
105 require.Equal(t, 80, info.OmittedBytes)
106 require.Equal(t, "head_tail", info.Strategy)
107
108 // Head should be first 10 bytes (all A's).
109 require.True(t, strings.HasPrefix(out, "AAAAAAAAAA"))
110 // Tail should be last 10 bytes (all Z's).
111 require.True(t, strings.HasSuffix(out, "ZZZZZZZZZZ"))
112 // Omission marker should be present.
113 require.Contains(t, out, "... [omitted 80 bytes] ...")
114
115 require.Equal(t, 20, buf.Len())
116 require.Equal(t, 100, buf.TotalWritten())
117}
118
119func TestHeadTailBuffer_MultiMBStaysBounded(t *testing.T) {
120 t.Parallel()

Callers

nothing calls this directly

Calls 7

NewHeadTailBufferSizedFunction · 0.92
TotalWrittenMethod · 0.80
WriteMethod · 0.65
OutputMethod · 0.65
EqualMethod · 0.45
ContainsMethod · 0.45
LenMethod · 0.45

Tested by

no test coverage detected