MCPcopy
hub / github.com/github/github-mcp-server / TestProcessResponseAsRingBufferToEnd

Function TestProcessResponseAsRingBufferToEnd

pkg/buffer/buffer_test.go:14–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestProcessResponseAsRingBufferToEnd(t *testing.T) {
15 t.Run("normal lines", func(t *testing.T) {
16 body := "line1\nline2\nline3\n"
17 resp := &http.Response{
18 Body: io.NopCloser(strings.NewReader(body)),
19 }
20
21 result, totalLines, respOut, err := ProcessResponseAsRingBufferToEnd(resp, 10)
22 if respOut != nil && respOut.Body != nil {
23 defer respOut.Body.Close()
24 }
25 require.NoError(t, err)
26 assert.Equal(t, 3, totalLines)
27 assert.Equal(t, "line1\nline2\nline3", result)
28 })
29
30 t.Run("ring buffer keeps last N lines", func(t *testing.T) {
31 body := "line1\nline2\nline3\nline4\nline5\n"
32 resp := &http.Response{
33 Body: io.NopCloser(strings.NewReader(body)),
34 }
35
36 result, totalLines, respOut, err := ProcessResponseAsRingBufferToEnd(resp, 3)
37 if respOut != nil && respOut.Body != nil {
38 defer respOut.Body.Close()
39 }
40 require.NoError(t, err)
41 assert.Equal(t, 5, totalLines)
42 assert.Equal(t, "line3\nline4\nline5", result)
43 })
44
45 t.Run("handles very long line exceeding 10MB", func(t *testing.T) {
46 // Create a line that exceeds maxLineSize (10MB)
47 longLine := strings.Repeat("x", 11*1024*1024) // 11MB
48 body := "line1\n" + longLine + "\nline3\n"
49 resp := &http.Response{
50 Body: io.NopCloser(strings.NewReader(body)),
51 }
52
53 result, totalLines, respOut, err := ProcessResponseAsRingBufferToEnd(resp, 100)
54 if respOut != nil && respOut.Body != nil {
55 defer respOut.Body.Close()
56 }
57 require.NoError(t, err)
58 // Should have processed lines with truncation marker
59 assert.Greater(t, totalLines, 0)
60 assert.Contains(t, result, "TRUNCATED")
61 })
62
63 t.Run("handles line at exactly max size", func(t *testing.T) {
64 // Create a line just under maxLineSize
65 longLine := strings.Repeat("a", 1024*1024) // 1MB - should work fine
66 body := "start\n" + longLine + "\nend\n"
67 resp := &http.Response{
68 Body: io.NopCloser(strings.NewReader(body)),
69 }
70
71 result, totalLines, respOut, err := ProcessResponseAsRingBufferToEnd(resp, 100)

Callers

nothing calls this directly

Calls 3

CloseMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected