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

Function TestLogin

pkg/cmd/auth/shared/login_flow_test.go:156–591  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

154}
155
156func TestLogin(t *testing.T) {
157 tests := []struct {
158 name string
159 opts LoginOptions
160 httpStubs func(*testing.T, *httpmock.Registry)
161 runStubs func(*testing.T, *run.CommandStubber, *LoginOptions)
162 wantsConfig map[string]string
163 wantsErr string
164 stdout string
165 stderr string
166 stderrAssert func(*testing.T, *LoginOptions, string)
167 }{
168 {
169 name: "tty, prompt (protocol: ssh, create key: yes)",
170 opts: LoginOptions{
171 Prompter: &prompter.PrompterMock{
172 SelectFunc: func(prompt, _ string, opts []string) (int, error) {
173 switch prompt {
174 case "What is your preferred protocol for Git operations on this host?":
175 return prompter.IndexFor(opts, "SSH")
176 case "How would you like to authenticate GitHub CLI?":
177 return prompter.IndexFor(opts, "Paste an authentication token")
178 }
179 return -1, prompter.NoSuchPromptErr(prompt)
180 },
181 PasswordFunc: func(_ string) (string, error) {
182 return "monkey", nil
183 },
184 ConfirmFunc: func(prompt string, _ bool) (bool, error) {
185 return true, nil
186 },
187 AuthTokenFunc: func() (string, error) {
188 return "ATOKEN", nil
189 },
190 InputFunc: func(_, _ string) (string, error) {
191 return "Test Key", nil
192 },
193 },
194
195 Hostname: "example.com",
196 Interactive: true,
197 },
198 httpStubs: func(t *testing.T, reg *httpmock.Registry) {
199 reg.Register(
200 httpmock.REST("GET", "api/v3/"),
201 httpmock.ScopesResponder("repo,read:org"))
202 reg.Register(
203 httpmock.GraphQL(`query UserCurrent\b`),
204 httpmock.StringResponse(`{"data":{"viewer":{ "login": "monalisa" }}}`))
205 reg.Register(
206 httpmock.REST("GET", "api/v3/user/keys"),
207 httpmock.StringResponse(`[]`))
208 reg.Register(
209 httpmock.REST("POST", "api/v3/user/keys"),
210 httpmock.StringResponse(`{}`))
211 },
212 runStubs: func(t *testing.T, cs *run.CommandStubber, opts *LoginOptions) {
213 dir := t.TempDir()

Callers

nothing calls this directly

Calls 15

RegisterMethod · 0.95
VerifyMethod · 0.95
IndexForFunction · 0.92
NoSuchPromptErrFunction · 0.92
RESTFunction · 0.92
ScopesResponderFunction · 0.92
GraphQLFunction · 0.92
StringResponseFunction · 0.92
NewContextForTestsFunction · 0.92
TestFunction · 0.92
StubFunction · 0.92
LoginFunction · 0.85

Tested by

no test coverage detected