MCPcopy
hub / github.com/cli/cli / Test_authRecoveryCommand

Function Test_authRecoveryCommand

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected