Skip to content

Commit

Permalink
Handle upgrade from SLS projects correctly.
Browse files Browse the repository at this point in the history
Added more unit tests.
  • Loading branch information
Frank Schmid committed Jun 6, 2017
1 parent 275c716 commit 62d1c9e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
5 changes: 4 additions & 1 deletion lib/stackops/lambdaRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ module.exports = function(currentTemplate, aliasStackTemplates, currentAliasStac
func.DependsOn[dependencyIndex] = roleName;
});

if (_.isEmpty(utils.findReferences(currentTemplate.Resources, 'IamRoleLambdaExecution')) && _.has(currentTemplate, 'Resources.IamRoleLambdaExecution')) {
if (_.has(currentTemplate, 'Resources.IamRoleLambdaExecution')) {
if (!_.isEmpty(utils.findReferences(currentTemplate.Resources, 'IamRoleLambdaExecution'))) {
stageStack.Resources.IamRoleLambdaExecution = currentTemplate.Resources.IamRoleLambdaExecution;
}
delete currentTemplate.Resources.IamRoleLambdaExecution;
}

Expand Down
38 changes: 36 additions & 2 deletions test/stackops/lambdaRole.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,47 @@ describe('lambdaRole', () => {
let stack;

beforeEach(() => {
stack = _.clone(require('../data/sls-stack-1.json'));
})
stack = _.cloneDeep(require('../data/sls-stack-1.json'));
});

it('should succeed with standard template', () => {
serverless.service.provider.compiledCloudFormationTemplate = stack;
return expect(awsAlias.aliasHandleLambdaRole({}, [], {})).to.be.fulfilled;
});

it('should remove old global IAM role when there are no references', () => {
const currentTemplate = {
Resources: {
IamRoleLambdaExecution: {}
},
Outputs: {}
};
serverless.service.provider.compiledCloudFormationTemplate = stack;
return expect(awsAlias.aliasHandleLambdaRole(currentTemplate, [], {})).to.be.fulfilled
.then(() => expect(currentTemplate).to.not.have.a.property('IamRoleLambdaExecution'));
});

it('should retain existing alias roles', () => {
const aliasTemplates = [{
Resources: {},
Outputs: {
ServerlessAliasName: {
Description: 'The current alias',
Value: 'testAlias'
}
}
}];
const currentTemplate = {
Resources: {
IamRoleLambdaExecution: {},
IamRoleLambdaExecutiontestAlias: {}
},
Outputs: {}
};
const stackTemplate = serverless.service.provider.compiledCloudFormationTemplate = stack;
return expect(awsAlias.aliasHandleLambdaRole(currentTemplate, aliasTemplates, {})).to.be.fulfilled
.then(() => expect(stackTemplate).to.have.a.deep.property('Resources.IamRoleLambdaExecutiontestAlias'));
});

});
});

0 comments on commit 62d1c9e

Please sign in to comment.