(t *testing.T)
| 557 | } |
| 558 | |
| 559 | func TestTokenRunRefresh(t *testing.T) { |
| 560 | // past and future are relative to the 10 minute refresh leeway: past tokens (or those with no recorded expiry) |
| 561 | // need refreshing, future tokens do not. |
| 562 | past := time.Now().Add(-time.Hour) |
| 563 | future := time.Now().Add(time.Hour) |
| 564 | |
| 565 | tests := []struct { |
| 566 | name string |
| 567 | secureStorage bool |
| 568 | noRefresh bool |
| 569 | setup func(*testing.T, gh.Config) |
| 570 | refresher *ghmock.TokenRefresherMock |
| 571 | wantStdout string |
| 572 | wantErrMsg string |
| 573 | wantRefresh int |
| 574 | wantRefreshTok string |
| 575 | wantStderrContains string |
| 576 | wantStderrOmits string |
| 577 | }{ |
| 578 | { |
| 579 | name: "state 1: expiring refreshable in config is refreshed", |
| 580 | setup: func(t *testing.T, cfg gh.Config) { |
| 581 | loginRefreshableWithExpiry(t, cfg, "github.com", "test-user", "gho_OLD", "ghr_OLD", false, &past) |
| 582 | }, |
| 583 | refresher: renewingRefresher("gho_NEW", "ghr_NEW"), |
| 584 | wantStdout: "gho_NEW\n", |
| 585 | wantRefresh: 1, |
| 586 | wantRefreshTok: "ghr_OLD", |
| 587 | wantStderrContains: "This token will expire", |
| 588 | }, |
| 589 | { |
| 590 | name: "state 1: expiring refreshable in keyring is refreshed", |
| 591 | setup: func(t *testing.T, cfg gh.Config) { |
| 592 | loginRefreshableWithExpiry(t, cfg, "github.com", "test-user", "gho_OLD", "ghr_OLD", true, &past) |
| 593 | }, |
| 594 | refresher: renewingRefresher("gho_NEW", "ghr_NEW"), |
| 595 | wantStdout: "gho_NEW\n", |
| 596 | wantRefresh: 1, |
| 597 | wantRefreshTok: "ghr_OLD", |
| 598 | }, |
| 599 | { |
| 600 | name: "state 1: unexpired refreshable is not refreshed", |
| 601 | setup: func(t *testing.T, cfg gh.Config) { |
| 602 | loginRefreshableWithExpiry(t, cfg, "github.com", "test-user", "gho_OLD", "ghr_OLD", false, &future) |
| 603 | }, |
| 604 | refresher: renewingRefresher("gho_NEW", "ghr_NEW"), |
| 605 | wantStdout: "gho_OLD\n", |
| 606 | wantRefresh: 0, |
| 607 | wantStderrContains: "This token will expire on ", |
| 608 | }, |
| 609 | { |
| 610 | name: "state 1: failed refresh falls back to the stored token", |
| 611 | setup: func(t *testing.T, cfg gh.Config) { |
| 612 | loginRefreshableWithExpiry(t, cfg, "github.com", "test-user", "gho_OLD", "ghr_OLD", false, &past) |
| 613 | }, |
| 614 | refresher: failingRefresher(), |
| 615 | wantStdout: "gho_OLD\n", |
| 616 | wantRefresh: 1, |
nothing calls this directly
no test coverage detected