Skip to content

Commit 52e945b

Browse files
authored
Merge pull request #173 from mather/bugfix/environment-merge
Fix lodash merge function not to update original object.
2 parents 2e50aed + a70161a commit 52e945b

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

package/lib/compileFunctions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ module.exports = {
4444
|| _.get(this, 'serverless.service.provider.timeout')
4545
|| '60s';
4646
funcTemplate.properties.environmentVariables = _.merge(
47+
{},
4748
_.get(this, 'serverless.service.provider.environment'),
4849
funcObject.environment // eslint-disable-line comma-dangle
4950
);

package/lib/compileFunctions.test.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,59 @@ describe('CompileFunctions', () => {
440440
});
441441
});
442442

443+
it('should merge the environment variables on the provider configuration and function definition', () => {
444+
googlePackage.serverless.service.functions = {
445+
func1: {
446+
handler: 'func1',
447+
environment: {
448+
TEST_VAR: 'test_var',
449+
TEST_VALUE: 'foobar',
450+
},
451+
events: [
452+
{ http: 'foo' },
453+
],
454+
},
455+
};
456+
googlePackage.serverless.service.provider.environment = {
457+
TEST_VAR: 'test',
458+
TEST_FOO: 'foo',
459+
};
460+
461+
const compiledResources = [{
462+
type: 'gcp-types/cloudfunctions-v1:projects.locations.functions',
463+
name: 'my-service-dev-func1',
464+
properties: {
465+
parent: 'projects/myProject/locations/us-central1',
466+
runtime: 'nodejs8',
467+
function: 'my-service-dev-func1',
468+
entryPoint: 'func1',
469+
availableMemoryMb: 256,
470+
environmentVariables: {
471+
TEST_VAR: 'test_var',
472+
TEST_VALUE: 'foobar',
473+
TEST_FOO: 'foo',
474+
},
475+
timeout: '60s',
476+
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
477+
httpsTrigger: {
478+
url: 'foo',
479+
},
480+
labels: {},
481+
},
482+
}];
483+
484+
return googlePackage.compileFunctions().then(() => {
485+
expect(consoleLogStub.calledOnce).toEqual(true);
486+
expect(googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources)
487+
.toEqual(compiledResources);
488+
expect(googlePackage.serverless.service.provider.environment)
489+
.toEqual({
490+
TEST_VAR: 'test',
491+
TEST_FOO: 'foo',
492+
});
493+
});
494+
});
495+
443496
it('should compile "http" events properly', () => {
444497
googlePackage.serverless.service.functions = {
445498
func1: {

0 commit comments

Comments
 (0)