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

Function TestNextID_JSONFormat

apps/cli/internal/cli/nextid_test.go:161–214  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

159}
160
161func TestNextID_JSONFormat(t *testing.T) {
162 resetNextIDFlags()
163 nextIDFormat = "json"
164
165 tmpDir := createNextIDTestFiles(t, map[string]string{
166 "001-task.md": `---
167id: "001"
168title: "Task one"
169status: pending
170priority: medium
171created: 2026-02-14
172---
173`,
174 "002-task.md": `---
175id: "002"
176title: "Task two"
177status: completed
178priority: high
179created: 2026-02-14
180---
181`,
182 })
183
184 oldStdout := os.Stdout
185 r, w, _ := os.Pipe()
186 os.Stdout = w
187
188 err := runNextID(nextIDCmd, []string{tmpDir})
189
190 w.Close()
191 os.Stdout = oldStdout
192
193 if err != nil {
194 t.Fatalf("unexpected error: %v", err)
195 }
196
197 var buf bytes.Buffer
198 buf.ReadFrom(r)
199
200 var result nextid.Result
201 if err := json.Unmarshal(buf.Bytes(), &result); err != nil {
202 t.Fatalf("failed to parse JSON: %v\noutput: %s", err, buf.String())
203 }
204
205 if result.NextID != "003" {
206 t.Errorf("NextID = %q, want %q", result.NextID, "003")
207 }
208 if result.MaxID != "002" {
209 t.Errorf("MaxID = %q, want %q", result.MaxID, "002")
210 }
211 if result.Total != 2 {
212 t.Errorf("Total = %d, want 2", result.Total)
213 }
214}
215
216func TestNextID_UnsupportedFormat(t *testing.T) {
217 resetNextIDFlags()

Callers

nothing calls this directly

Calls 3

resetNextIDFlagsFunction · 0.85
createNextIDTestFilesFunction · 0.85
runNextIDFunction · 0.85

Tested by

no test coverage detected