Skip to content

Commit

Permalink
Merge 2e3373e into 1e8dbb1
Browse files Browse the repository at this point in the history
  • Loading branch information
nethunter committed Sep 22, 2018
2 parents 1e8dbb1 + 2e3373e commit a73cac8
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
9 changes: 9 additions & 0 deletions package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ module.exports = {
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,
);

if (!_.size(funcTemplate.properties.environmentVariables)) {
delete funcTemplate.properties.environmentVariables;
}

funcTemplate.properties.labels = _.assign({},
_.get(this, 'serverless.service.provider.labels') || {},
_.get(funcObject, 'labels') || {},
Expand Down
80 changes: 80 additions & 0 deletions package/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,86 @@ describe('CompileFunctions', () => {
});
});

it('should set the environment variables based on the function configuration', () => {
googlePackage.serverless.service.functions = {
func1: {
handler: 'func1',
environment: {
TEST_VAR: 'test',
},
events: [
{ http: 'foo' },
],
}
};

const compiledResources = [{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
runtime: 'nodejs8',
function: 'func1',
availableMemoryMb: 256,
environmentVariables: {
TEST_VAR: 'test',
},
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
labels: {},
},
}];

return googlePackage.compileFunctions().then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources)
.toEqual(compiledResources);
});
});

it('should set the environment variables based on the provider configuration', () => {
googlePackage.serverless.service.functions = {
func1: {
handler: 'func1',
events: [
{ http: 'foo' },
],
},
};
googlePackage.serverless.service.provider.environment = {
TEST_VAR: 'test',
};

const compiledResources = [{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
runtime: 'nodejs8',
function: 'func1',
availableMemoryMb: 256,
environmentVariables: {
TEST_VAR: 'test',
},
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
labels: {},
},
}];

return googlePackage.compileFunctions().then(() => {
expect(consoleLogStub.calledOnce).toEqual(true);
expect(googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources)
.toEqual(compiledResources);
});
});

it('should compile "http" events properly', () => {
googlePackage.serverless.service.functions = {
func1: {
Expand Down

0 comments on commit a73cac8

Please sign in to comment.