@@ -166,6 +166,65 @@ func TestSendBuildStartedMessage(t *testing.T) {
166166 assert .Empty (t , msgTimestamp )
167167}
168168
169+ func TestCalculateProgress (t * testing.T ) {
170+ t .Run ("Zero estimated duration" , func (t * testing.T ) {
171+ progress := calculateProgress (1 * time .Minute , 0 )
172+ assert .InDelta (t , 0.0 , progress , 0.001 )
173+ })
174+
175+ t .Run ("Half complete" , func (t * testing.T ) {
176+ progress := calculateProgress (30 * time .Second , 60 * time .Second )
177+ assert .InDelta (t , 0.5 , progress , 0.001 )
178+ })
179+
180+ t .Run ("Fully complete" , func (t * testing.T ) {
181+ progress := calculateProgress (60 * time .Second , 60 * time .Second )
182+ assert .InDelta (t , 1.0 , progress , 0.001 )
183+ })
184+
185+ t .Run ("Over estimated time" , func (t * testing.T ) {
186+ progress := calculateProgress (90 * time .Second , 60 * time .Second )
187+ assert .InDelta (t , 1.5 , progress , 0.001 )
188+ })
189+ }
190+
191+ func TestRenderProgressBar (t * testing.T ) {
192+ t .Run ("Zero progress" , func (t * testing.T ) {
193+ bar := renderProgressBar (0.0 )
194+ assert .Equal (t , "░░░░░░░░░░░░░░░░░░░░ 0%" , bar )
195+ })
196+
197+ t .Run ("25% progress" , func (t * testing.T ) {
198+ bar := renderProgressBar (0.25 )
199+ assert .Equal (t , "█████░░░░░░░░░░░░░░░ 25%" , bar )
200+ })
201+
202+ t .Run ("50% progress" , func (t * testing.T ) {
203+ bar := renderProgressBar (0.5 )
204+ assert .Equal (t , "██████████░░░░░░░░░░ 50%" , bar )
205+ })
206+
207+ t .Run ("75% progress" , func (t * testing.T ) {
208+ bar := renderProgressBar (0.75 )
209+ assert .Equal (t , "███████████████░░░░░ 75%" , bar )
210+ })
211+
212+ t .Run ("100% progress" , func (t * testing.T ) {
213+ bar := renderProgressBar (1.0 )
214+ assert .Equal (t , "████████████████████ 100%" , bar )
215+ })
216+
217+ t .Run ("Over 100% progress" , func (t * testing.T ) {
218+ bar := renderProgressBar (1.5 )
219+ assert .Equal (t , "████████████████████ 150%" , bar )
220+ })
221+
222+ t .Run ("Negative progress" , func (t * testing.T ) {
223+ bar := renderProgressBar (- 0.1 )
224+ assert .Equal (t , "░░░░░░░░░░░░░░░░░░░░ -10%" , bar )
225+ })
226+ }
227+
169228func spawnJenkinsServer () * httptest.Server {
170229 mux := http .NewServeMux ()
171230
0 commit comments