Codebase list golang-github-vbauerster-mpb / 2abfd95
Refactoring: Output to WithOutput Vladimir Bauer 8 years ago
6 changed file(s) with 18 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
1313 )
1414
1515 func TestBarCompleted(t *testing.T) {
16 p := mpb.New(mpb.Output(ioutil.Discard))
16 p := mpb.New(mpb.WithOutput(ioutil.Discard))
1717 total := 80
1818 bar := p.AddBar(int64(total))
1919
3131 }
3232
3333 func TestBarID(t *testing.T) {
34 p := mpb.New(mpb.Output(ioutil.Discard))
34 p := mpb.New(mpb.WithOutput(ioutil.Discard))
3535
3636 numBars := 3
3737 bars := make([]*mpb.Bar, numBars)
5959
6060 width := 100
6161 p := mpb.New(
62 mpb.Output(&buf),
62 mpb.WithOutput(&buf),
6363 mpb.WithWidth(width),
6464 )
6565
9090 func TestBarPanics(t *testing.T) {
9191 var wg sync.WaitGroup
9292 var buf bytes.Buffer
93 p := mpb.New(mpb.Output(&buf), mpb.WithWaitGroup(&wg))
93 p := mpb.New(mpb.WithOutput(&buf), mpb.WithWaitGroup(&wg))
9494
9595 wantPanic := "Upps!!!"
9696 numBars := 3
55 )
66
77 func benchmarkSingleBar(total int) {
8 p := New(Output(ioutil.Discard))
8 p := New(WithOutput(ioutil.Discard))
99 bar := p.AddBar(int64(total))
1010 for i := 0; i < total; i++ {
1111 bar.Increment()
3232 }
3333
3434 func BenchmarkIncrSingleBar(b *testing.B) {
35 p := New(Output(ioutil.Discard))
35 p := New(WithOutput(ioutil.Discard))
3636 bar := p.AddBar(int64(b.N))
3737 for i := 0; i < b.N; i++ {
3838 bar.Increment()
6868 }
6969 }
7070
71 // Output overrides default output os.Stdout
72 func Output(w io.Writer) ProgressOption {
71 // WithOutput overrides default output os.Stdout
72 func WithOutput(w io.Writer) ProgressOption {
7373 return func(s *pState) {
7474 if w == nil {
7575 w = ioutil.Discard
7878 }
7979 }
8080
81 // OutputInterceptors provides a way to write to the underlying progress pool's
81 // WithInterceptors provides a way to write to the underlying progress pool's
8282 // writer. Could be useful if you want to output something below the bars, while
8383 // they're rendering.
84 func OutputInterceptors(interseptors ...func(io.Writer)) ProgressOption {
84 func WithInterceptors(interseptors ...func(io.Writer)) ProgressOption {
8585 return func(s *pState) {
8686 s.interceptors = interseptors
8787 }
1414 ctx, cancel := context.WithCancel(context.Background())
1515 shutdown := make(chan struct{})
1616 p := mpb.New(
17 mpb.Output(ioutil.Discard),
17 mpb.WithOutput(ioutil.Discard),
1818 mpb.WithContext(ctx),
1919 mpb.WithShutdownNotifier(shutdown),
2020 )
1717 }
1818
1919 func TestBarCount(t *testing.T) {
20 p := mpb.New(mpb.Output(ioutil.Discard))
20 p := mpb.New(mpb.WithOutput(ioutil.Discard))
2121
2222 var wg sync.WaitGroup
2323 wg.Add(1)
4343 }
4444
4545 func TestBarAbort(t *testing.T) {
46 p := mpb.New(mpb.Output(ioutil.Discard))
46 p := mpb.New(mpb.WithOutput(ioutil.Discard))
4747
4848 var wg sync.WaitGroup
4949 wg.Add(1)
7777 cancel := make(chan struct{})
7878 shutdown := make(chan struct{})
7979 p := mpb.New(
80 mpb.Output(ioutil.Discard),
80 mpb.WithOutput(ioutil.Discard),
8181 mpb.WithCancel(cancel),
8282 mpb.WithShutdownNotifier(shutdown),
8383 )
117117 cancel := make(chan struct{})
118118 customFormat := "╢▌▌░╟"
119119 p := mpb.New(
120 mpb.Output(&buf),
120 mpb.WithOutput(&buf),
121121 mpb.WithCancel(cancel),
122122 mpb.WithFormat(customFormat),
123123 )
151151 customWidth := 60
152152 customFormat := "(#>=_)"
153153 p := mpb.New(
154 mpb.Output(&buf),
154 mpb.WithOutput(&buf),
155155 mpb.WithWidth(customWidth),
156156 mpb.WithFormat(customFormat),
157157 )
2121
2222 func TestProxyReader(t *testing.T) {
2323 var buf bytes.Buffer
24 p := mpb.New(mpb.Output(&buf))
24 p := mpb.New(mpb.WithOutput(&buf))
2525
2626 reader := strings.NewReader(content)
2727
4949
5050 func TestProxyReaderCloser(t *testing.T) {
5151 var buf bytes.Buffer
52 p := mpb.New(mpb.Output(&buf))
52 p := mpb.New(mpb.WithOutput(&buf))
5353
5454 ts := setupTestHttpServer(content)
5555 defer ts.Close()