MCPcopy Create free account
hub / github.com/diillson/chatcli / TestStreamWriter

Function TestStreamWriter

pkg/coder/engine/engine_test.go:93–129  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

91}
92
93func 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
131func TestStreamWriterCRLF(t *testing.T) {
132 var lines []string

Callers

nothing calls this directly

Calls 4

WriteMethod · 0.95
FlushMethod · 0.95
NewStreamWriterFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected