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

Function TestTokenRunRefresh

pkg/cmd/auth/token/token_test.go:559–783  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

557}
558
559func 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,

Callers

nothing calls this directly

Calls 15

TestFunction · 0.92
NewIsolatedTestConfigFunction · 0.92
expiredRefresherFunction · 0.85
tokenRunFunction · 0.85
setupMethod · 0.80
EqualMethod · 0.80
ContainsMethod · 0.80
RefreshCallsMethod · 0.80
renewingRefresherFunction · 0.70
failingRefresherFunction · 0.70
loginFunction · 0.70

Tested by

no test coverage detected