Skip to content

Commit

Permalink
fix: Recognize final DELETE_COMPLETE event with verbose flag (#7979)
Browse files Browse the repository at this point in the history
  • Loading branch information
herebebogans authored Jul 24, 2020
1 parent e68e116 commit e980625
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/aws/lib/monitorStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports = {
(!this.options.verbose ||
(stackStatus &&
(stackStatus.endsWith('ROLLBACK_COMPLETE') ||
stackStatus === 'DELETE_FAILED')))
['DELETE_FAILED', 'DELETE_COMPLETE'].includes(stackStatus))))
) {
// empty console.log for a prettier output
if (!this.options.verbose) this.serverless.cli.consoleLog('');
Expand Down
80 changes: 80 additions & 0 deletions lib/plugins/aws/lib/monitorStack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,86 @@ describe('monitorStack', () => {
}
);

it(
'should throw an error if stack status is DELETE_COMPLETE and should output all ' +
'stack events information with the --verbose option',
() => {
awsPlugin.options.verbose = true;
const describeStackEventsStub = sinon.stub(awsPlugin.provider, 'request');
const cfDataMock = {
StackId: 'new-service-dev',
};
const createStartEvent = {
StackEvents: [
{
EventId: '1a2b3c4d',
StackName: 'new-service-dev',
LogicalResourceId: 'new-service-dev',
ResourceType: 'AWS::CloudFormation::Stack',
Timestamp: new Date(),
ResourceStatus: 'CREATE_IN_PROGRESS',
},
],
};
const createItemFailedEvent = {
StackEvents: [
{
EventId: '1e2f3g4h',
StackName: 'new-service-dev',
LogicalResourceId: 'myBucket',
ResourceType: 'AWS::S3::Bucket',
Timestamp: new Date(),
ResourceStatus: 'CREATE_FAILED',
ResourceStatusReason: 'Invalid Property for X',
},
],
};
const createItemDeleteEvent = {
StackEvents: [
{
EventId: '1i2j3k4l',
StackName: 'new-service-dev',
LogicalResourceId: 'myBucket',
ResourceType: 'AWS::S3::Bucket',
Timestamp: new Date(),
ResourceStatus: 'DELETE_IN_PROGRESS',
},
],
};
const createFailedEvent = {
StackEvents: [
{
EventId: '1m2n3o4p',
StackName: 'new-service-dev',
LogicalResourceId: 'new-service-dev',
ResourceType: 'AWS::CloudFormation::Stack',
Timestamp: new Date(),
ResourceStatus: 'DELETE_COMPLETE',
},
],
};

describeStackEventsStub.onCall(0).resolves(createStartEvent);
describeStackEventsStub.onCall(1).resolves(createItemFailedEvent);
describeStackEventsStub.onCall(2).resolves(createItemDeleteEvent);
describeStackEventsStub.onCall(3).resolves(createFailedEvent);

return awsPlugin.monitorStack('create', cfDataMock, { frequency: 10 }).catch(e => {
let errorMessage = 'An error occurred: ';
errorMessage += 'myBucket - Invalid Property for X.';
expect(e.name).to.be.equal('ServerlessError');
expect(e.message).to.be.equal(errorMessage);
expect(describeStackEventsStub.callCount).to.be.equal(4);
expect(
describeStackEventsStub.calledWithExactly('CloudFormation', 'describeStackEvents', {
StackName: cfDataMock.StackId,
})
).to.be.equal(true);
awsPlugin.provider.request.restore();
});
}
);

it('should record an error and fail if status is UPDATE_ROLLBACK_IN_PROGRESS', () => {
const describeStackEventsStub = sinon.stub(awsPlugin.provider, 'request');
const cfDataMock = {
Expand Down

0 comments on commit e980625

Please sign in to comment.