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