git/githistory/log: handle tasks with no output

This commit is contained in:
Taylor Blau 2017-11-16 08:33:10 -08:00
parent fcc1522bed
commit 6bd752e674
2 changed files with 19 additions and 1 deletions

@ -203,7 +203,12 @@ func (l *Logger) logTask(task Task) {
}
}
l.log(fmt.Sprintf("%s, done\n", update.S))
if update != nil {
// If a task sent no updates, the last recorded update will be
// nil. Given this, only log a message when there was at least
// (1) update.
l.log(fmt.Sprintf("%s, done\n", update.S))
}
}
// logLine writes a complete line and moves the cursor to the beginning of the

@ -175,3 +175,16 @@ func TestLoggerLogsAllDurableUpdates(t *testing.T) {
"second, done\n",
}, ""), buf.String())
}
func TestLoggerHandlesSilentTasks(t *testing.T) {
var buf bytes.Buffer
task := make(chan *Update)
close(task)
l := NewLogger(&buf)
l.Enqueue(ChanTask(task))
l.Close()
assert.Equal(t, "", buf.String())
}