MCPcopy Create free account
hub / github.com/cli/cli / TestFrameReaderSplitCRLFWithBufferedFrameEnd

Function TestFrameReaderSplitCRLFWithBufferedFrameEnd

internal/eventstream/sse_test.go:182–211  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

180}
181
182func TestFrameReaderSplitCRLFWithBufferedFrameEnd(t *testing.T) {
183 // The CR arrives alone, and the LF that completes it arrives together with the blank line that ends the frame.
184 // The stream then stays open, as it does between heartbeats.
185 body, w := io.Pipe()
186 t.Cleanup(func() { w.Close() })
187 go func() {
188 _, _ = w.Write([]byte("data: a\r"))
189 _, _ = w.Write([]byte("\n\r\n"))
190 }()
191
192 type result struct {
193 frame Frame
194 err error
195 }
196 done := make(chan result, 1)
197 go func() {
198 frame, err := NewFrameReader(body).Next()
199 done <- result{frame, err}
200 }()
201
202 select {
203 case res := <-done:
204 require.NoError(t, res.err)
205 assert.Equal(t, Frame{Event: "message", Data: "a"}, res.frame)
206 case <-time.After(5 * time.Second):
207 w.Close()
208 <-done
209 t.Fatal("the frame was not returned until the stream sent more bytes")
210 }
211}
212
213func TestFrameReaderLineTooLong(t *testing.T) {
214 r := NewFrameReader(strings.NewReader("data: " + strings.Repeat("x", maxLineSize) + "\n\n"))

Callers

nothing calls this directly

Calls 5

NewFrameReaderFunction · 0.85
NextMethod · 0.80
EqualMethod · 0.80
CloseMethod · 0.65
WriteMethod · 0.65

Tested by

no test coverage detected