(t *testing.T)
| 180 | } |
| 181 | |
| 182 | func 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 | |
| 213 | func TestFrameReaderLineTooLong(t *testing.T) { |
| 214 | r := NewFrameReader(strings.NewReader("data: " + strings.Repeat("x", maxLineSize) + "\n\n")) |
nothing calls this directly
no test coverage detected