Skip to content
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
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ class Prune {
}

pruneFunctions() {
const selectedFunctions = this.options.function ? [this.options.function] : this.serverless.service.getAllFunctions();
const selectedFunctions = this.options.function ? [this.options.function] :
(this.serverless.service.provider.versionFunctions === false ? this.serverless.service.getAllFunctions().filter(key => this.serverless.service.getFunction(key).provisionedConcurrency) : this.serverless.service.getAllFunctions());
const functionNames = selectedFunctions.map(key => this.serverless.service.getFunction(key).name);

this.createProgress(
Expand Down
29 changes: 26 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ describe('Prune', function() {
return Object.assign(serverless, withLayers);
}

function createMockServerless(functions, serviceCustom) {
function createMockServerless(functions, serviceCustom, versionFunctions) {
let functionObjects = (functions || []).map(key => typeof key === 'object' ? Object.assign({}, key, {name: `service-${key.name}`}) : ({ name: `service-${key}`}));
const serverless = {
getProvider: sinon.stub(),
cli: { log: sinon.stub() },
service: {
getAllFunctions: () => functions,
getFunction: (key) => { return { name:`service-${key}` }; },
provider: { versionFunctions: true },
functions: functionObjects,
getAllFunctions: () => functions.map(f => typeof f === 'string' ? f : f.name),
getFunction: (key) => functionObjects.find(f => f.name === `service-${key}`) || {name: `service-${key}`},
custom: serviceCustom
}
};
if (versionFunctions !== undefined) {
serverless.service.provider.versionFunctions = versionFunctions;
}
const provider = { request: sinon.stub() };
serverless.getProvider.withArgs('aws').returns(provider);

Expand Down Expand Up @@ -335,6 +341,23 @@ describe('Prune', function() {

});

it('should ignore functions that have no provisioned concurrency when versioning is turned off on service', function() {

const serverless = createMockServerless([{name: 'FunctionA'}, {name: 'FunctionB', provisionedConcurrency: 1}], null, false);
const plugin = new PrunePlugin(serverless, { number: 1 });

plugin.provider.request.withArgs('Lambda', 'listVersionsByFunction', sinon.match.any)
.returns(createVersionsResponse([1, 2, 3, 4, 5]));

plugin.provider.request.withArgs('Lambda', 'listAliases', sinon.match.any)
.returns(createAliasResponse([]));

return plugin.pruneFunctions().then(() => {
sinon.assert.neverCalledWith(plugin.provider.request, 'Lambda', 'listVersionsByFunction', functionMatcher('service-FunctionA'));
sinon.assert.calledWith(plugin.provider.request, 'Lambda', 'listVersionsByFunction', functionMatcher('service-FunctionB'));
});
});

it('should only operate on target function if specified from CLI', function() {

const serverless = createMockServerless(['FunctionA', 'FunctionB', 'FunctionC']);
Expand Down