(t *testing.T)
| 548 | } |
| 549 | |
| 550 | func 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{ |
nothing calls this directly
no test coverage detected