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

Function TestRefreshTelemetry

internal/config/refreshable_telemetry_test.go:52–347  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

50}
51
52func TestRefreshTelemetry(t *testing.T) {
53 host := "github.com"
54 user := "test-user"
55 future := time.Now().Add(8 * time.Hour)
56
57 tests := []struct {
58 name string
59 secure bool
60 lockErr error
61 whileLock func(t *testing.T)
62 // setup runs after the expiring credential is stored.
63 setup func(t *testing.T)
64 refresher func(t *testing.T) gh.TokenRefresher
65 wantOutcome string
66 wantLock string
67 wantStorage string
68 // wantStorageError defaults to "none".
69 wantStorageError string
70 wantWarning string
71 }{
72 {
73 name: "renewed by a peer while waiting for the lock",
74 secure: true,
75 whileLock: func(t *testing.T) {
76 setRefreshableKeyring(t, host, user, gh.Credential{Token: "peer-access", RefreshToken: "peer-refresh", ExpiresAt: &future})
77 },
78 refresher: func(*testing.T) gh.TokenRefresher { return renewingRefresher() },
79 wantOutcome: "already_fresh",
80 wantLock: "held",
81 wantStorage: "keyring",
82 },
83 {
84 name: "refreshed",
85 refresher: func(*testing.T) gh.TokenRefresher { return renewingRefresher() },
86 wantOutcome: "done",
87 wantLock: "held",
88 wantStorage: "plaintext",
89 },
90 {
91 name: "refreshed without the lock after a timeout",
92 secure: true,
93 lockErr: flock.ErrTimeout,
94 refresher: func(*testing.T) gh.TokenRefresher { return renewingRefresher() },
95 wantOutcome: "done",
96 wantLock: "timeout",
97 wantStorage: "keyring",
98 },
99 {
100 name: "rejected and adopted the peer's credential",
101 secure: true,
102 refresher: func(t *testing.T) gh.TokenRefresher {
103 return rejectingRefresher(func() {
104 setRefreshableKeyring(t, host, user, gh.Credential{Token: "peer-access", RefreshToken: "peer-refresh", ExpiresAt: &future})
105 })
106 },
107 wantOutcome: "rejected_adopted",
108 wantLock: "held",
109 wantStorage: "keyring",

Callers

nothing calls this directly

Calls 15

SetFunction · 0.92
MockInitFunction · 0.92
setRefreshableKeyringFunction · 0.85
rejectingRefresherFunction · 0.85
stubKeyringDeleteFunction · 0.85
refreshableServiceNameFunction · 0.85
newTestAuthConfigFunction · 0.85
JoinMethod · 0.80
setupMethod · 0.80
EqualMethod · 0.80
EmptyMethod · 0.80

Tested by

no test coverage detected