Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Avoid negative elapsed the display when only one event is sent.
Browse files Browse the repository at this point in the history
Signed-off-by: Guillaume Tardif <[email protected]>
  • Loading branch information
gtardif committed Feb 3, 2021
1 parent 7d0be7a commit f0dbc60
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion api/progress/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions api/progress/tty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down

0 comments on commit f0dbc60

Please sign in to comment.