MCPcopy Create free account
hub / github.com/JordanCoin/codemap / TestDaemonCommandHelpersAndMultiRepoShellout

Function TestDaemonCommandHelpersAndMultiRepoShellout

cmd/hooks_more_test.go:633–761  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

631}
632
633func TestDaemonCommandHelpersAndMultiRepoShellout(t *testing.T) {
634 t.Run("start daemon shells out to watch start", func(t *testing.T) {
635 var gotName string
636 var gotArgs []string
637 withHookRuntimeStubs(
638 t,
639 func() (string, error) { return "/tmp/codemap-hook", nil },
640 func(name string, args ...string) *exec.Cmd {
641 gotName = name
642 gotArgs = append([]string(nil), args...)
643 return exec.Command("sh", "-c", "exit 0")
644 },
645 nil,
646 func(time.Duration) {},
647 )
648
649 startDaemon("/repo")
650 if gotName != "/tmp/codemap-hook" {
651 t.Fatalf("startDaemon executable = %q, want /tmp/codemap-hook", gotName)
652 }
653 wantArgs := []string{"watch", "start", "/repo"}
654 if strings.Join(gotArgs, "|") != strings.Join(wantArgs, "|") {
655 t.Fatalf("startDaemon args = %v, want %v", gotArgs, wantArgs)
656 }
657 })
658
659 t.Run("stop daemon shells out only when running", func(t *testing.T) {
660 var callCount int
661 var gotArgs []string
662 withHookRuntimeStubs(
663 t,
664 func() (string, error) { return "/tmp/codemap-hook", nil },
665 func(name string, args ...string) *exec.Cmd {
666 callCount++
667 gotArgs = append([]string(nil), args...)
668 return exec.Command("sh", "-c", "exit 0")
669 },
670 func(string) bool { return true },
671 nil,
672 )
673
674 stopDaemon("/repo")
675 if callCount != 1 {
676 t.Fatalf("expected stopDaemon to shell out once, got %d", callCount)
677 }
678 wantArgs := []string{"watch", "stop", "/repo"}
679 if strings.Join(gotArgs, "|") != strings.Join(wantArgs, "|") {
680 t.Fatalf("stopDaemon args = %v, want %v", gotArgs, wantArgs)
681 }
682 })
683
684 t.Run("multi repo start shells out for each child repo", func(t *testing.T) {
685 root := t.TempDir()
686 for _, repo := range []string{"svc-a", "svc-b"} {
687 repoPath := filepath.Join(root, repo)
688 if err := os.MkdirAll(repoPath, 0o755); err != nil {
689 t.Fatal(err)
690 }

Callers

nothing calls this directly

Calls 6

withHookRuntimeStubsFunction · 0.85
startDaemonFunction · 0.85
stopDaemonFunction · 0.85
writeProjectConfigFunction · 0.85
captureOutputFunction · 0.85

Tested by

no test coverage detected