github.com/git-lfs/git-lfs@v2.5.2+incompatible/tasklog/simple_task_test.go (about) 1 package tasklog 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 "github.com/stretchr/testify/require" 8 ) 9 10 func TestSimpleTaskLogLogsUpdates(t *testing.T) { 11 task := NewSimpleTask() 12 13 var updates []*Update 14 15 go func() { 16 for update := range task.Updates() { 17 updates = append(updates, update) 18 } 19 task.OnComplete() 20 }() 21 22 task.Log("Hello, world") 23 task.Complete() 24 25 require.Len(t, updates, 1) 26 assert.Equal(t, "Hello, world", updates[0].S) 27 } 28 29 func TestSimpleTaskLogfLogsFormattedUpdates(t *testing.T) { 30 task := NewSimpleTask() 31 32 var updates []*Update 33 34 go func() { 35 for update := range task.Updates() { 36 updates = append(updates, update) 37 } 38 task.OnComplete() 39 }() 40 41 task.Logf("Hello, world (%d)", 3+4) 42 task.Complete() 43 44 require.Len(t, updates, 1) 45 assert.Equal(t, "Hello, world (7)", updates[0].S) 46 } 47 48 func TestSimpleTaskCompleteClosesUpdates(t *testing.T) { 49 task := NewSimpleTask() 50 51 select { 52 case <-task.Updates(): 53 t.Fatalf("tasklog: unexpected update from *SimpleTask") 54 default: 55 } 56 57 go func() { 58 <-task.Updates() 59 task.OnComplete() 60 }() 61 62 task.Complete() 63 64 if _, ok := <-task.Updates(); ok { 65 t.Fatalf("tasklog: expected (*SimpleTask).Updates() to be closed") 66 } 67 } 68 69 func TestSimpleTaskIsNotThrottled(t *testing.T) { 70 task := NewSimpleTask() 71 72 throttled := task.Throttled() 73 74 assert.False(t, throttled, 75 "tasklog: expected *SimpleTask not to be Throttle()-d") 76 }