Skip to content

Commit

Permalink
enhance test
Browse files Browse the repository at this point in the history
  • Loading branch information
sai-sunder-s committed Nov 4, 2022
1 parent 3e69699 commit 786f566
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/auth/googleauth.ts
Expand Up @@ -375,7 +375,7 @@ export class GoogleAuth<T extends AuthClient = JSONClient> {
): Promise<ADCResponse> {
const projectId = await this.getProjectIdOptional();

if (quotaProjectIdOverride && quotaProjectIdOverride !== '') {
if (quotaProjectIdOverride) {
credential.quotaProjectId = quotaProjectIdOverride;
}

Expand Down
11 changes: 8 additions & 3 deletions test/test.googleauth.ts
Expand Up @@ -1044,14 +1044,19 @@ describe('googleauth', () => {
assert.strictEqual(undefined, client.scope);
});

it('getApplicationDefault should set quota project from environment if available', async () => {
it('explicitly set quota project should not be overriden by environment value', async () => {
mockLinuxWellKnownFile(
'./test/fixtures/config-with-quota/.config/gcloud/application_default_credentials.json'
);
mockEnvVar('GOOGLE_CLOUD_QUOTA_PROJECT', 'quota_from_env');
const result = await auth.getApplicationDefault();
const client = result.credential as JWT;
let result = await auth.getApplicationDefault();
let client = result.credential as JWT;
assert.strictEqual('quota_from_env', client.quotaProjectId);

client.quotaProjectId = 'explicit_quota';
result = await auth.getApplicationDefault();
client = result.credential as JWT;
assert.strictEqual('explicit_quota', client.quotaProjectId);
});

it('getApplicationDefault should use quota project id from file if environment variable is empty', async () => {
Expand Down

0 comments on commit 786f566

Please sign in to comment.