2017-11-22 22:07:24 +00:00
|
|
|
package tasklog
|
2017-06-16 21:06:32 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestListTaskCallsDoneWhenComplete(t *testing.T) {
|
|
|
|
task := NewListTask("example")
|
|
|
|
task.Complete()
|
|
|
|
|
|
|
|
select {
|
|
|
|
case update, ok := <-task.Updates():
|
2017-08-09 21:45:18 +00:00
|
|
|
assert.Equal(t, "example: ...", update.S)
|
2017-06-16 21:06:32 +00:00
|
|
|
assert.True(t, ok,
|
2017-11-22 22:07:24 +00:00
|
|
|
"tasklog: expected Updates() to remain open")
|
2017-06-16 21:06:32 +00:00
|
|
|
default:
|
2017-11-22 22:07:24 +00:00
|
|
|
t.Fatal("tasklog: expected update from *ListTask")
|
2017-06-16 21:06:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
select {
|
|
|
|
case update, ok := <-task.Updates():
|
|
|
|
assert.False(t, ok,
|
|
|
|
"git/githistory.log: unexpected *ListTask.Update(): %s", update)
|
|
|
|
default:
|
2017-11-22 22:07:24 +00:00
|
|
|
t.Fatal("tasklog: expected *ListTask.Updates() to be closed")
|
2017-06-16 21:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestListTaskWritesEntries(t *testing.T) {
|
|
|
|
task := NewListTask("example")
|
|
|
|
task.Entry("1")
|
|
|
|
|
|
|
|
select {
|
|
|
|
case update, ok := <-task.Updates():
|
|
|
|
assert.True(t, ok,
|
2017-11-22 22:07:24 +00:00
|
|
|
"tasklog: expected ListTask.Updates() to remain open")
|
2017-08-09 21:45:18 +00:00
|
|
|
assert.Equal(t, "1\n", update.S)
|
2017-06-16 21:06:32 +00:00
|
|
|
default:
|
2017-11-22 22:07:24 +00:00
|
|
|
t.Fatal("tasklog: expected task.Updates() to have an update")
|
2017-06-16 21:06:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-19 20:27:50 +00:00
|
|
|
func TestListTaskIsNotThrottled(t *testing.T) {
|
2017-06-16 21:06:32 +00:00
|
|
|
task := NewListTask("example")
|
|
|
|
|
2017-06-19 20:27:50 +00:00
|
|
|
throttled := task.Throttled()
|
2017-06-16 21:06:32 +00:00
|
|
|
|
2017-06-19 20:27:50 +00:00
|
|
|
assert.False(t, throttled,
|
2017-11-22 22:07:24 +00:00
|
|
|
"tasklog: expected *ListTask to be Throttle()-d")
|
2017-06-16 21:06:32 +00:00
|
|
|
}
|