minor: refactoring names
Vladimir Bauer
3 years ago
| 29 | 29 | func TestProxyReader(t *testing.T) { |
| 30 | 30 | p := mpb.New(mpb.WithOutput(io.Discard)) |
| 31 | 31 | |
| 32 | reader := &testReader{strings.NewReader(content), false} | |
| 32 | tr := &testReader{strings.NewReader(content), false} | |
| 33 | 33 | |
| 34 | bar := p.AddBar(int64(len(content))) | |
| 34 | bar := p.New(int64(len(content)), mpb.NopStyle()) | |
| 35 | 35 | |
| 36 | 36 | var buf bytes.Buffer |
| 37 | _, err := io.Copy(&buf, bar.ProxyReader(reader)) | |
| 37 | _, err := io.Copy(&buf, bar.ProxyReader(tr)) | |
| 38 | 38 | if err != nil { |
| 39 | t.Errorf("Error copying from reader: %+v\n", err) | |
| 39 | t.Errorf("io.Copy: %s\n", err.Error()) | |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | p.Wait() |
| 43 | 43 | |
| 44 | if !reader.called { | |
| 44 | if !tr.called { | |
| 45 | 45 | t.Error("Read not called") |
| 46 | 46 | } |
| 47 | 47 | |
| 63 | 63 | func TestProxyReadCloser(t *testing.T) { |
| 64 | 64 | p := mpb.New(mpb.WithOutput(io.Discard)) |
| 65 | 65 | |
| 66 | reader := &testReadCloser{strings.NewReader(content), false} | |
| 66 | tr := &testReadCloser{strings.NewReader(content), false} | |
| 67 | 67 | |
| 68 | bar := p.AddBar(int64(len(content))) | |
| 68 | bar := p.New(int64(len(content)), mpb.NopStyle()) | |
| 69 | 69 | |
| 70 | rc := bar.ProxyReader(reader) | |
| 71 | _, _ = io.Copy(io.Discard, rc) | |
| 70 | rc := bar.ProxyReader(tr) | |
| 71 | _, err := io.Copy(io.Discard, rc) | |
| 72 | if err != nil { | |
| 73 | t.Errorf("io.Copy: %s\n", err.Error()) | |
| 74 | } | |
| 72 | 75 | _ = rc.Close() |
| 73 | 76 | |
| 74 | 77 | p.Wait() |
| 75 | 78 | |
| 76 | if !reader.called { | |
| 79 | if !tr.called { | |
| 77 | 80 | t.Error("Close not called") |
| 78 | 81 | } |
| 79 | 82 | } |
| 80 | 83 | |
| 81 | type testWriterTo struct { | |
| 84 | type testReaderWriterTo struct { | |
| 82 | 85 | io.Reader |
| 83 | 86 | called bool |
| 84 | 87 | } |
| 85 | 88 | |
| 86 | func (wt *testWriterTo) WriteTo(w io.Writer) (n int64, err error) { | |
| 87 | wt.called = true | |
| 88 | return wt.Reader.(io.WriterTo).WriteTo(w) | |
| 89 | func (r *testReaderWriterTo) WriteTo(w io.Writer) (n int64, err error) { | |
| 90 | r.called = true | |
| 91 | return r.Reader.(io.WriterTo).WriteTo(w) | |
| 89 | 92 | } |
| 90 | 93 | |
| 91 | func TestProxyWriterTo(t *testing.T) { | |
| 94 | func TestProxyReaderWriterTo(t *testing.T) { | |
| 92 | 95 | p := mpb.New(mpb.WithOutput(io.Discard)) |
| 93 | 96 | |
| 94 | writerTo := &testWriterTo{strings.NewReader(content), false} | |
| 97 | tr := &testReaderWriterTo{strings.NewReader(content), false} | |
| 95 | 98 | |
| 96 | bar := p.AddBar(int64(len(content))) | |
| 99 | bar := p.New(int64(len(content)), mpb.NopStyle()) | |
| 97 | 100 | |
| 98 | 101 | var buf bytes.Buffer |
| 99 | _, err := io.Copy(&buf, bar.ProxyReader(writerTo)) | |
| 102 | _, err := io.Copy(&buf, bar.ProxyReader(tr)) | |
| 100 | 103 | if err != nil { |
| 101 | t.Errorf("Error copying from reader: %+v\n", err) | |
| 104 | t.Errorf("io.Copy: %s\n", err.Error()) | |
| 102 | 105 | } |
| 103 | 106 | |
| 104 | 107 | p.Wait() |
| 105 | 108 | |
| 106 | if !writerTo.called { | |
| 109 | if !tr.called { | |
| 107 | 110 | t.Error("WriteTo not called") |
| 108 | 111 | } |
| 109 | 112 | |