(t *testing.T)
| 3099 | } |
| 3100 | |
| 3101 | func TestDecodeSSEStopsEarly(t *testing.T) { |
| 3102 | t.Parallel() |
| 3103 | |
| 3104 | body := strings.Join([]string{ |
| 3105 | "id: 1", |
| 3106 | "event: done", |
| 3107 | `data: {"ok":true}`, |
| 3108 | "", |
| 3109 | "id: 2", |
| 3110 | "event: later", |
| 3111 | `data: {"ok":false}`, |
| 3112 | "", |
| 3113 | }, "\n") |
| 3114 | |
| 3115 | count := 0 |
| 3116 | err := decodeSSE(context.Background(), io.NopCloser(strings.NewReader(body)), func(event SSEEvent) error { |
| 3117 | count++ |
| 3118 | if event.Event == "done" { |
| 3119 | return errStopSSE |
| 3120 | } |
| 3121 | return nil |
| 3122 | }) |
| 3123 | if err != nil { |
| 3124 | t.Fatalf("decodeSSE() error = %v", err) |
| 3125 | } |
| 3126 | if count != 1 { |
| 3127 | t.Fatalf("decodeSSE() count = %d, want 1", count) |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | func TestDecodeSSERejectsNilArguments(t *testing.T) { |
| 3132 | t.Parallel() |
nothing calls this directly
no test coverage detected