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

Function TestSearch_IntegrationWithFiles

apps/cli/internal/cli/search_test.go:596–652  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

594}
595
596func TestSearch_IntegrationWithFiles(t *testing.T) {
597 resetSearchFlags()
598
599 tmpDir := createSearchTestFiles(t)
600 taskDir = tmpDir
601
602 // Capture stderr for "no results" case
603 oldStderr := os.Stderr
604 stderrR, stderrW, _ := os.Pipe()
605 os.Stderr = stderrW
606
607 oldStdout := os.Stdout
608 stdoutR, stdoutW, _ := os.Pipe()
609 os.Stdout = stdoutW
610
611 searchFormat = "json"
612 err := runSearch(searchCmd, []string{"authentication"})
613
614 stdoutW.Close()
615 stderrW.Close()
616 os.Stdout = oldStdout
617 os.Stderr = oldStderr
618
619 if err != nil {
620 t.Fatalf("unexpected error: %v", err)
621 }
622
623 var stdoutBuf bytes.Buffer
624 stdoutBuf.ReadFrom(stdoutR)
625
626 var stderrBuf bytes.Buffer
627 stderrBuf.ReadFrom(stderrR)
628
629 output := stdoutBuf.String()
630 if output == "" {
631 t.Fatalf("expected JSON output, got empty. stderr: %s", stderrBuf.String())
632 }
633
634 var parsed []search.Result
635 if err := json.Unmarshal([]byte(output), &parsed); err != nil {
636 t.Fatalf("failed to parse JSON: %v\noutput: %s", err, output)
637 }
638
639 // "authentication" appears in task 001 title+body and task 002 body
640 if len(parsed) < 1 {
641 t.Fatalf("expected at least 1 result, got %d", len(parsed))
642 }
643
644 foundIDs := make(map[string]bool)
645 for _, r := range parsed {
646 foundIDs[r.ID] = true
647 }
648
649 if !foundIDs["001"] {
650 t.Error("expected task 001 to match (title contains 'authentication')")
651 }
652}

Callers

nothing calls this directly

Calls 4

resetSearchFlagsFunction · 0.85
createSearchTestFilesFunction · 0.85
runSearchFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected