Skip to content

fix: Fix deployment status when the function name is specified #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2020
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
5 changes: 2 additions & 3 deletions info/lib/displayServiceInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ module.exports = {

const getFunctionNameInService = (funcName, service, stage) => {
let funcNameInService = funcName;
funcNameInService = funcNameInService.replace(service, '');
funcNameInService = funcNameInService.replace(stage, '');
funcNameInService = funcNameInService.slice(2, funcNameInService.length);
funcNameInService = funcNameInService.replace(`${service}-`, '');
funcNameInService = funcNameInService.replace(`${stage}-`, '');
return funcNameInService;
};
40 changes: 38 additions & 2 deletions info/lib/displayServiceInfo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ describe('DisplayServiceInfo', () => {
serverless = new Serverless();
serverless.service.service = 'my-service';
serverless.service.functions = {
func1: {
'func1': {
handler: 'handler',
events: [{ http: 'foo' }],
},
func2: {
'func2': {
handler: 'handler',
events: [
{
Expand All @@ -32,6 +32,11 @@ describe('DisplayServiceInfo', () => {
},
],
},
'my-func3': {
name: 'my-func3',
handler: 'handler',
events: [{ http: 'foo' }],
},
};
serverless.service.provider = {
project: 'my-project',
Expand Down Expand Up @@ -131,6 +136,37 @@ describe('DisplayServiceInfo', () => {
});
});

it('should gather the resource data when the function name is specified', () => {
const resources = {
resources: [
{ type: 'resource.which.should.be.filterered', name: 'someResource' },
{
type: 'gcp-types/cloudfunctions-v1:projects.locations.functions',
name: 'my-func3',
},
],
};

const expectedData = {
service: 'my-service',
project: 'my-project',
stage: 'dev',
region: 'us-central1',
resources: {
functions: [
{
name: 'my-func3',
resource: 'https://us-central1-my-project.cloudfunctions.net/my-func3',
},
],
},
};

return googleInfo.gatherData(resources).then((data) => {
expect(data).toEqual(expectedData);
});
});

it('should resolve with empty data if resource type is not matching', () => {
const resources = {
resources: [{ type: 'resource.which.should.be.filterered', name: 'someResource' }],
Expand Down
7 changes: 5 additions & 2 deletions test/serverless.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ class Serverless {
};
this.service.getFunction = function (functionName) {
//eslint-disable-line
// NOTE the stage is always 'dev'!
this.functions[functionName].name = `${this.service}-dev-${functionName}`;
// NOTE assign the function name only when it is not specified
if (!this.functions[functionName].name) {
// NOTE the stage is always 'dev'!
this.functions[functionName].name = `${this.service}-dev-${functionName}`;
}
return this.functions[functionName];
};
this.utils = {
Expand Down