MCPcopy Create free account
hub / github.com/cli/cli / TestRunCopilot

Function TestRunCopilot

pkg/cmd/copilot/copilot_test.go:707–782  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

705}
706
707func 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

Callers

nothing calls this directly

Calls 8

TestFunction · 0.92
runCopilotFunction · 0.85
SetStdinTTYMethod · 0.80
SetStdoutTTYMethod · 0.80
EqualMethod · 0.80
ErrorfMethod · 0.65
RunMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected