mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
* fix #1854 - added latest version of eslint-config-airbnb-base package * fix #1854 - added latest npm shrinkwrap scheme * fix #1854 - added latest npm coveralls package * fix #1854 - added latest npm eslint package * fix #1854 - added latest npm eslint-config-airbnb package * fix #1854 - added latest npm eslint-plugin-import package * fix #1854 - added latest npm eslint-plugin-jsx-a11y package * fix #1854 - added latest npm eslint-plugin-react package * fix #1854 - fixed estlint new-parens errors for integration test * fix #1854 - fixed estlint new-parens errors for yaml parsers tests * fix #1854 - fixed estlint max-len errors for util tests * fix #1854 - disabled no-extraneous-dependencies on eslintrc for NodeJS 4 incapability on this feature * fix #1854 - fixed eslint new-parens errors for Service tests * fix #1854 - fixed eslint new-parens errors for Serverless tests * fix #1854 - fixed eslint new-parens errors for plugin manager tests * fix #1854 - fixed eslint new-parens errors for plugin tracking tests * fix #1854 - fixed eslint new-parens errors for plugin package zipService lib * fix #1854 - fixed eslint new-parens errors for plugin package zipService tests * fix #1854 - fixed eslint trailing spaces errors for plugin package zipService lib * fix #1854 - fixed eslint new-parens errors for plugin package cleanup tests * fix #1854 - fixed eslint new-parens errors for plugin create tests * fix #1854 - fixed eslint dot same line expectation error on plugin aws logs index * fix #1854 - fixed eslint operator assignment error on plugin aws logs index * fix #1854 - fixed eslint dot location error on plugin aws invoke tests * fix #1854 - fixed eslint new-parens error on plugin aws invoke tests * fix #1854 - fixed eslint new-parens error on plugin aws deployFunction tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy uploadDeploymentPackage tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy updateStack tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy createStack tests * fix #1854 - fixed eslint new-parens error on plugin aws deploy apiGateway lib deployment * fix #1854 - fixed eslint unary typeof whitespace req error on Serverless Service class * fix #1854 - fixed eslint unary typeof whitespace req error on Serverless Service class ( second fix ) * fix #1854 - fixed eslint no-lonely-if req error on Serverless Service class * fix #1854 - disabled react/require-extension on eslintrc because it's deprecated * fix #1854 - AwsCompileApigEvents #constructor() should resolve if no functions are given: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - createStack #postCreate() should resolve: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - emptyS3Bucket #deleteObjects() should resolve if objectsInBucket is empty: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - AwsInvoke #extendedValidate() should resolve if path is not given: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - #cleanup() should resolve if the .serverless directory is not present: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 -#validate() should resolve if servicePath is given: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - Service #load() should resolve if no servicePath is found: Error: Resolution method is overspecified. Specify a callback *or* return a Promise; not both. * fix #1854 - added latest mocha package * fix #1854 - added latest sinon npm package * fix #1854 - serverless/lib/plugins/aws/deploy/tests/createStack.js 136:48 error Missing semicolon semi * fix #1854 - serverless/lib/plugins/package/tests/cleanup.js 35:7 error Missing semicolon semi * fix #1854 - serverless/lib/plugins/package/tests/validate.js 22:49 error Missing semicolon semi * fix #1854 - added latest npm shrinkwrap * fix #1854 - fixed no-extra-boolean-cast eslint error on aws deploy apiGateway methods * fix #1854 - fixed new-parens eslint error on serverless tests for Service class
120 lines
4.4 KiB
JavaScript
120 lines
4.4 KiB
JavaScript
'use strict';
|
|
|
|
const expect = require('chai').expect;
|
|
const sinon = require('sinon');
|
|
const AwsRemove = require('../index');
|
|
const Serverless = require('../../../../Serverless');
|
|
const BbPromise = require('bluebird');
|
|
|
|
describe('emptyS3Bucket', () => {
|
|
const serverless = new Serverless();
|
|
|
|
let awsRemove;
|
|
|
|
beforeEach(() => {
|
|
const options = {
|
|
stage: 'dev',
|
|
region: 'us-east-1',
|
|
};
|
|
awsRemove = new AwsRemove(serverless, options);
|
|
awsRemove.serverless.cli = new serverless.classes.CLI();
|
|
});
|
|
|
|
describe('#setServerlessDeploymentBucketName()', () => {
|
|
it('should store the name of the Serverless deployment bucket in the "this" variable', () => {
|
|
const getServerlessDeploymentBucketNameStub = sinon
|
|
.stub(awsRemove.sdk, 'getServerlessDeploymentBucketName')
|
|
.returns(BbPromise.resolve('new-service-dev-us-east-1-12345678'));
|
|
|
|
return awsRemove.setServerlessDeploymentBucketName().then(() => {
|
|
expect(awsRemove.bucketName).to.equal('new-service-dev-us-east-1-12345678');
|
|
expect(getServerlessDeploymentBucketNameStub.calledOnce).to.be.equal(true);
|
|
expect(getServerlessDeploymentBucketNameStub
|
|
.calledWith(awsRemove.options.stage, awsRemove.options.region));
|
|
awsRemove.sdk.getServerlessDeploymentBucketName.restore();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#listObjects()', () => {
|
|
it('should resolve if no objects are present', () => {
|
|
const listObjectsStub = sinon.stub(awsRemove.sdk, 'request')
|
|
.returns(BbPromise.resolve());
|
|
|
|
return awsRemove.listObjects().then(() => {
|
|
expect(listObjectsStub.calledOnce).to.be.equal(true);
|
|
expect(listObjectsStub.args[0][0]).to.equal('S3');
|
|
expect(listObjectsStub.args[0][1]).to.equal('listObjectsV2');
|
|
expect(listObjectsStub.calledWith(awsRemove.options.stage, awsRemove.options.region));
|
|
expect(awsRemove.objectsInBucket.length).to.equal(0);
|
|
awsRemove.sdk.request.restore();
|
|
});
|
|
});
|
|
|
|
it('should push objects to the array if present', () => {
|
|
const listObjectsStub = sinon.stub(awsRemove.sdk, 'request')
|
|
.returns(BbPromise.resolve({
|
|
Contents: [
|
|
{ Key: 'object1' },
|
|
{ Key: 'object2' },
|
|
],
|
|
}));
|
|
|
|
return awsRemove.listObjects().then(() => {
|
|
expect(listObjectsStub.calledOnce).to.be.equal(true);
|
|
expect(listObjectsStub.args[0][0]).to.equal('S3');
|
|
expect(listObjectsStub.args[0][1]).to.equal('listObjectsV2');
|
|
expect(listObjectsStub.calledWith(awsRemove.options.stage, awsRemove.options.region));
|
|
expect(awsRemove.objectsInBucket[0]).to.deep.equal({ Key: 'object1' });
|
|
expect(awsRemove.objectsInBucket[1]).to.deep.equal({ Key: 'object2' });
|
|
awsRemove.sdk.request.restore();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#deleteObjects()', () => {
|
|
it('should delete all objects in the S3 bucket', () => {
|
|
awsRemove.objectsInBucket = [{ Key: 'foo' }];
|
|
|
|
const deleteObjectsStub = sinon.stub(awsRemove.sdk, 'request')
|
|
.returns(BbPromise.resolve());
|
|
|
|
return awsRemove.deleteObjects().then(() => {
|
|
expect(deleteObjectsStub.calledOnce).to.be.equal(true);
|
|
expect(deleteObjectsStub.calledWith(awsRemove.options.stage, awsRemove.options.region));
|
|
awsRemove.sdk.request.restore();
|
|
});
|
|
});
|
|
|
|
it('should resolve if objectsInBucket is empty', (done) => {
|
|
awsRemove.objectsInBucket = [];
|
|
|
|
awsRemove.deleteObjects().then(() => {
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#emptyS3Bucket()', () => {
|
|
it('should run promise chain in order', () => {
|
|
const setServerlessDeploymentBucketNameStub = sinon
|
|
.stub(awsRemove, 'setServerlessDeploymentBucketName').returns(BbPromise.resolve());
|
|
const listObjectsStub = sinon
|
|
.stub(awsRemove, 'listObjects').returns(BbPromise.resolve());
|
|
const deleteObjectsStub = sinon
|
|
.stub(awsRemove, 'deleteObjects').returns(BbPromise.resolve());
|
|
|
|
return awsRemove.emptyS3Bucket().then(() => {
|
|
expect(setServerlessDeploymentBucketNameStub.calledOnce).to.be.equal(true);
|
|
expect(listObjectsStub.calledAfter(setServerlessDeploymentBucketNameStub))
|
|
.to.be.equal(true);
|
|
expect(deleteObjectsStub.calledAfter(listObjectsStub)).to.be.equal(true);
|
|
|
|
awsRemove.setServerlessDeploymentBucketName.restore();
|
|
awsRemove.listObjects.restore();
|
|
awsRemove.deleteObjects.restore();
|
|
});
|
|
});
|
|
});
|
|
});
|