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