Skip to content

Commit

Permalink
feat: cast environment variable values to string
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Jun 23, 2020
1 parent ad8cf16 commit 6e0097e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions package/lib/compileFunctions.js
Expand Up @@ -46,10 +46,13 @@ module.exports = {
'nodejs8';
funcTemplate.properties.timeout =
_.get(funcObject, 'timeout') || _.get(this, 'serverless.service.provider.timeout') || '60s';
funcTemplate.properties.environmentVariables = _.merge(
{},
_.get(this, 'serverless.service.provider.environment'),
funcObject.environment // eslint-disable-line comma-dangle
funcTemplate.properties.environmentVariables = _.mapValues(
_.merge(
{},
_.get(this, 'serverless.service.provider.environment'),
funcObject.environment // eslint-disable-line comma-dangle
),
(value) => value.toString()
);

if (!funcTemplate.properties.serviceAccountEmail) {
Expand Down
16 changes: 16 additions & 0 deletions package/lib/compileFunctions.test.js
Expand Up @@ -376,6 +376,9 @@ describe('CompileFunctions', () => {
handler: 'func1',
environment: {
TEST_VAR: 'test',
INT_VAR: 1,
FLOAT_VAR: 3.141,
BOOL_VAR: true,
},
events: [{ http: 'foo' }],
},
Expand All @@ -393,6 +396,9 @@ describe('CompileFunctions', () => {
availableMemoryMb: 256,
environmentVariables: {
TEST_VAR: 'test',
INT_VAR: '1',
FLOAT_VAR: '3.141',
BOOL_VAR: 'true',
},
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
Expand Down Expand Up @@ -421,6 +427,9 @@ describe('CompileFunctions', () => {
};
googlePackage.serverless.service.provider.environment = {
TEST_VAR: 'test',
INT_VAR: 1,
FLOAT_VAR: 3.141,
BOOL_VAR: true,
};

const compiledResources = [
Expand All @@ -435,6 +444,9 @@ describe('CompileFunctions', () => {
availableMemoryMb: 256,
environmentVariables: {
TEST_VAR: 'test',
INT_VAR: '1',
FLOAT_VAR: '3.141',
BOOL_VAR: 'true',
},
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
Expand All @@ -461,13 +473,15 @@ describe('CompileFunctions', () => {
environment: {
TEST_VAR: 'test_var',
TEST_VALUE: 'foobar',
TEST_BOOL: true,
},
events: [{ http: 'foo' }],
},
};
googlePackage.serverless.service.provider.environment = {
TEST_VAR: 'test',
TEST_FOO: 'foo',
TEST_BOOL: false,
};

const compiledResources = [
Expand All @@ -484,6 +498,7 @@ describe('CompileFunctions', () => {
TEST_VAR: 'test_var',
TEST_VALUE: 'foobar',
TEST_FOO: 'foo',
TEST_BOOL: 'true',
},
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
Expand All @@ -503,6 +518,7 @@ describe('CompileFunctions', () => {
expect(googlePackage.serverless.service.provider.environment).toEqual({
TEST_VAR: 'test',
TEST_FOO: 'foo',
TEST_BOOL: false,
});
});
});
Expand Down

0 comments on commit 6e0097e

Please sign in to comment.