Skip to content
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

refactor: ignore handlers with image.name property #1885

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ function getAllNodeFunctions() {
return _.filter(functions, funcName => {
const func = this.serverless.service.getFunction(funcName);

// if `uri` is provided or simple remote image path, it means the
// if `uri` or `name` is provided or simple remote image path, it means the
// image isn't built by Serverless so we shouldn't take care of it
if ((func.image && func.image.uri) || (func.image && typeof func.image == 'string')) {
if ((func.image && (func.image.uri || func.image.name)) || (func.image && typeof func.image == 'string')) {
return false;
}

Expand Down
59 changes: 59 additions & 0 deletions tests/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,65 @@ describe('Utils', () => {
});
});

describe('getAllNodeFunctions', () => {
it('should return all functions with node runtime', () => {
const mockServerless = {
service: {
getAllFunctions: jest.fn(() => ['foo', 'bar', 'baz']),
getFunction: jest.fn(name => {
if (name === 'foo') {
return { runtime: 'nodejs6.10' };
}
if (name === 'bar') {
return { runtime: 'nodejs8.10' };
}
if (name === 'baz') {
return { runtime: 'python3.6' };
}
})
}
};

expect(Utils.getAllNodeFunctions.call({ serverless: mockServerless })).toEqual(['foo', 'bar']);
});

it('should ignore handlers with image.uri property', () => {
const mockServerless = {
service: {
getAllFunctions: jest.fn(() => ['foo', 'bar']),
getFunction: jest.fn(name => {
if (name === 'foo') {
return { runtime: 'nodejs6.10' };
}
if (name === 'bar') {
return { runtime: 'nodejs8.10', image: { uri: 'fake-image-uri' } };
}
})
}
};

expect(Utils.getAllNodeFunctions.call({ serverless: mockServerless })).toEqual(['foo']);
});

it('should ignore handlers with image.name property', () => {
const mockServerless = {
service: {
getAllFunctions: jest.fn(() => ['foo', 'bar']),
getFunction: jest.fn(name => {
if (name === 'foo') {
return { runtime: 'nodejs6.10' };
}
if (name === 'bar') {
return { runtime: 'nodejs8.10', image: { name: 'fake-image-name' } };
}
})
}
};

expect(Utils.getAllNodeFunctions.call({ serverless: mockServerless })).toEqual(['foo']);
});
});

describe('isProviderGoogle', () => {
describe('when the provider is set to "google"', () => {
const mockServerless = {
Expand Down
Loading