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

Function TestOutputValidationJSON

apps/cli/internal/cli/validate_test.go:337–377  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

335}
336
337func TestOutputValidationJSON(t *testing.T) {
338 result := &validator.ValidationResult{
339 Issues: []validator.ValidationIssue{
340 {Level: validator.LevelError, TaskID: "001", Message: "missing title"},
341 },
342 Errors: 1,
343 TaskCount: 2,
344 }
345
346 oldStdout := os.Stdout
347 r, w, _ := os.Pipe()
348 os.Stdout = w
349
350 err := outputValidationJSON(result)
351
352 w.Close()
353 os.Stdout = oldStdout
354
355 if err != nil {
356 t.Fatalf("outputValidationJSON failed: %v", err)
357 }
358
359 var buf bytes.Buffer
360 buf.ReadFrom(r)
361 output := buf.String()
362
363 var parsed validator.ValidationResult
364 if err := json.Unmarshal([]byte(output), &parsed); err != nil {
365 t.Fatalf("failed to parse JSON: %v\noutput: %s", err, output)
366 }
367
368 if parsed.Errors != 1 {
369 t.Errorf("errors = %d, want 1", parsed.Errors)
370 }
371 if parsed.TaskCount != 2 {
372 t.Errorf("task_count = %d, want 2", parsed.TaskCount)
373 }
374 if len(parsed.Issues) != 1 {
375 t.Errorf("issues count = %d, want 1", len(parsed.Issues))
376 }
377}
378
379// --- Command-level tests ---
380

Callers

nothing calls this directly

Calls 1

outputValidationJSONFunction · 0.85

Tested by

no test coverage detected