waitForToken polls until the manager has a token or the deadline passes. The authorization-code flow completes asynchronously after the callback fires, so tests wait for the resulting token rather than sleeping a fixed duration.
(t *testing.T, m *Manager)
| 203 | // authorization-code flow completes asynchronously after the callback fires, so |
| 204 | // tests wait for the resulting token rather than sleeping a fixed duration. |
| 205 | func waitForToken(t *testing.T, m *Manager) string { |
| 206 | t.Helper() |
| 207 | deadline := time.Now().Add(3 * time.Second) |
| 208 | for time.Now().Before(deadline) { |
| 209 | if tok := m.AccessToken(); tok != "" { |
| 210 | return tok |
| 211 | } |
| 212 | time.Sleep(5 * time.Millisecond) |
| 213 | } |
| 214 | t.Fatal("timed out waiting for access token") |
| 215 | return "" |
| 216 | } |
no test coverage detected