MCPcopy
hub / github.com/elastic/go-elasticsearch / TestAutoDrainingReader

Function TestAutoDrainingReader

elasticsearch_internal_test.go:1766–1783  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1764}
1765
1766func 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
1785func TestAutoDrainingReaderDrainsOnClose(t *testing.T) {
1786 content := bytes.Buffer{}

Callers

nothing calls this directly

Calls 2

CloseMethod · 0.95
ReadMethod · 0.45

Tested by

no test coverage detected