(t *testing.T)
| 741 | } |
| 742 | |
| 743 | func TestLogin_recordsAuthTelemetryOnFailure(t *testing.T) { |
| 744 | // Telemetry must reflect how far the login got: an issued expiring token is recorded even when storing it fails, |
| 745 | // and a stored credential counts as a successful sign-in even when a later side effect fails. |
| 746 | tests := []struct { |
| 747 | name string |
| 748 | config iconfig |
| 749 | gitProtocol string |
| 750 | helperErr error |
| 751 | setup func(t *testing.T, opts *LoginOptions, reg *httpmock.Registry) |
| 752 | wantSuccess string |
| 753 | }{ |
| 754 | { |
| 755 | name: "storage fails after an expiring token is issued", |
| 756 | config: failingStorageConfig{tinyConfig{}}, |
| 757 | gitProtocol: "https", |
| 758 | wantSuccess: "false", |
| 759 | }, |
| 760 | { |
| 761 | name: "credential helper setup fails after storage", |
| 762 | config: tinyConfig{}, |
| 763 | gitProtocol: "https", |
| 764 | helperErr: errors.New("helper setup failed"), |
| 765 | wantSuccess: "true", |
| 766 | }, |
| 767 | { |
| 768 | name: "SSH key upload fails after storage", |
| 769 | config: tinyConfig{}, |
| 770 | gitProtocol: "ssh", |
| 771 | setup: func(t *testing.T, opts *LoginOptions, reg *httpmock.Registry) { |
| 772 | dir := t.TempDir() |
| 773 | require.NoError(t, os.WriteFile(filepath.Join(dir, "id_ed25519.pub"), []byte("PUBKEY asdf"), 0600)) |
| 774 | opts.sshContext = ssh.NewContextForTests(dir, "") |
| 775 | reg.Register(httpmock.REST("GET", "user/keys"), httpmock.StatusStringResponse(500, "{}")) |
| 776 | }, |
| 777 | wantSuccess: "true", |
| 778 | }, |
| 779 | } |
| 780 | |
| 781 | for _, tt := range tests { |
| 782 | t.Run(tt.name, func(t *testing.T) { |
| 783 | ios, _, _, _ := iostreams.Test() |
| 784 | recorder := &telemetry.InvocationRecorderSpy{} |
| 785 | reg := &httpmock.Registry{} |
| 786 | defer reg.Verify(t) |
| 787 | |
| 788 | opts := &LoginOptions{ |
| 789 | IO: ios, |
| 790 | Config: tt.config, |
| 791 | HTTPClient: &http.Client{Transport: reg}, |
| 792 | Hostname: "github.com", |
| 793 | Interactive: true, |
| 794 | GitProtocol: tt.gitProtocol, |
| 795 | Telemetry: recorder, |
| 796 | Prompter: &prompter.PrompterMock{ |
| 797 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 798 | switch prompt { |
| 799 | case "How would you like to authenticate GitHub CLI?": |
| 800 | return prompter.IndexFor(opts, "Login with a web browser") |
nothing calls this directly
no test coverage detected