(t *testing.T)
| 3193 | } |
| 3194 | |
| 3195 | func TestDecodeSSEPreservesMultiLineData(t *testing.T) { |
| 3196 | t.Parallel() |
| 3197 | |
| 3198 | body := strings.Join([]string{ |
| 3199 | "id: 1", |
| 3200 | "event: message", |
| 3201 | `data: {"first":true}`, |
| 3202 | `data: {"second":true}`, |
| 3203 | "", |
| 3204 | }, "\n") |
| 3205 | |
| 3206 | var seen SSEEvent |
| 3207 | err := decodeSSE(context.Background(), io.NopCloser(strings.NewReader(body)), func(event SSEEvent) error { |
| 3208 | seen = event |
| 3209 | return nil |
| 3210 | }) |
| 3211 | if err != nil { |
| 3212 | t.Fatalf("decodeSSE() error = %v", err) |
| 3213 | } |
| 3214 | if got, want := string(seen.Data), "{\"first\":true}\n{\"second\":true}"; got != want { |
| 3215 | t.Fatalf("decodeSSE() data = %q, want %q", got, want) |
| 3216 | } |
| 3217 | } |
| 3218 | |
| 3219 | func newHTTPResponse(status int, body string) *http.Response { |
| 3220 | return &http.Response{ |
nothing calls this directly
no test coverage detected