Skip to content

Commit c63fa18

Browse files
committed
feat: cast environment variable values to string
1 parent 0bb6cae commit c63fa18

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
@@ -47,10 +47,13 @@ module.exports = {
4747
'nodejs8';
4848
funcTemplate.properties.timeout =
4949
_.get(funcObject, 'timeout') || _.get(this, 'serverless.service.provider.timeout') || '60s';
50-
funcTemplate.properties.environmentVariables = _.merge(
51-
{},
52-
_.get(this, 'serverless.service.provider.environment'),
53-
funcObject.environment // eslint-disable-line comma-dangle
50+
funcTemplate.properties.environmentVariables = _.mapValues(
51+
_.merge(
52+
{},
53+
_.get(this, 'serverless.service.provider.environment'),
54+
funcObject.environment // eslint-disable-line comma-dangle
55+
),
56+
(value) => value.toString()
5457
);
5558
funcTemplate.accessControl.gcpIamPolicy.bindings = _.unionBy(
5659
_.get(funcObject, 'iam.bindings'),

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)