Codebase list golang-github-vbauerster-mpb / 8f48aec
TestAppendElapsed Vladimir Bauer 9 years ago
1 changed file(s) with 42 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
224224 t.Errorf("%q not found in bar: %s\n", want, barOut)
225225 }
226226 }
227
228 func TestAppendElapsed(t *testing.T) {
229 var buf bytes.Buffer
230 p := mpb.New().SetOut(&buf)
231
232 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace().
233 AppendElapsed(0, 0)
234
235 for i := 0; i < 100; i++ {
236 time.Sleep(10 * time.Millisecond)
237 bar.Incr(1)
238 }
239
240 p.Stop()
241
242 want := "]1s"
243 barOut := buf.String()
244 if !strings.Contains(barOut, want) {
245 t.Errorf("%q not found in bar: %s\n", want, barOut)
246 }
247 }
248
249 func TestAppendElapsedDindentRight(t *testing.T) {
250 var buf bytes.Buffer
251 p := mpb.New().SetOut(&buf)
252
253 bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace().
254 AppendElapsed(3, mpb.DidentRight)
255
256 for i := 0; i < 100; i++ {
257 time.Sleep(10 * time.Millisecond)
258 bar.Incr(1)
259 }
260
261 p.Stop()
262
263 want := "]1s "
264 barOut := buf.String()
265 if !strings.Contains(barOut, want) {
266 t.Errorf("%q not found in bar: %s\n", want, barOut)
267 }
268 }