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

Function Test_authRecoveryCommand

internal/ghcmd/cmd_test.go:631–700  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

629}
630
631func Test_authRecoveryCommand(t *testing.T) {
632 tests := []struct {
633 name string
634 token string
635 source string
636 requestURL string
637 want string
638 }{
639 {
640 name: "stored oauth token",
641 token: "gho_abc123",
642 source: "oauth_token",
643 requestURL: "https://api.github.com/graphql",
644 want: "gh auth refresh -h github.com",
645 },
646 {
647 name: "stored pat",
648 token: "github_pat_abc123",
649 source: "oauth_token",
650 requestURL: "https://api.github.com/graphql",
651 want: "gh auth login -h github.com",
652 },
653 {
654 name: "env token",
655 token: "gho_abc123",
656 source: "GH_TOKEN",
657 requestURL: "https://api.github.com/graphql",
658 want: "gh auth login -h github.com",
659 },
660 {
661 name: "missing request url",
662 token: "gho_abc123",
663 source: "oauth_token",
664 want: "gh auth login",
665 },
666 }
667
668 for _, tt := range tests {
669 t.Run(tt.name, func(t *testing.T) {
670 authCfg := config.NewMockConfig().Authentication()
671 authCfg.SetActiveToken(tt.token, tt.source)
672 cfg := &ghmock.ConfigMock{
673 AuthenticationFunc: func() gh.AuthConfig {
674 return authCfg
675 },
676 }
677
678 var requestURL *url.URL
679 if tt.requestURL != "" {
680 var err error
681 requestURL, err = url.Parse(tt.requestURL)
682 if err != nil {
683 t.Fatalf("failed to parse request URL: %v", err)
684 }
685 }
686
687 httpErr := api.HTTPError{
688 HTTPError: &ghAPI.HTTPError{

Callers

nothing calls this directly

Calls 6

NewMockConfigFunction · 0.92
authRecoveryCommandFunction · 0.85
RunMethod · 0.65
AuthenticationMethod · 0.65
SetActiveTokenMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected