(t *testing.T)
| 32 | } |
| 33 | |
| 34 | func TestLogin(t *testing.T) { |
| 35 | tests := []struct { |
| 36 | name string |
| 37 | opts LoginOptions |
| 38 | httpStubs func(*testing.T, *httpmock.Registry) |
| 39 | runStubs func(*testing.T, *run.CommandStubber, *LoginOptions) |
| 40 | wantsConfig map[string]string |
| 41 | wantsErr string |
| 42 | stdout string |
| 43 | stderr string |
| 44 | stderrAssert func(*testing.T, *LoginOptions, string) |
| 45 | }{ |
| 46 | { |
| 47 | name: "tty, prompt (protocol: ssh, create key: yes)", |
| 48 | opts: LoginOptions{ |
| 49 | Prompter: &prompter.PrompterMock{ |
| 50 | SelectFunc: func(prompt, _ string, opts []string) (int, error) { |
| 51 | switch prompt { |
| 52 | case "What is your preferred protocol for Git operations on this host?": |
| 53 | return prompter.IndexFor(opts, "SSH") |
| 54 | case "How would you like to authenticate GitHub CLI?": |
| 55 | return prompter.IndexFor(opts, "Paste an authentication token") |
| 56 | } |
| 57 | return -1, prompter.NoSuchPromptErr(prompt) |
| 58 | }, |
| 59 | PasswordFunc: func(_ string) (string, error) { |
| 60 | return "monkey", nil |
| 61 | }, |
| 62 | ConfirmFunc: func(prompt string, _ bool) (bool, error) { |
| 63 | return true, nil |
| 64 | }, |
| 65 | AuthTokenFunc: func() (string, error) { |
| 66 | return "ATOKEN", nil |
| 67 | }, |
| 68 | InputFunc: func(_, _ string) (string, error) { |
| 69 | return "Test Key", nil |
| 70 | }, |
| 71 | }, |
| 72 | |
| 73 | Hostname: "example.com", |
| 74 | Interactive: true, |
| 75 | }, |
| 76 | httpStubs: func(t *testing.T, reg *httpmock.Registry) { |
| 77 | reg.Register( |
| 78 | httpmock.REST("GET", "api/v3/"), |
| 79 | httpmock.ScopesResponder("repo,read:org")) |
| 80 | reg.Register( |
| 81 | httpmock.GraphQL(`query UserCurrent\b`), |
| 82 | httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`)) |
| 83 | reg.Register( |
| 84 | httpmock.REST("GET", "api/v3/user/keys"), |
| 85 | httpmock.StringResponse(`[]`)) |
| 86 | reg.Register( |
| 87 | httpmock.REST("POST", "api/v3/user/keys"), |
| 88 | httpmock.StringResponse(`{}`)) |
| 89 | }, |
| 90 | runStubs: func(t *testing.T, cs *run.CommandStubber, opts *LoginOptions) { |
| 91 | dir := t.TempDir() |
nothing calls this directly
no test coverage detected