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

Function Test_authRecoveryCommand

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

Source from the content-addressed store, hash-verified

548}
549
550func Test_authRecoveryCommand(t *testing.T) {
551 tests := []struct {
552 name string
553 token string
554 source string
555 requestURL string
556 want string
557 }{
558 {
559 name: "stored oauth token",
560 token: "gho_abc123",
561 source: "oauth_token",
562 requestURL: "https://api.github.com/graphql",
563 want: "gh auth refresh -h github.com",
564 },
565 {
566 name: "stored pat",
567 token: "github_pat_abc123",
568 source: "oauth_token",
569 requestURL: "https://api.github.com/graphql",
570 want: "gh auth login -h github.com",
571 },
572 {
573 name: "env token",
574 token: "gho_abc123",
575 source: "GH_TOKEN",
576 requestURL: "https://api.github.com/graphql",
577 want: "gh auth login -h github.com",
578 },
579 {
580 name: "missing request url",
581 token: "gho_abc123",
582 source: "oauth_token",
583 want: "gh auth login",
584 },
585 }
586
587 for _, tt := range tests {
588 t.Run(tt.name, func(t *testing.T) {
589 authCfg := config.NewMockConfig().Authentication()
590 authCfg.SetActiveToken(tt.token, tt.source)
591 cfg := &ghmock.ConfigMock{
592 AuthenticationFunc: func() gh.AuthConfig {
593 return authCfg
594 },
595 }
596
597 var requestURL *url.URL
598 if tt.requestURL != "" {
599 var err error
600 requestURL, err = url.Parse(tt.requestURL)
601 if err != nil {
602 t.Fatalf("failed to parse request URL: %v", err)
603 }
604 }
605
606 httpErr := api.HTTPError{
607 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