31 lines
671 B
Go
31 lines
671 B
Go
package sse
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestForEachLineHandlesLargeLines(t *testing.T) {
|
|
largePayload := strings.Repeat("x", 128*1024)
|
|
input := "data: " + largePayload + "\n\n"
|
|
|
|
var lines []string
|
|
if err := ForEachLine(strings.NewReader(input), func(line string) error {
|
|
lines = append(lines, line)
|
|
return nil
|
|
}); err != nil {
|
|
t.Fatalf("ForEachLine() error = %v", err)
|
|
}
|
|
|
|
if len(lines) != 2 {
|
|
t.Fatalf("expected 2 lines, got %d", len(lines))
|
|
}
|
|
|
|
if lines[0] != "data: "+largePayload {
|
|
t.Fatalf("unexpected first line length: got %d", len(lines[0]))
|
|
}
|
|
|
|
if lines[1] != "" {
|
|
t.Fatalf("expected blank separator line, got %q", lines[1])
|
|
}
|
|
}
|