| 1764 | } |
| 1765 | |
| 1766 | func TestAutoDrainingReader(t *testing.T) { |
| 1767 | content := strings.NewReader("hello elasticsearch") |
| 1768 | wrapped := &autoDrainingReader{ReadCloser: &readCloser{Reader: content}} |
| 1769 | buf := make([]byte, 5) |
| 1770 | n, err := wrapped.Read(buf) |
| 1771 | if err != nil { |
| 1772 | t.Fatalf("Read error: %v", err) |
| 1773 | } |
| 1774 | if n != 5 { |
| 1775 | t.Errorf("expected 5 bytes, got %d", n) |
| 1776 | } |
| 1777 | if string(buf[:n]) != "hello" { |
| 1778 | t.Errorf("expected 'hello', got '%s'", string(buf[:n])) |
| 1779 | } |
| 1780 | if err := wrapped.Close(); err != nil { |
| 1781 | t.Fatalf("Close error: %v", err) |
| 1782 | } |
| 1783 | } |
| 1784 | |
| 1785 | func TestAutoDrainingReaderDrainsOnClose(t *testing.T) { |
| 1786 | content := bytes.Buffer{} |