Skip to content

Commit

Permalink
fix: use FUNCTION_TARGET to detect GCF 10 and above (#748)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored Jul 19, 2019
1 parent 131489e commit ca17685
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/auth/envDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function isAppEngine() {
}

function isCloudFunction() {
return !!process.env.FUNCTION_NAME;
return !!(process.env.FUNCTION_NAME || process.env.FUNCTION_TARGET);
}

async function isKubernetesEngine() {
Expand Down
9 changes: 8 additions & 1 deletion test/test.googleauth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1226,13 +1226,20 @@ describe('googleauth', () => {
scope.done();
});

it('should get the current environment if GCF', async () => {
it('should get the current environment if GCF 8 and below', async () => {
envDetect.clear();
mockEnvVar('FUNCTION_NAME', 'DOGGY');
const env = await auth.getEnv();
assert.strictEqual(env, envDetect.GCPEnv.CLOUD_FUNCTIONS);
});

it('should get the current environment if GCF 10 and up', async () => {
envDetect.clear();
mockEnvVar('FUNCTION_TARGET', 'KITTY');
const env = await auth.getEnv();
assert.strictEqual(env, envDetect.GCPEnv.CLOUD_FUNCTIONS);
});

it('should get the current environment if GAE', async () => {
envDetect.clear();
mockEnvVar('GAE_SERVICE', 'KITTY');
Expand Down

0 comments on commit ca17685

Please sign in to comment.