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

Fix #5664 - Rollback fails due to a timestamp parsing error #5710

Merged
merged 3 commits into from Jan 28, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+53 −7
Diff settings

Always

Just for now

@@ -65,7 +65,13 @@ class AwsRollback {
return BbPromise.reject(`${msg} ${hint}`); return BbPromise.reject(`${msg} ${hint}`);
} }


const date = new Date(this.options.timestamp); let date = new Date(this.options.timestamp);

// The if below is added due issues#5664 - Check it for more details
if (date instanceof Date === false || isNaN(date.valueOf())) {
date = new Date(Number(this.options.timestamp));
}

const dateString = `${date.getTime().toString()}-${date.toISOString()}`; const dateString = `${date.getTime().toString()}-${date.toISOString()}`;
const exists = _.some(deployments, (deployment) => ( const exists = _.some(deployments, (deployment) => (
_.some(deployment, { _.some(deployment, {
@@ -14,21 +14,28 @@ describe('AwsRollback', () => {
let serverless; let serverless;
let provider; let provider;


beforeEach(() => { const createInstance = (options) => {
serverless = new Serverless(); serverless = new Serverless();
const options = {
stage: 'dev',
region: 'us-east-1',
timestamp: 1476779096930,
};
provider = new AwsProvider(serverless, options); provider = new AwsProvider(serverless, options);
serverless.setProvider('aws', provider); serverless.setProvider('aws', provider);
serverless.service.service = 'rollback'; serverless.service.service = 'rollback';

spawnStub = sinon.stub(serverless.pluginManager, 'spawn'); spawnStub = sinon.stub(serverless.pluginManager, 'spawn');

awsRollback = new AwsRollback(serverless, options); awsRollback = new AwsRollback(serverless, options);
awsRollback.serverless.cli = new serverless.classes.CLI(); awsRollback.serverless.cli = new serverless.classes.CLI();
const prefix = provider.getDeploymentPrefix(); const prefix = provider.getDeploymentPrefix();
s3Key = `${prefix}/${serverless.service.service}/${provider.getStage()}`; s3Key = `${prefix}/${serverless.service.service}/${provider.getStage()}`;
};

beforeEach(() => {
createInstance({
stage: 'dev',
region: 'us-east-1',
timestamp: 1476779096930,
});

return Promise.resolve();
}); });


afterEach(() => { afterEach(() => {
@@ -80,6 +87,39 @@ describe('AwsRollback', () => {
}); });


describe('#setStackToUpdate()', () => { describe('#setStackToUpdate()', () => {
it('should resolve when the timestamp argument is passed as a string', () => {
createInstance({
stage: 'dev',
region: 'us-east-1',
timestamp: '1476779096930',
});

const s3Objects = [
{
// eslint-disable-next-line max-len
Key: 'serverless/rollback/dev/1476779096930-2016-10-18T08:24:56.930Z/compiled-cloudformation-template.json',
},
{
Key: 'serverless/rollback/dev/1476779096930-2016-10-18T08:24:56.930Z/test.zip',
},
];
const s3Response = {
Contents: s3Objects,
};

sinon.stub(awsRollback.provider, 'request')
.resolves(s3Response);

return awsRollback.setStackToUpdate()
.then(() => {
expect(awsRollback.serverless.service.package.artifactDirectoryName)
.to.be.equal('serverless/rollback/dev/1476779096930-2016-10-18T08:24:56.930Z');

awsRollback.provider.request.restore();
});
});


it('should reject in case no deployments are available', () => { it('should reject in case no deployments are available', () => {
const s3Response = { const s3Response = {
Contents: [], Contents: [],
ProTip! Use n and p to navigate between commits in a pull request.