Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ module.exports = {
funcTemplate.properties.timeout = _.get(funcObject, 'timeout')
|| _.get(this, 'serverless.service.provider.timeout')
|| '60s';
funcTemplate.properties.labels = _.assign({},
_.get(this, 'serverless.service.provider.labels') || {},
_.get(funcObject, 'labels') || {},
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this makes much more sense now after your comment in #94


const eventType = Object.keys(funcObject.events[0])[0];

Expand Down
126 changes: 126 additions & 0 deletions package/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ describe('CompileFunctions', () => {
httpsTrigger: {
url: 'foo',
},
labels: {},
},
}];

Expand Down Expand Up @@ -153,6 +154,7 @@ describe('CompileFunctions', () => {
httpsTrigger: {
url: 'foo',
},
labels: {},
},
}];

Expand Down Expand Up @@ -186,6 +188,7 @@ describe('CompileFunctions', () => {
httpsTrigger: {
url: 'foo',
},
labels: {},
},
}];

Expand Down Expand Up @@ -219,6 +222,126 @@ describe('CompileFunctions', () => {
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 labels based on the functions configuration', () => {
googlePackage.serverless.service.functions = {
func1: {
handler: 'func1',
labels: {
test: 'label',
},
events: [
{ http: 'foo' },
],
},
};

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

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

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

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

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

it('should set the labels based on the merged provider and function configuration', () => {
googlePackage.serverless.service.functions = {
func1: {
handler: 'func1',
events: [
{ http: 'foo' },
],
labels: {
test: 'functionLabel',
},
},
};
googlePackage.serverless.service.provider.labels = {
test: 'providerLabel',
secondTest: 'tested',
};

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

Expand Down Expand Up @@ -251,6 +374,7 @@ describe('CompileFunctions', () => {
httpsTrigger: {
url: 'foo',
},
labels: {},
},
}];

Expand Down Expand Up @@ -303,6 +427,7 @@ describe('CompileFunctions', () => {
path: 'some-path',
resource: 'some-resource',
},
labels: {},
},
},
{
Expand All @@ -318,6 +443,7 @@ describe('CompileFunctions', () => {
eventType: 'foo',
resource: 'some-resource',
},
labels: {},
},
},
];
Expand Down