(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func TestLogin(t *testing.T) { |
| 77 | tests := []struct { |
| 78 | name string |
| 79 | opts LoginOptions |
| 80 | httpStubs func(*testing.T, *httpmock.Registry) |
| 81 | runStubs func(*testing.T, *run.CommandStubber, *LoginOptions) |
| 82 | wantsConfig map[string]string |
| 83 | wantsErr string |
| 84 | stdout string |
| 85 | stderr string |
| 86 | stderrAssert func(*testing.T, *LoginOptions, string) |
| 87 | }{ |
| 88 | { |
| 89 | name: "tty, prompt (protocol: ssh, create key: yes)", |
| 90 | opts: LoginOptions{ |
| 91 | Prompter: &prompter.PrompterMock{ |
| 92 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 93 | switch prompt { |
| 94 | case "What is your preferred protocol for Git operations on this host?": |
| 95 | return prompter.IndexFor(opts, "SSH") |
| 96 | case "How would you like to authenticate GitHub CLI?": |
| 97 | return prompter.IndexFor(opts, "Paste an authentication token") |
| 98 | } |
| 99 | return -1, prompter.NoSuchPromptErr(prompt) |
| 100 | }, |
| 101 | PasswordFunc: func(_ string) (string, error) { |
| 102 | return "monkey", nil |
| 103 | }, |
| 104 | ConfirmFunc: func(prompt string, _ bool) (bool, error) { |
| 105 | return true, nil |
| 106 | }, |
| 107 | AuthTokenFunc: func() (string, error) { |
| 108 | return "ATOKEN", nil |
| 109 | }, |
| 110 | InputFunc: func(_, _ string) (string, error) { |
| 111 | return "Test Key", nil |
| 112 | }, |
| 113 | }, |
| 114 | |
| 115 | Hostname: "example.com", |
| 116 | Interactive: true, |
| 117 | }, |
| 118 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 119 | reg.Register( |
| 120 | httpmock.REST("GET", "api/v3/"), |
| 121 | httpmock.ScopesResponder("repo,read:org")) |
| 122 | reg.Register( |
| 123 | httpmock.GraphQL(`query UserCurrent\b`), |
| 124 | httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`)) |
| 125 | reg.Register( |
| 126 | httpmock.REST("GET", "api/v3/user/keys"), |
| 127 | httpmock.StringResponse(`[]`)) |
| 128 | reg.Register( |
| 129 | httpmock.REST("POST", "api/v3/user/keys"), |
| 130 | httpmock.StringResponse(`{}`)) |
| 131 | }, |
| 132 | runStubs: func(t *testing.T, cs *run.CommandStubber, opts *LoginOptions) { |
| 133 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected