Skip to content

Commit

Permalink
Add actual check to TestOptionSetElapsedTime
Browse files Browse the repository at this point in the history
  • Loading branch information
oerlikon committed Nov 20, 2022
1 parent 23b4ee3 commit f9d6be8
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,22 +395,23 @@ func TestOptionSetPredictTime(t *testing.T) {
}
}

func TestOptionSetElapsedTime(t *testing.T) {
/*
Spinner test with iteration count and iteration rate
*/
func TestOptionSetElapsedTime_spinner(t *testing.T) {
buf := strings.Builder{}
bar := NewOptions(-1,
OptionSetWidth(10),
OptionSetWriter(&buf),
OptionShowIts(),
OptionShowCount(),
OptionSetElapsedTime(false),
)
bar.Reset()
time.Sleep(1 * time.Second)
bar.Add(5)

// Output:
// - (5/-, 5 it/s)
result := strings.TrimSpace(buf.String())
expect := "- (5/-, 5 it/s)"
if result != expect {
t.Errorf("Render miss-match\nResult: '%s'\nExpect: '%s'\n%+v", result, expect, bar)
}
}

func TestShowElapsedTimeOnFinish(t *testing.T) {
Expand All @@ -420,14 +421,11 @@ func TestShowElapsedTimeOnFinish(t *testing.T) {
OptionSetWidth(10),
OptionSetWriter(&buf),
)

bar.Reset()
time.Sleep(3 * time.Second)
bar.Add(10)

result := strings.TrimSpace(buf.String())
expect := "100% |██████████| [3s]"

if result != expect {
t.Errorf("Render miss-match\nResult: '%s'\nExpect: '%s'\n%+v", result, expect, bar)
}
Expand Down

0 comments on commit f9d6be8

Please sign in to comment.