(t *testing.T)
| 252 | } |
| 253 | |
| 254 | func TestGetAccessTokenForceRefreshesToken(t *testing.T) { |
| 255 | authFile := filepath.Join(t.TempDir(), "auth.json") |
| 256 | if err := os.WriteFile(authFile, []byte(`{"":{"personal":"old-token"}}`), 0600); err != nil { |
| 257 | t.Fatal(err) |
| 258 | } |
| 259 | t.Setenv(envAuthFile, authFile) |
| 260 | mockAuthorization(t, "auth-code", "new-token") |
| 261 | |
| 262 | token, filePath, err := getAccessToken(tokenPersonal, "", true) |
| 263 | if err != nil { |
| 264 | t.Fatal(err) |
| 265 | } |
| 266 | if token != "new-token" { |
| 267 | t.Fatalf("expected new token, got %q", token) |
| 268 | } |
| 269 | if filePath != authFile { |
| 270 | t.Fatalf("expected auth file %q, got %q", authFile, filePath) |
| 271 | } |
| 272 | |
| 273 | tokens, err := readTokens(authFile) |
| 274 | if err != nil { |
| 275 | t.Fatal(err) |
| 276 | } |
| 277 | if tokens[""][tokenPersonal].AccessToken != "new-token" { |
| 278 | t.Fatalf("expected saved token to be refreshed, got %q", tokens[""][tokenPersonal].AccessToken) |
| 279 | } |
| 280 | if tokens[""][tokenPersonal].RefreshToken == "" { |
| 281 | t.Fatal("expected saved token to include a refresh token") |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | func TestGetAccessTokenRefreshesExpiredCredential(t *testing.T) { |
| 286 | expired := time.Now().Add(-time.Hour).UTC() |
nothing calls this directly
no test coverage detected