MCPcopy
hub / github.com/cli/cli / Test_loginRun_Survey

Function Test_loginRun_Survey

pkg/cmd/auth/login/login_test.go:520–833  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

518}
519
520func Test_loginRun_Survey(t *testing.T) {
521 stubHomeDir(t, t.TempDir())
522
523 tests := []struct {
524 name string
525 opts *LoginOptions
526 httpStubs func(*httpmock.Registry)
527 prompterStubs func(*prompter.PrompterMock)
528 runStubs func(*run.CommandStubber)
529 cfgStubs func(*testing.T, gh.Config)
530 wantHosts string
531 wantErrOut *regexp.Regexp
532 wantSecureToken string
533 }{
534 {
535 name: "hostname set",
536 opts: &LoginOptions{
537 Hostname: "rebecca.chambers",
538 Interactive: true,
539 InsecureStorage: true,
540 },
541 wantHosts: heredoc.Doc(`
542 rebecca.chambers:
543 users:
544 jillv:
545 oauth_token: def456
546 git_protocol: https
547 oauth_token: def456
548 user: jillv
549 `),
550 prompterStubs: func(pm *prompter.PrompterMock) {
551 pm.SelectFunc = func(prompt, _ string, opts []string) (int, error) {
552 switch prompt {
553 case "What is your preferred protocol for Git operations on this host?":
554 return prompter.IndexFor(opts, "HTTPS")
555 case "How would you like to authenticate GitHub CLI?":
556 return prompter.IndexFor(opts, "Paste an authentication token")
557 }
558 return -1, prompter.NoSuchPromptErr(prompt)
559 }
560 },
561 runStubs: func(rs *run.CommandStubber) {
562 rs.Register(`git config credential\.https:/`, 1, "")
563 rs.Register(`git config credential\.helper`, 1, "")
564 },
565 httpStubs: func(reg *httpmock.Registry) {
566 reg.Register(httpmock.REST("GET", "api/v3/"), httpmock.ScopesResponder("repo,read:org"))
567 reg.Register(
568 httpmock.GraphQL(`query UserCurrent\b`),
569 httpmock.StringResponse(`{"data":{"viewer":{"login":"jillv"}}}`))
570 },
571 wantErrOut: regexp.MustCompile("Tip: you can generate a Personal Access Token here https://rebecca.chambers/settings/tokens"),
572 },
573 {
574 name: "choose Other",
575 wantHosts: heredoc.Doc(`
576 brad.vickers:
577 users:

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
TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
StubFunction · 0.92
stubHomeDirFunction · 0.85

Tested by

no test coverage detected