Merge pull request #1230 from gtardif/fix_progress_time_display

Avoid negative elapsed the display when only one event is sent.
This commit is contained in:
Guillaume Tardif 2021-02-03 15:55:50 +01:00 committed by GitHub
commit af62c52716
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -154,7 +154,10 @@ func (w *ttyWriter) print() {
func lineText(event Event, pad string, terminalWidth, statusPadding int, color bool) string {
endTime := time.Now()
if event.Status != Working {
endTime = event.endTime
endTime = event.startTime
if (event.endTime != time.Time{}) {
endTime = event.endTime
}
}
elapsed := endTime.Sub(event.startTime).Seconds()

View File

@ -56,6 +56,25 @@ func TestLineText(t *testing.T) {
assert.Equal(t, out, "\x1b[31m . id Text Status 0.0s\n\x1b[0m")
}
func TestLineTextSingleEvent(t *testing.T) {
now := time.Now()
ev := Event{
ID: "id",
Text: "Text",
Status: Done,
StatusText: "Status",
startTime: now,
spinner: &spinner{
chars: []string{"."},
},
}
lineWidth := len(fmt.Sprintf("%s %s", ev.ID, ev.Text))
out := lineText(ev, "", 50, lineWidth, true)
assert.Equal(t, out, "\x1b[34m . id Text Status 0.0s\n\x1b[0m")
}
func TestErrorEvent(t *testing.T) {
w := &ttyWriter{
events: map[string]Event{},