mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Fixed S3 Transfer Acceleration bug with custom deployment buckets (#4606)
* fixed s3 transfer acceleration bug with custom deployment buckets * added test (custom deployment bucket case) * unwrapping stubs (node 5.11 fail) * increased coverage * add return to BbPromise
This commit is contained in:
parent
923b2d5a9a
commit
bb2ddc0eec
@ -58,7 +58,12 @@ module.exports = {
|
||||
{ StackName: stackName }
|
||||
)
|
||||
.then((data) => {
|
||||
if (this.provider.isS3TransferAccelerationEnabled()) {
|
||||
const shouldCheckStackOutput =
|
||||
// check stack output only if acceleration is requested
|
||||
this.provider.isS3TransferAccelerationEnabled() &&
|
||||
// custom deployment bucket won't generate any output (no check)
|
||||
!this.serverless.service.provider.deploymentBucket;
|
||||
if (shouldCheckStackOutput) {
|
||||
const isAlreadyAccelerated = !!_.find(data.Stacks[0].Outputs,
|
||||
{ OutputKey: 'ServerlessDeploymentBucketAccelerated' });
|
||||
if (!isAlreadyAccelerated) {
|
||||
@ -66,7 +71,7 @@ module.exports = {
|
||||
this.provider.disableTransferAccelerationForCurrentDeploy();
|
||||
}
|
||||
}
|
||||
BbPromise.resolve('alreadyCreated');
|
||||
return BbPromise.resolve('alreadyCreated');
|
||||
}))
|
||||
.catch((e) => {
|
||||
if (e.message.indexOf('does not exist') > -1) {
|
||||
|
||||
@ -87,6 +87,15 @@ describe('createStack', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw error if invalid stack name', () => {
|
||||
sandbox.stub(awsDeploy, 'create').resolves();
|
||||
sandbox.stub(awsDeploy.provider, 'request').resolves();
|
||||
awsDeploy.serverless.service.service = 'service-name'.repeat(100);
|
||||
|
||||
return expect(awsDeploy.createStack.bind(awsDeploy))
|
||||
.to.throw(awsDeploy.serverless.classes.Error, /not valid/);
|
||||
});
|
||||
|
||||
it('should set the createLater flag and resolve if deployment bucket is provided', () => {
|
||||
awsDeploy.serverless.service.provider.deploymentBucket = 'serverless';
|
||||
sandbox.stub(awsDeploy.provider, 'request')
|
||||
@ -104,7 +113,7 @@ describe('createStack', () => {
|
||||
|
||||
sandbox.stub(awsDeploy.provider, 'request').rejects(errorMock);
|
||||
|
||||
const createStub = sinon
|
||||
const createStub = sandbox
|
||||
.stub(awsDeploy, 'create').resolves();
|
||||
|
||||
return awsDeploy.createStack().catch((e) => {
|
||||
@ -121,7 +130,7 @@ describe('createStack', () => {
|
||||
|
||||
sandbox.stub(awsDeploy.provider, 'request').rejects(errorMock);
|
||||
|
||||
const createStub = sinon
|
||||
const createStub = sandbox
|
||||
.stub(awsDeploy, 'create').resolves();
|
||||
|
||||
return awsDeploy.createStack().then(() => {
|
||||
@ -149,5 +158,27 @@ describe('createStack', () => {
|
||||
expect(disableTransferAccelerationStub.called).to.be.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('should not disable S3 Transfer Acceleration if custom bucket is used', () => {
|
||||
const disableTransferAccelerationStub = sandbox
|
||||
.stub(awsDeploy.provider,
|
||||
'disableTransferAccelerationForCurrentDeploy').resolves();
|
||||
|
||||
const describeStacksOutput = {
|
||||
Stacks: [
|
||||
{
|
||||
Outputs: [],
|
||||
},
|
||||
],
|
||||
};
|
||||
sandbox.stub(awsDeploy.provider, 'request').resolves(describeStacksOutput);
|
||||
|
||||
awsDeploy.provider.options['aws-s3-accelerate'] = true;
|
||||
awsDeploy.serverless.service.provider.deploymentBucket = 'my-custom-bucket';
|
||||
|
||||
return awsDeploy.createStack().then(() => {
|
||||
expect(disableTransferAccelerationStub.called).to.be.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user