Refac: Centralize storage file management (#4078)

Co-authored-by: Taylor Mullen <ntaylormullen@google.com>
This commit is contained in:
Yuki Okita
2025-08-20 10:55:47 +09:00
committed by GitHub
parent 6f5fca4bf4
commit fbbf39b059
50 changed files with 889 additions and 532 deletions
+10 -4
View File
@@ -11,7 +11,7 @@ import {
clearCachedCredentialFile,
clearOauthClientCache,
} from './oauth2.js';
import { getCachedGoogleAccount } from '../utils/user_account.js';
import { UserAccountManager } from '../utils/userAccountManager.js';
import { OAuth2Client, Compute } from 'google-auth-library';
import * as fs from 'fs';
import * as path from 'path';
@@ -180,7 +180,10 @@ describe('oauth2', () => {
});
// Verify the getCachedGoogleAccount function works
expect(getCachedGoogleAccount()).toBe('test-google-account@gmail.com');
const userAccountManager = new UserAccountManager();
expect(userAccountManager.getCachedGoogleAccount()).toBe(
'test-google-account@gmail.com',
);
});
it('should perform login with user code', async () => {
@@ -533,14 +536,17 @@ describe('oauth2', () => {
googleAccountPath,
JSON.stringify(accountData),
);
const userAccountManager = new UserAccountManager();
expect(fs.existsSync(credsPath)).toBe(true);
expect(fs.existsSync(googleAccountPath)).toBe(true);
expect(getCachedGoogleAccount()).toBe('test@example.com');
expect(userAccountManager.getCachedGoogleAccount()).toBe(
'test@example.com',
);
await clearCachedCredentialFile();
expect(fs.existsSync(credsPath)).toBe(false);
expect(getCachedGoogleAccount()).toBeNull();
expect(userAccountManager.getCachedGoogleAccount()).toBeNull();
const updatedAccountData = JSON.parse(
fs.readFileSync(googleAccountPath, 'utf-8'),
);