WithBarRemoveOnComplete test
Vladimir Bauer
7 years ago
| 9 | 9 | "time" |
| 10 | 10 | "unicode/utf8" |
| 11 | 11 | |
| 12 | "github.com/vbauerster/mpb" | |
| 12 | 13 | . "github.com/vbauerster/mpb/v4" |
| 13 | 14 | "github.com/vbauerster/mpb/v4/decor" |
| 14 | 15 | ) |
| 87 | 88 | } |
| 88 | 89 | } |
| 89 | 90 | |
| 90 | func TestBarHas100PercentAfterOnComplete(t *testing.T) { | |
| 91 | func TestBarHas100PercentWithOnCompleteDecorator(t *testing.T) { | |
| 91 | 92 | var buf bytes.Buffer |
| 92 | 93 | |
| 93 | 94 | p := New(WithOutput(&buf)) |
| 100 | 101 | decor.Percentage(), "done", |
| 101 | 102 | ), |
| 102 | 103 | ), |
| 104 | ) | |
| 105 | ||
| 106 | for i := 0; i < total; i++ { | |
| 107 | bar.Increment() | |
| 108 | time.Sleep(10 * time.Millisecond) | |
| 109 | } | |
| 110 | ||
| 111 | p.Wait() | |
| 112 | ||
| 113 | hundred := "100 %" | |
| 114 | if !bytes.Contains(buf.Bytes(), []byte(hundred)) { | |
| 115 | t.Errorf("Bar's buffer does not contain: %q\n", hundred) | |
| 116 | } | |
| 117 | } | |
| 118 | ||
| 119 | func TestBarHas100PercentWithBarRemoveOnComplete(t *testing.T) { | |
| 120 | var buf bytes.Buffer | |
| 121 | ||
| 122 | p := New(WithOutput(&buf)) | |
| 123 | ||
| 124 | total := 50 | |
| 125 | ||
| 126 | bar := p.AddBar(int64(total), | |
| 127 | mpb.BarRemoveOnComplete(), | |
| 128 | AppendDecorators(decor.Percentage()), | |
| 103 | 129 | ) |
| 104 | 130 | |
| 105 | 131 | for i := 0; i < total; i++ { |