MCPcopy Create free account
hub / github.com/driangle/taskmd / captureSearchOutput

Function captureSearchOutput

apps/cli/internal/cli/search_test.go:85–116  ·  view source on GitHub ↗
(t *testing.T, tasks []*model.Task, query, format string)

Source from the content-addressed store, hash-verified

83}
84
85func captureSearchOutput(t *testing.T, tasks []*model.Task, query, format string) (string, error) {
86 t.Helper()
87
88 results := search.Search(tasks, query)
89
90 oldStdout := os.Stdout
91 r, w, _ := os.Pipe()
92 os.Stdout = w
93
94 var runErr error
95 switch format {
96 case "json":
97 if len(results) > 0 {
98 runErr = WriteJSON(os.Stdout, results)
99 }
100 case "yaml":
101 if len(results) > 0 {
102 runErr = WriteYAML(os.Stdout, results)
103 }
104 case "table":
105 if len(results) > 0 {
106 runErr = outputSearchTable(results, query)
107 }
108 }
109
110 w.Close()
111 os.Stdout = oldStdout
112
113 var buf bytes.Buffer
114 buf.ReadFrom(r)
115 return buf.String(), runErr
116}
117
118func TestSearch_MatchInTitle(t *testing.T) {
119 resetSearchFlags()

Callers 3

TestSearch_JSONFormatFunction · 0.85
TestSearch_YAMLFormatFunction · 0.85
TestSearch_TableOutputFunction · 0.85

Calls 3

WriteJSONFunction · 0.85
WriteYAMLFunction · 0.85
outputSearchTableFunction · 0.85

Tested by

no test coverage detected