github.com/2lambda123/git-lfs@v2.5.2+incompatible/tasklog/waiting_task_test.go (about) 1 package tasklog 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func TestWaitingTaskDisplaysWaitingStatus(t *testing.T) { 10 task := NewWaitingTask("example") 11 12 assert.Equal(t, "example: ...", (<-task.Updates()).S) 13 } 14 15 func TestWaitingTaskCallsDoneWhenComplete(t *testing.T) { 16 task := NewWaitingTask("example") 17 18 select { 19 case v, ok := <-task.Updates(): 20 if ok { 21 assert.Equal(t, "example: ...", v.S) 22 } else { 23 t.Fatal("expected channel to be open") 24 } 25 default: 26 } 27 28 task.Complete() 29 30 if _, ok := <-task.Updates(); ok { 31 t.Fatalf("expected channel to be closed") 32 } 33 } 34 35 func TestWaitingTaskPanicsWithMultipleDoneCalls(t *testing.T) { 36 task := NewWaitingTask("example") 37 38 task.Complete() 39 40 defer func() { 41 if err := recover(); err == nil { 42 t.Fatal("tasklog: expected panic()") 43 } else { 44 if s, ok := err.(error); ok { 45 assert.Equal(t, "close of closed channel", s.Error()) 46 } else { 47 t.Fatal("tasklog: expected panic() to implement error") 48 } 49 } 50 }() 51 52 task.Complete() 53 } 54 55 func TestWaitingTaskIsThrottled(t *testing.T) { 56 task := NewWaitingTask("example") 57 58 throttled := task.Throttled() 59 60 assert.True(t, throttled, 61 "tasklog: expected *WaitingTask to be Throttle()-d") 62 }