MCPcopy
hub / github.com/jesseduffield/lazygit / TestNewCmdTaskInstantStop

Function TestNewCmdTaskInstantStop

pkg/tasks/tasks_test.go:22–85  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20}
21
22func TestNewCmdTaskInstantStop(t *testing.T) {
23 writer := bytes.NewBuffer(nil)
24 beforeStart, getBeforeStartCallCount := getCounter()
25 refreshView, getRefreshViewCallCount := getCounter()
26 onEndOfInput, getOnEndOfInputCallCount := getCounter()
27 onNewKey, getOnNewKeyCallCount := getCounter()
28 onDone, getOnDoneCallCount := getCounter()
29 task := gocui.NewFakeTask()
30 newTask := func() gocui.Task {
31 return task
32 }
33
34 manager := NewViewBufferManager(
35 utils.NewDummyLog(),
36 writer,
37 beforeStart,
38 refreshView,
39 onEndOfInput,
40 onNewKey,
41 newTask,
42 )
43
44 stop := make(chan struct{})
45 reader := bytes.NewBufferString("test")
46 start := func() (*exec.Cmd, io.Reader) {
47 // not actually starting this because it's not necessary
48 cmd := exec.Command("blah")
49
50 close(stop)
51
52 return cmd, reader
53 }
54
55 fn := manager.NewCmdTask(start, "prefix\n", LinesToRead{20, -1, nil}, onDone)
56
57 _ = fn(TaskOpts{Stop: stop, InitialContentLoaded: func() { task.Done() }})
58
59 callCountExpectations := []struct {
60 expected int
61 actual int
62 name string
63 }{
64 {0, getBeforeStartCallCount(), "beforeStart"},
65 {1, getRefreshViewCallCount(), "refreshView"},
66 {0, getOnEndOfInputCallCount(), "onEndOfInput"},
67 {0, getOnNewKeyCallCount(), "onNewKey"},
68 {1, getOnDoneCallCount(), "onDone"},
69 }
70 for _, expectation := range callCountExpectations {
71 if expectation.actual != expectation.expected {
72 t.Errorf("expected %s to be called %d times, got %d", expectation.name, expectation.expected, expectation.actual)
73 }
74 }
75
76 if task.Status() != gocui.TaskStatusDone {
77 t.Errorf("expected task status to be 'done', got '%s'", task.FormatStatus())
78 }
79

Callers

nothing calls this directly

Calls 10

NewCmdTaskMethod · 0.95
DoneMethod · 0.95
StatusMethod · 0.95
FormatStatusMethod · 0.95
NewFakeTaskFunction · 0.92
NewDummyLogFunction · 0.92
getCounterFunction · 0.85
NewViewBufferManagerFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected