drop io/ioutil
Vladimir Bauer
3 years ago
| 3 | 3 | "bytes" |
| 4 | 4 | "context" |
| 5 | 5 | "fmt" |
| 6 | "io/ioutil" | |
| 6 | "io" | |
| 7 | 7 | "strings" |
| 8 | 8 | "sync/atomic" |
| 9 | 9 | "testing" |
| 15 | 15 | ) |
| 16 | 16 | |
| 17 | 17 | func TestBarCompleted(t *testing.T) { |
| 18 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard)) | |
| 18 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) | |
| 19 | 19 | total := 80 |
| 20 | 20 | bar := p.AddBar(int64(total)) |
| 21 | 21 | |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | func TestBarAborted(t *testing.T) { |
| 36 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard)) | |
| 36 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) | |
| 37 | 37 | total := 80 |
| 38 | 38 | bar := p.AddBar(int64(total)) |
| 39 | 39 | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | func TestBarEnableTriggerCompleteAndIncrementBefore(t *testing.T) { |
| 54 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard)) | |
| 54 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) | |
| 55 | 55 | bar := p.AddBar(0) // never complete bar |
| 56 | 56 | |
| 57 | 57 | for _, f := range []func(){ |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | func TestBarEnableTriggerCompleteAndIncrementAfter(t *testing.T) { |
| 79 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard)) | |
| 79 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) | |
| 80 | 80 | bar := p.AddBar(0) // never complete bar |
| 81 | 81 | |
| 82 | 82 | for _, f := range []func(){ |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | func TestBarID(t *testing.T) { |
| 104 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(ioutil.Discard)) | |
| 104 | p := mpb.New(mpb.WithWidth(80), mpb.WithOutput(io.Discard)) | |
| 105 | 105 | total := 100 |
| 106 | 106 | wantID := 11 |
| 107 | 107 | bar := p.AddBar(int64(total), mpb.BarID(wantID)) |
| 203 | 203 | p := mpb.New( |
| 204 | 204 | mpb.WithWidth(80), |
| 205 | 205 | mpb.WithDebugOutput(&buf), |
| 206 | mpb.WithOutput(ioutil.Discard), | |
| 206 | mpb.WithOutput(io.Discard), | |
| 207 | 207 | ) |
| 208 | 208 | |
| 209 | 209 | total := 100 |
| 240 | 240 | p := mpb.New( |
| 241 | 241 | mpb.WithWidth(80), |
| 242 | 242 | mpb.WithDebugOutput(&buf), |
| 243 | mpb.WithOutput(ioutil.Discard), | |
| 243 | mpb.WithOutput(io.Discard), | |
| 244 | 244 | ) |
| 245 | 245 | |
| 246 | 246 | total := 100 |
| 292 | 292 | refresh := make(chan interface{}) |
| 293 | 293 | p := mpb.NewWithContext(ctx, mpb.WithWidth(100), |
| 294 | 294 | mpb.WithManualRefresh(refresh), |
| 295 | mpb.WithOutput(ioutil.Discard), | |
| 295 | mpb.WithOutput(io.Discard), | |
| 296 | 296 | ) |
| 297 | 297 | _ = p.AddBar(0, |
| 298 | 298 | mpb.BarFillerTrim(), |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | 3 | "io" |
| 4 | "io/ioutil" | |
| 5 | 4 | "sync" |
| 6 | 5 | "time" |
| 7 | 6 | ) |
| 73 | 72 | func WithOutput(w io.Writer) ContainerOption { |
| 74 | 73 | return func(s *pState) { |
| 75 | 74 | if w == nil { |
| 76 | s.output = ioutil.Discard | |
| 75 | s.output = io.Discard | |
| 77 | 76 | s.outputDiscarded = true |
| 78 | 77 | return |
| 79 | 78 | } |
| 2 | 2 | import ( |
| 3 | 3 | "bytes" |
| 4 | 4 | "fmt" |
| 5 | "io/ioutil" | |
| 5 | "io" | |
| 6 | 6 | "strconv" |
| 7 | 7 | "testing" |
| 8 | 8 | ) |
| 9 | 9 | |
| 10 | 10 | var ( |
| 11 | out = ioutil.Discard | |
| 11 | out = io.Discard | |
| 12 | 12 | lines = 99 |
| 13 | 13 | ) |
| 14 | 14 |
| 2 | 2 | import ( |
| 3 | 3 | crand "crypto/rand" |
| 4 | 4 | "io" |
| 5 | "io/ioutil" | |
| 6 | 5 | "math/rand" |
| 7 | 6 | "time" |
| 8 | 7 | |
| 77 | 76 | defer proxyReader.Close() |
| 78 | 77 | |
| 79 | 78 | // and copy from reader, ignoring errors |
| 80 | _, _ = io.Copy(ioutil.Discard, proxyReader) | |
| 79 | _, _ = io.Copy(io.Discard, proxyReader) | |
| 81 | 80 | |
| 82 | 81 | p.Wait() |
| 83 | 82 | } |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | 3 | "context" |
| 4 | "io/ioutil" | |
| 4 | "io" | |
| 5 | 5 | "math/rand" |
| 6 | 6 | "testing" |
| 7 | 7 | "time" |
| 20 | 20 | |
| 21 | 21 | func TestBarCount(t *testing.T) { |
| 22 | 22 | shutdown := make(chan struct{}) |
| 23 | p := mpb.New(mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(ioutil.Discard)) | |
| 23 | p := mpb.New(mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(io.Discard)) | |
| 24 | 24 | |
| 25 | 25 | b := p.AddBar(0, mpb.BarRemoveOnComplete()) |
| 26 | 26 | |
| 47 | 47 | |
| 48 | 48 | func TestBarAbort(t *testing.T) { |
| 49 | 49 | shutdown := make(chan struct{}) |
| 50 | p := mpb.New(mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(ioutil.Discard)) | |
| 50 | p := mpb.New(mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(io.Discard)) | |
| 51 | 51 | n := 2 |
| 52 | 52 | bars := make([]*mpb.Bar, n) |
| 53 | 53 | for i := 0; i < n; i++ { |
| 96 | 96 | func TestWithContext(t *testing.T) { |
| 97 | 97 | shutdown := make(chan struct{}) |
| 98 | 98 | ctx, cancel := context.WithCancel(context.Background()) |
| 99 | p := mpb.NewWithContext(ctx, mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(ioutil.Discard)) | |
| 99 | p := mpb.NewWithContext(ctx, mpb.WithShutdownNotifier(shutdown), mpb.WithOutput(io.Discard)) | |
| 100 | 100 | |
| 101 | 101 | done := make(chan struct{}) |
| 102 | 102 | bar := p.AddBar(0) // never complete bar |
| 138 | 138 | |
| 139 | 139 | total := 100 |
| 140 | 140 | numBars := 6 |
| 141 | p := mpb.New(mpb.WithOutput(ioutil.Discard)) | |
| 141 | p := mpb.New(mpb.WithOutput(io.Discard)) | |
| 142 | 142 | for i := 0; i < numBars; i++ { |
| 143 | 143 | bar := p.AddBar(int64(total), |
| 144 | 144 | mpb.BarOptional(mpb.BarRemoveOnComplete(), i == 0), |
| 1 | 1 | |
| 2 | 2 | import ( |
| 3 | 3 | "io" |
| 4 | "io/ioutil" | |
| 5 | 4 | "time" |
| 6 | 5 | ) |
| 7 | 6 | |
| 75 | 74 | if rc, ok := r.(io.ReadCloser); ok { |
| 76 | 75 | return rc |
| 77 | 76 | } |
| 78 | return ioutil.NopCloser(r) | |
| 77 | return io.NopCloser(r) | |
| 79 | 78 | } |
| 2 | 2 | import ( |
| 3 | 3 | "bytes" |
| 4 | 4 | "io" |
| 5 | "io/ioutil" | |
| 6 | 5 | "strings" |
| 7 | 6 | "testing" |
| 8 | 7 | |
| 38 | 37 | } |
| 39 | 38 | |
| 40 | 39 | func TestProxyReader(t *testing.T) { |
| 41 | p := mpb.New(mpb.WithOutput(ioutil.Discard)) | |
| 40 | p := mpb.New(mpb.WithOutput(io.Discard)) | |
| 42 | 41 | |
| 43 | 42 | tReader := &testReader{strings.NewReader(content), false} |
| 44 | 43 | |
| 62 | 61 | } |
| 63 | 62 | |
| 64 | 63 | func TestProxyWriterTo(t *testing.T) { |
| 65 | p := mpb.New(mpb.WithOutput(ioutil.Discard)) | |
| 64 | p := mpb.New(mpb.WithOutput(io.Discard)) | |
| 66 | 65 | |
| 67 | 66 | var reader io.Reader = strings.NewReader(content) |
| 68 | 67 | tWriterTo := testWriterTo{&testReader{reader, false}, reader.(io.WriterTo)} |