(t *testing.T)
| 705 | } |
| 706 | |
| 707 | func TestRunCopilot(t *testing.T) { |
| 708 | execErr := fmt.Errorf("exec failed: something went wrong") |
| 709 | tests := []struct { |
| 710 | name string |
| 711 | isTTY bool |
| 712 | prompter prompter.Prompter |
| 713 | findCopilot func() string |
| 714 | runExternal func(*exec.Cmd) error |
| 715 | wantErr error |
| 716 | wantErrSubstring string |
| 717 | wantStderr string |
| 718 | }{ |
| 719 | { |
| 720 | name: "declining install prints trailing newline", |
| 721 | isTTY: true, |
| 722 | prompter: &prompter.PrompterMock{ |
| 723 | ConfirmFunc: func(_ string, _ bool) (bool, error) { |
| 724 | return false, nil |
| 725 | }, |
| 726 | }, |
| 727 | findCopilot: func() string { |
| 728 | return "" |
| 729 | }, |
| 730 | wantErr: cmdutil.SilentError, |
| 731 | wantStderr: "! Copilot CLI was not installed\n", |
| 732 | }, |
| 733 | { |
| 734 | name: "execution failure includes direct command hint", |
| 735 | findCopilot: func() string { |
| 736 | return "/usr/bin/copilot" |
| 737 | }, |
| 738 | runExternal: func(_ *exec.Cmd) error { |
| 739 | return execErr |
| 740 | }, |
| 741 | wantErr: execErr, |
| 742 | wantErrSubstring: "try running `copilot` directly without `gh`.", |
| 743 | }, |
| 744 | } |
| 745 | |
| 746 | for _, tt := range tests { |
| 747 | t.Run(tt.name, func(t *testing.T) { |
| 748 | t.Setenv("CI", "") |
| 749 | t.Setenv("BUILD_NUMBER", "") |
| 750 | t.Setenv("RUN_ID", "") |
| 751 | |
| 752 | ios, _, _, stderr := iostreams.Test() |
| 753 | if tt.isTTY { |
| 754 | ios.SetStdinTTY(true) |
| 755 | ios.SetStdoutTTY(true) |
| 756 | } |
| 757 | |
| 758 | opts := &CopilotOptions{ |
| 759 | IO: ios, |
| 760 | Prompter: tt.prompter, |
| 761 | CopilotArgs: []string{}, |
| 762 | } |
| 763 | |
| 764 | origFind := findCopilotBinaryFunc |
nothing calls this directly
no test coverage detected