Skip to content

Commit 6e0097e

Browse files
committed
feat: cast environment variable values to string
1 parent ad8cf16 commit 6e0097e

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

package/lib/compileFunctions.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@ module.exports = {
4646
'nodejs8';
4747
funcTemplate.properties.timeout =
4848
_.get(funcObject, 'timeout') || _.get(this, 'serverless.service.provider.timeout') || '60s';
49-
funcTemplate.properties.environmentVariables = _.merge(
50-
{},
51-
_.get(this, 'serverless.service.provider.environment'),
52-
funcObject.environment // eslint-disable-line comma-dangle
49+
funcTemplate.properties.environmentVariables = _.mapValues(
50+
_.merge(
51+
{},
52+
_.get(this, 'serverless.service.provider.environment'),
53+
funcObject.environment // eslint-disable-line comma-dangle
54+
),
55+
(value) => value.toString()
5356
);
5457

5558
if (!funcTemplate.properties.serviceAccountEmail) {

package/lib/compileFunctions.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,9 @@ describe('CompileFunctions', () => {
376376
handler: 'func1',
377377
environment: {
378378
TEST_VAR: 'test',
379+
INT_VAR: 1,
380+
FLOAT_VAR: 3.141,
381+
BOOL_VAR: true,
379382
},
380383
events: [{ http: 'foo' }],
381384
},
@@ -393,6 +396,9 @@ describe('CompileFunctions', () => {
393396
availableMemoryMb: 256,
394397
environmentVariables: {
395398
TEST_VAR: 'test',
399+
INT_VAR: '1',
400+
FLOAT_VAR: '3.141',
401+
BOOL_VAR: 'true',
396402
},
397403
timeout: '60s',
398404
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
@@ -421,6 +427,9 @@ describe('CompileFunctions', () => {
421427
};
422428
googlePackage.serverless.service.provider.environment = {
423429
TEST_VAR: 'test',
430+
INT_VAR: 1,
431+
FLOAT_VAR: 3.141,
432+
BOOL_VAR: true,
424433
};
425434

426435
const compiledResources = [
@@ -435,6 +444,9 @@ describe('CompileFunctions', () => {
435444
availableMemoryMb: 256,
436445
environmentVariables: {
437446
TEST_VAR: 'test',
447+
INT_VAR: '1',
448+
FLOAT_VAR: '3.141',
449+
BOOL_VAR: 'true',
438450
},
439451
timeout: '60s',
440452
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
@@ -461,13 +473,15 @@ describe('CompileFunctions', () => {
461473
environment: {
462474
TEST_VAR: 'test_var',
463475
TEST_VALUE: 'foobar',
476+
TEST_BOOL: true,
464477
},
465478
events: [{ http: 'foo' }],
466479
},
467480
};
468481
googlePackage.serverless.service.provider.environment = {
469482
TEST_VAR: 'test',
470483
TEST_FOO: 'foo',
484+
TEST_BOOL: false,
471485
};
472486

473487
const compiledResources = [
@@ -484,6 +498,7 @@ describe('CompileFunctions', () => {
484498
TEST_VAR: 'test_var',
485499
TEST_VALUE: 'foobar',
486500
TEST_FOO: 'foo',
501+
TEST_BOOL: 'true',
487502
},
488503
timeout: '60s',
489504
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
@@ -503,6 +518,7 @@ describe('CompileFunctions', () => {
503518
expect(googlePackage.serverless.service.provider.environment).toEqual({
504519
TEST_VAR: 'test',
505520
TEST_FOO: 'foo',
521+
TEST_BOOL: false,
506522
});
507523
});
508524
});

0 commit comments

Comments
 (0)