Codebase list golang-github-vbauerster-mpb / 10915d5
minor: refactoring names Vladimir Bauer 3 years ago
1 changed file(s) with 23 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
2929 func TestProxyReader(t *testing.T) {
3030 p := mpb.New(mpb.WithOutput(io.Discard))
3131
32 reader := &testReader{strings.NewReader(content), false}
32 tr := &testReader{strings.NewReader(content), false}
3333
34 bar := p.AddBar(int64(len(content)))
34 bar := p.New(int64(len(content)), mpb.NopStyle())
3535
3636 var buf bytes.Buffer
37 _, err := io.Copy(&buf, bar.ProxyReader(reader))
37 _, err := io.Copy(&buf, bar.ProxyReader(tr))
3838 if err != nil {
39 t.Errorf("Error copying from reader: %+v\n", err)
39 t.Errorf("io.Copy: %s\n", err.Error())
4040 }
4141
4242 p.Wait()
4343
44 if !reader.called {
44 if !tr.called {
4545 t.Error("Read not called")
4646 }
4747
6363 func TestProxyReadCloser(t *testing.T) {
6464 p := mpb.New(mpb.WithOutput(io.Discard))
6565
66 reader := &testReadCloser{strings.NewReader(content), false}
66 tr := &testReadCloser{strings.NewReader(content), false}
6767
68 bar := p.AddBar(int64(len(content)))
68 bar := p.New(int64(len(content)), mpb.NopStyle())
6969
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 }
7275 _ = rc.Close()
7376
7477 p.Wait()
7578
76 if !reader.called {
79 if !tr.called {
7780 t.Error("Close not called")
7881 }
7982 }
8083
81 type testWriterTo struct {
84 type testReaderWriterTo struct {
8285 io.Reader
8386 called bool
8487 }
8588
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)
8992 }
9093
91 func TestProxyWriterTo(t *testing.T) {
94 func TestProxyReaderWriterTo(t *testing.T) {
9295 p := mpb.New(mpb.WithOutput(io.Discard))
9396
94 writerTo := &testWriterTo{strings.NewReader(content), false}
97 tr := &testReaderWriterTo{strings.NewReader(content), false}
9598
96 bar := p.AddBar(int64(len(content)))
99 bar := p.New(int64(len(content)), mpb.NopStyle())
97100
98101 var buf bytes.Buffer
99 _, err := io.Copy(&buf, bar.ProxyReader(writerTo))
102 _, err := io.Copy(&buf, bar.ProxyReader(tr))
100103 if err != nil {
101 t.Errorf("Error copying from reader: %+v\n", err)
104 t.Errorf("io.Copy: %s\n", err.Error())
102105 }
103106
104107 p.Wait()
105108
106 if !writerTo.called {
109 if !tr.called {
107110 t.Error("WriteTo not called")
108111 }
109112