TestAppendETA
Vladimir Bauer
9 years ago
| 308 | 308 | t.Errorf("%q not found in bar: %s\n", want, barOut) |
| 309 | 309 | } |
| 310 | 310 | } |
| 311 | ||
| 312 | func TestAppendETA(t *testing.T) { | |
| 313 | var buf bytes.Buffer | |
| 314 | p := mpb.New().SetOut(&buf) | |
| 315 | ||
| 316 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 317 | AppendETA(0, 0) | |
| 318 | ||
| 319 | for i := 0; i < 100; i++ { | |
| 320 | time.Sleep(10 * time.Millisecond) | |
| 321 | bar.Incr(1) | |
| 322 | } | |
| 323 | ||
| 324 | p.Stop() | |
| 325 | ||
| 326 | want := "]0s" | |
| 327 | barOut := buf.String() | |
| 328 | if !strings.Contains(barOut, want) { | |
| 329 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 330 | } | |
| 331 | } | |
| 332 | ||
| 333 | func TestAppendETADindentRight(t *testing.T) { | |
| 334 | var buf bytes.Buffer | |
| 335 | p := mpb.New().SetOut(&buf) | |
| 336 | ||
| 337 | bar := p.AddBar(100).TrimLeftSpace().TrimRightSpace(). | |
| 338 | AppendETA(3, mpb.DidentRight) | |
| 339 | ||
| 340 | for i := 0; i < 100; i++ { | |
| 341 | time.Sleep(10 * time.Millisecond) | |
| 342 | bar.Incr(1) | |
| 343 | } | |
| 344 | ||
| 345 | p.Stop() | |
| 346 | ||
| 347 | want := "]0s " | |
| 348 | barOut := buf.String() | |
| 349 | if !strings.Contains(barOut, want) { | |
| 350 | t.Errorf("%q not found in bar: %s\n", want, barOut) | |
| 351 | } | |
| 352 | } |