MCPcopy Index your code
hub / github.com/imroc/req / TestChunkReadPartial

Function TestChunkReadPartial

internal/chunked_test.go:191–214  ·  view source on GitHub ↗

Issue 17355: ChunkedReader shouldn't block waiting for more data if it can return something.

(t *testing.T)

Source from the content-addressed store, hash-verified

189// Issue 17355: ChunkedReader shouldn't block waiting for more data
190// if it can return something.
191func TestChunkReadPartial(t *testing.T) {
192 pr, pw := io.Pipe()
193 go func() {
194 pw.Write([]byte("7\r\n1234567"))
195 }()
196 cr := NewChunkedReader(pr)
197 readBuf := make([]byte, 7)
198 n, err := cr.Read(readBuf)
199 if err != nil {
200 t.Fatal(err)
201 }
202 want := "1234567"
203 if n != 7 || string(readBuf) != want {
204 t.Fatalf("Read: %v %q; want %d, %q", n, readBuf[:n], len(want), want)
205 }
206 go func() {
207 pw.Write([]byte("xx"))
208 }()
209 _, err = cr.Read(readBuf)
210 if got := fmt.Sprint(err); !strings.Contains(got, "malformed") {
211 t.Fatalf("second read = %v; want malformed error", err)
212 }
213
214}
215
216// Issue 48861: ChunkedReader should report incomplete chunks
217func TestIncompleteChunk(t *testing.T) {

Callers

nothing calls this directly

Calls 3

NewChunkedReaderFunction · 0.85
WriteMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…