(t *testing.T)
| 85 | } |
| 86 | |
| 87 | func TestNewCmdTask(t *testing.T) { |
| 88 | writer := bytes.NewBuffer(nil) |
| 89 | beforeStart, getBeforeStartCallCount := getCounter() |
| 90 | refreshView, getRefreshViewCallCount := getCounter() |
| 91 | onEndOfInput, getOnEndOfInputCallCount := getCounter() |
| 92 | onNewKey, getOnNewKeyCallCount := getCounter() |
| 93 | onDone, getOnDoneCallCount := getCounter() |
| 94 | task := gocui.NewFakeTask() |
| 95 | newTask := func() gocui.Task { |
| 96 | return task |
| 97 | } |
| 98 | |
| 99 | manager := NewViewBufferManager( |
| 100 | utils.NewDummyLog(), |
| 101 | writer, |
| 102 | beforeStart, |
| 103 | refreshView, |
| 104 | onEndOfInput, |
| 105 | onNewKey, |
| 106 | newTask, |
| 107 | ) |
| 108 | |
| 109 | stop := make(chan struct{}) |
| 110 | reader := bytes.NewBufferString("test") |
| 111 | start := func() (*exec.Cmd, io.Reader) { |
| 112 | // not actually starting this because it's not necessary |
| 113 | cmd := exec.Command("blah") |
| 114 | |
| 115 | return cmd, reader |
| 116 | } |
| 117 | |
| 118 | fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone) |
| 119 | wg := sync.WaitGroup{} |
| 120 | wg.Go(func() { |
| 121 | time.Sleep(100 * time.Millisecond) |
| 122 | close(stop) |
| 123 | }) |
| 124 | _ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }}) |
| 125 | |
| 126 | wg.Wait() |
| 127 | |
| 128 | callCountExpectations := []struct { |
| 129 | expected int |
| 130 | actual int |
| 131 | name string |
| 132 | }{ |
| 133 | {1, getBeforeStartCallCount(), "beforeStart"}, |
| 134 | {1, getRefreshViewCallCount(), "refreshView"}, |
| 135 | {1, getOnEndOfInputCallCount(), "onEndOfInput"}, |
| 136 | {0, getOnNewKeyCallCount(), "onNewKey"}, |
| 137 | {1, getOnDoneCallCount(), "onDone"}, |
| 138 | } |
| 139 | for _, expectation := range callCountExpectations { |
| 140 | if expectation.actual != expectation.expected { |
| 141 | t.Errorf("expected %s to be called %d times, got %d", expectation.name, expectation.expected, expectation.actual) |
| 142 | } |
| 143 | } |
| 144 |
nothing calls this directly
no test coverage detected