(t *testing.T)
| 595 | } |
| 596 | |
| 597 | func TestRunCopilot(t *testing.T) { |
| 598 | execErr := fmt.Errorf("exec failed: something went wrong") |
| 599 | tests := []struct { |
| 600 | name string |
| 601 | isTTY bool |
| 602 | prompter prompter.Prompter |
| 603 | findCopilot func() string |
| 604 | runExternal func(*exec.Cmd) error |
| 605 | wantErr error |
| 606 | wantErrSubstring string |
| 607 | wantStderr string |
| 608 | }{ |
| 609 | { |
| 610 | name: "declining install prints trailing newline", |
| 611 | isTTY: true, |
| 612 | prompter: &prompter.PrompterMock{ |
| 613 | ConfirmFunc: func(_ string, _ bool) (bool, error) { |
| 614 | return false, nil |
| 615 | }, |
| 616 | }, |
| 617 | findCopilot: func() string { |
| 618 | return "" |
| 619 | }, |
| 620 | wantErr: cmdutil.SilentError, |
| 621 | wantStderr: "! Copilot CLI was not installed\n", |
| 622 | }, |
| 623 | { |
| 624 | name: "execution failure includes direct command hint", |
| 625 | findCopilot: func() string { |
| 626 | return "/usr/bin/copilot" |
| 627 | }, |
| 628 | runExternal: func(_ *exec.Cmd) error { |
| 629 | return execErr |
| 630 | }, |
| 631 | wantErr: execErr, |
| 632 | wantErrSubstring: "try running `copilot` directly without `gh`.", |
| 633 | }, |
| 634 | } |
| 635 | |
| 636 | for _, tt := range tests { |
| 637 | t.Run(tt.name, func(t *testing.T) { |
| 638 | t.Setenv("CI", "") |
| 639 | t.Setenv("BUILD_NUMBER", "") |
| 640 | t.Setenv("RUN_ID", "") |
| 641 | |
| 642 | ios, _, _, stderr := iostreams.Test() |
| 643 | if tt.isTTY { |
| 644 | ios.SetStdinTTY(true) |
| 645 | ios.SetStdoutTTY(true) |
| 646 | } |
| 647 | |
| 648 | opts := &CopilotOptions{ |
| 649 | IO: ios, |
| 650 | Prompter: tt.prompter, |
| 651 | CopilotArgs: []string{}, |
| 652 | } |
| 653 | |
| 654 | origFind := findCopilotBinaryFunc |
nothing calls this directly
no test coverage detected