(t *testing.T)
| 318 | } |
| 319 | |
| 320 | func TestReader_ReadStringInto_BufferTooSmall(t *testing.T) { |
| 321 | // Feed two consecutive bulk-string replies. The first read uses a |
| 322 | // too-small buf and must error; the second must succeed cleanly. This |
| 323 | // guards the drain-on-error behaviour — without it, the unread payload |
| 324 | // of the first reply would leak into the stream and the second read |
| 325 | // would parse garbage. |
| 326 | src := []byte("$5\r\nhello\r\n$5\r\nworld\r\n") |
| 327 | r := proto.NewReader(bytes.NewReader(src)) |
| 328 | |
| 329 | smallBuf := make([]byte, 3) |
| 330 | n, err := r.ReadStringInto(smallBuf) |
| 331 | if err == nil { |
| 332 | t.Fatal("expected buffer-too-small error, got nil") |
| 333 | } |
| 334 | if n != 0 { |
| 335 | t.Fatalf("got n=%d on error, want 0", n) |
| 336 | } |
| 337 | |
| 338 | // After the drain, the reader is aligned at the start of the second |
| 339 | // reply. A normal read must parse it as "world". |
| 340 | bigBuf := make([]byte, 16) |
| 341 | n, err = r.ReadStringInto(bigBuf) |
| 342 | if err != nil { |
| 343 | t.Fatalf("follow-up ReadStringInto: %v (connection left misaligned by the buffer-too-small drain)", err) |
| 344 | } |
| 345 | if n != 5 || string(bigBuf[:n]) != "world" { |
| 346 | t.Fatalf("follow-up: got n=%d %q, want 5 \"world\"", n, bigBuf[:n]) |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | func TestReader_ReadStringInto_Large(t *testing.T) { |
| 351 | // Payload deliberately larger than the default bufio buffer (32 KiB) |
nothing calls this directly
no test coverage detected
searching dependent graphs…