(t *testing.T)
| 631 | } |
| 632 | |
| 633 | func 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 | } |
nothing calls this directly
no test coverage detected