Update proxyreader_test
Vladimir Bauer
9 years ago
| 21 | 21 | |
| 22 | 22 | func TestProxyReader(t *testing.T) { |
| 23 | 23 | var buf bytes.Buffer |
| 24 | p := mpb.New().SetOut(&buf) | |
| 24 | p := mpb.New(mpb.Output(&buf)) | |
| 25 | 25 | |
| 26 | 26 | reader := strings.NewReader(content) |
| 27 | 27 | |
| 28 | total := int64(len(content)) | |
| 29 | bar := p.AddBar(total).TrimLeftSpace().TrimRightSpace() | |
| 28 | total := len(content) | |
| 29 | bar := p.AddBar(100, mpb.BarTrim()) | |
| 30 | 30 | preader := bar.ProxyReader(reader) |
| 31 | 31 | |
| 32 | 32 | written, err := io.Copy(ioutil.Discard, preader) |
| 36 | 36 | |
| 37 | 37 | p.Stop() |
| 38 | 38 | |
| 39 | if written != total { | |
| 39 | if written != int64(total) { | |
| 40 | 40 | t.Errorf("Expected written: %d, got: %d\n", total, written) |
| 41 | 41 | } |
| 42 | 42 | |
| 49 | 49 | |
| 50 | 50 | func TestProxyReaderCloser(t *testing.T) { |
| 51 | 51 | var buf bytes.Buffer |
| 52 | p := mpb.New().SetOut(&buf) | |
| 52 | p := mpb.New(mpb.Output(&buf)) | |
| 53 | 53 | |
| 54 | 54 | ts := setupTestHttpServer(content) |
| 55 | 55 | defer ts.Close() |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | total := resp.ContentLength |
| 64 | bar := p.AddBar(total).TrimLeftSpace().TrimRightSpace() | |
| 64 | bar := p.AddBar(total, mpb.BarTrim()) | |
| 65 | 65 | reader := bar.ProxyReader(resp.Body) |
| 66 | 66 | |
| 67 | 67 | // calling reader.Close() will call resp.Body.Close() implicitly |