1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
package uiprogress
import (
"bytes"
"fmt"
"strings"
"sync"
"testing"
"time"
)
func TestStoppingPrintout(t *testing.T) {
progress := New()
progress.SetRefreshInterval(time.Millisecond * 10)
var buffer = &bytes.Buffer{}
progress.SetOut(buffer)
bar := progress.AddBar(100)
progress.Start()
var wg sync.WaitGroup
wg.Add(1)
go func() {
for i := 0; i <= 80; i = i + 10 {
bar.Set(i)
time.Sleep(time.Millisecond * 5)
}
wg.Done()
}()
wg.Wait()
progress.Stop()
fmt.Fprintf(buffer, "foo")
var wantSuffix = "[======================================================>-------------]\nfoo"
if !strings.HasSuffix(buffer.String(), wantSuffix) {
t.Errorf("Content that should be printed after stop not appearing on buffer.")
}
}
|