Codebase list golang-github-vbauerster-mpb / 07a688b
Remove duplicate test Vladimir Bauer 8 years ago
2 changed file(s) with 36 addition(s) and 66 deletion(s). Raw diff Collapse all Expand all
22 import (
33 "bytes"
44 "fmt"
5 "io/ioutil"
56 "strings"
67 "sync"
78 "testing"
4445 }
4546 }
4647
47 func TestBarFormat(t *testing.T) {
48 var buf bytes.Buffer
49 cancel := make(chan struct{})
50 customFormat := "(#>_)"
51 p := mpb.New(
52 mpb.Output(&buf),
53 mpb.WithCancel(cancel),
54 mpb.WithFormat(customFormat),
55 )
56 bar := p.AddBar(100, mpb.BarTrim())
57
58 go func() {
59 for i := 0; i < 100; i++ {
60 time.Sleep(10 * time.Millisecond)
61 bar.Increment()
62 }
63 }()
64
65 time.Sleep(250 * time.Millisecond)
66 close(cancel)
67 p.Stop()
68
69 barAsStr := strings.Trim(buf.String(), "\n")
70
71 seen := make(map[rune]bool)
72 for _, r := range barAsStr {
73 if !seen[r] {
74 seen[r] = true
75 }
76 }
77 for _, r := range customFormat {
78 if !seen[r] {
79 t.Errorf("Rune %#U not found in bar\n", r)
80 }
81 }
82 }
83
84 func TestBarInvalidFormat(t *testing.T) {
85 var buf bytes.Buffer
86 customWidth := 60
87 customFormat := "(#>=_)"
88 p := mpb.New(
89 mpb.Output(&buf),
90 mpb.WithWidth(customWidth),
91 mpb.WithFormat(customFormat),
92 )
93 bar := p.AddBar(100, mpb.BarTrim())
94
95 for i := 0; i < 100; i++ {
96 time.Sleep(10 * time.Millisecond)
97 bar.Incr(1)
98 }
99
100 p.Stop()
101
102 got := buf.String()
103 want := fmt.Sprintf("[%s]", strings.Repeat("=", customWidth-2))
104 if !strings.Contains(got, want) {
105 t.Errorf("Expected format: %s, got %s\n", want, got)
106 }
107 }
108
10948 func TestBarInProgress(t *testing.T) {
11049 var buf bytes.Buffer
11150 cancel := make(chan struct{})
13877
13978 func TestBarGetID(t *testing.T) {
14079 var wg sync.WaitGroup
141 var buf bytes.Buffer
142 p := mpb.New(mpb.Output(&buf))
80 p := mpb.New(
81 mpb.Output(ioutil.Discard),
82 mpb.WithWaitGroup(&wg),
83 )
14384
14485 numBars := 3
14586 wg.Add(numBars)
164105 }
165106 }
166107
167 wg.Wait()
168108 p.Stop()
169109 }
170110
44 "fmt"
55 "io/ioutil"
66 "math/rand"
7 "strings"
78 "sync"
89 "testing"
910 "time"
100101 var buf bytes.Buffer
101102 cancel := make(chan struct{})
102103 customFormat := "╢▌▌░╟"
103 p := mpb.New(mpb.Output(&buf), mpb.WithCancel(cancel), mpb.WithFormat(customFormat))
104 p := mpb.New(
105 mpb.Output(&buf),
106 mpb.WithCancel(cancel),
107 mpb.WithFormat(customFormat),
108 )
104109 bar := p.AddBar(100, mpb.BarTrim())
105110
106111 go func() {
120125 }
121126 }
122127 }
128
129 func TestInvalidFormatWidth(t *testing.T) {
130 var buf bytes.Buffer
131 customWidth := 60
132 customFormat := "(#>=_)"
133 p := mpb.New(
134 mpb.Output(&buf),
135 mpb.WithWidth(customWidth),
136 mpb.WithFormat(customFormat),
137 )
138 bar := p.AddBar(100, mpb.BarTrim())
139
140 for i := 0; i < 100; i++ {
141 time.Sleep(10 * time.Millisecond)
142 bar.Incr(1)
143 }
144
145 p.Stop()
146
147 got := buf.String()
148 want := fmt.Sprintf("[%s]", strings.Repeat("=", customWidth-2))
149 if !strings.Contains(got, want) {
150 t.Errorf("Expected format: %s, got %s\n", want, got)
151 }
152 }