Add resolving for bucket name retrieval when noDeploy option is set

This commit is contained in:
Philipp Muens 2016-08-22 15:07:49 +02:00
parent bcc74df4dd
commit ede355cc5d
2 changed files with 20 additions and 4 deletions

View File

@ -1,7 +1,13 @@
'use strict';
const BbPromise = require('bluebird');
module.exports = {
setBucketName() {
if (this.options.noDeploy) {
return BbPromise.resolve();
}
return this.sdk.getServerlessDeploymentBucketName(this.options.stage, this.options.region)
.then((bucketName) => {
this.bucketName = bucketName;

View File

@ -9,6 +9,7 @@ const BbPromise = require('bluebird');
describe('#setBucketName()', () => {
let serverless;
let awsDeploy;
let getServerlessDeploymentBucketNameStub;
beforeEach(() => {
serverless = new Serverless();
@ -17,19 +18,28 @@ describe('#setBucketName()', () => {
region: 'us-east-1',
};
awsDeploy = new AwsDeploy(serverless, options);
});
it('should store the name of the Serverless deployment bucket in the "this" variable', () => {
const getServerlessDeploymentBucketNameStub = sinon
getServerlessDeploymentBucketNameStub = sinon
.stub(awsDeploy.sdk, 'getServerlessDeploymentBucketName')
.returns(BbPromise.resolve('bucket-name'));
});
return awsDeploy.setBucketName().then(() => {
it('should store the name of the Serverless deployment bucket', () => awsDeploy
.setBucketName().then(() => {
expect(awsDeploy.bucketName).to.equal('bucket-name');
expect(getServerlessDeploymentBucketNameStub.calledOnce).to.be.equal(true);
expect(getServerlessDeploymentBucketNameStub
.calledWith(awsDeploy.options.stage, awsDeploy.options.region));
awsDeploy.sdk.getServerlessDeploymentBucketName.restore();
})
);
it('should resolve if no deploy', () => {
awsDeploy.options.noDeploy = true;
return awsDeploy.setBucketName().then(() => {
expect(getServerlessDeploymentBucketNameStub.calledOnce).to.be.equal(false);
awsDeploy.sdk.getServerlessDeploymentBucketName.restore();
});
});
});