progress: Add test for error event
@@ -18,6 +18,7 @@ package progress
import (
"fmt"
+ "sync"
"testing"
"time"
@@ -54,3 +55,32 @@ func TestLineText(t *testing.T) {
out = lineText(ev, 50, lineWidth, true)
assert.Equal(t, "\x1b[31m . id Text Status 0.0s\n\x1b[0m", out)
}
+
+func TestErrorEvent(t *testing.T) {
+ w := &ttyWriter{
+ events: map[string]Event{},
+ mtx: &sync.RWMutex{},
+ }
+ e := Event{
+ ID: "id",
+ Text: "Text",
+ Status: Working,
+ StatusText: "Working",
+ startTime: time.Now(),
+ spinner: &spinner{
+ chars: []string{"."},
+ },
+ }
+ // Fire "Working" event and check end time isn't touched
+ w.Event(e)
+ event, ok := w.events[e.ID]
+ assert.True(t, ok)
+ assert.True(t, event.endTime.Equal(time.Time{}))
+
+ // Fire "Error" event and check end time is set
+ e.Status = Error
+ w.Event(e)
+ event, ok = w.events[e.ID]
+ assert.True(t, ok)
+ assert.True(t, event.endTime.After(time.Now().Add(-10*time.Second)))
+}
