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

Function Test_authRecoveryCommand

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

Source from the content-addressed store, hash-verified

515}
516
517func Test_authRecoveryCommand(t *testing.T) {
518 tests := []struct {
519 name string
520 token string
521 source string
522 requestURL string
523 want string
524 }{
525 {
526 name: "stored oauth token",
527 token: "gho_abc123",
528 source: "oauth_token",
529 requestURL: "https://api.github.com/graphql",
530 want: "gh auth refresh -h github.com",
531 },
532 {
533 name: "stored pat",
534 token: "github_pat_abc123",
535 source: "oauth_token",
536 requestURL: "https://api.github.com/graphql",
537 want: "gh auth login -h github.com",
538 },
539 {
540 name: "env token",
541 token: "gho_abc123",
542 source: "GH_TOKEN",
543 requestURL: "https://api.github.com/graphql",
544 want: "gh auth login -h github.com",
545 },
546 {
547 name: "missing request url",
548 token: "gho_abc123",
549 source: "oauth_token",
550 want: "gh auth login",
551 },
552 }
553
554 for _, tt := range tests {
555 t.Run(tt.name, func(t *testing.T) {
556 authCfg := config.NewMockConfig().Authentication()
557 authCfg.SetActiveToken(tt.token, tt.source)
558 cfg := &ghmock.ConfigMock{
559 AuthenticationFunc: func() gh.AuthConfig {
560 return authCfg
561 },
562 }
563
564 var requestURL *url.URL
565 if tt.requestURL != "" {
566 var err error
567 requestURL, err = url.Parse(tt.requestURL)
568 if err != nil {
569 t.Fatalf("failed to parse request URL: %v", err)
570 }
571 }
572
573 httpErr := api.HTTPError{
574 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