(t *testing.T)
| 91 | } |
| 92 | |
| 93 | func TestStreamWriter(t *testing.T) { |
| 94 | var lines []string |
| 95 | sw := NewStreamWriter(func(line string) { |
| 96 | lines = append(lines, line) |
| 97 | }) |
| 98 | |
| 99 | if _, err := sw.Write([]byte("hello\nworld\n")); err != nil { |
| 100 | t.Fatal(err) |
| 101 | } |
| 102 | if len(lines) != 2 || lines[0] != "hello" || lines[1] != "world" { |
| 103 | t.Errorf("expected [hello, world], got %v", lines) |
| 104 | } |
| 105 | |
| 106 | lines = nil |
| 107 | if _, err := sw.Write([]byte("partial")); err != nil { |
| 108 | t.Fatal(err) |
| 109 | } |
| 110 | if len(lines) != 0 { |
| 111 | t.Errorf("expected no lines for partial, got %v", lines) |
| 112 | } |
| 113 | |
| 114 | if _, err := sw.Write([]byte(" data\n")); err != nil { |
| 115 | t.Fatal(err) |
| 116 | } |
| 117 | if len(lines) != 1 || lines[0] != "partial data" { |
| 118 | t.Errorf("expected [partial data], got %v", lines) |
| 119 | } |
| 120 | |
| 121 | lines = nil |
| 122 | if _, err := sw.Write([]byte("final")); err != nil { |
| 123 | t.Fatal(err) |
| 124 | } |
| 125 | sw.Flush() |
| 126 | if len(lines) != 1 || lines[0] != "final" { |
| 127 | t.Errorf("expected [final] after flush, got %v", lines) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | func TestStreamWriterCRLF(t *testing.T) { |
| 132 | var lines []string |
nothing calls this directly
no test coverage detected