(t *testing.T)
| 50 | } |
| 51 | |
| 52 | func 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", |
nothing calls this directly
no test coverage detected