progress: Add test for error event

Signed-off-by: Christopher Crone <christopher.crone@docker.com>
This commit is contained in:
Christopher Crone 2020-07-06 13:52:36 +02:00
parent 9cc04472fb
commit fac4c60077
1 changed files with 30 additions and 0 deletions

View File

@ -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)))
}