mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +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
269 lines
8.7 KiB
JavaScript
269 lines
8.7 KiB
JavaScript
'use strict';
|
|
|
|
const expect = require('chai').expect;
|
|
const sinon = require('sinon');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
const BbPromise = require('bluebird');
|
|
const AwsDeploy = require('../index');
|
|
const Serverless = require('../../../../Serverless');
|
|
|
|
describe('createStack', () => {
|
|
let serverless;
|
|
let awsDeploy;
|
|
|
|
const tmpDirPath = path.join(os.tmpdir(), (new Date()).getTime().toString());
|
|
const serverlessEnvYmlPath = path.join(tmpDirPath, 'serverless.env.yml');
|
|
const serverlessYmlPath = path.join(tmpDirPath, 'serverless.yml');
|
|
const serverlessYml = {
|
|
service: 'first-service',
|
|
provider: 'aws',
|
|
functions: {
|
|
first: {
|
|
handler: 'sample.handler',
|
|
},
|
|
},
|
|
};
|
|
const serverlessEnvYml = {
|
|
vars: {},
|
|
stages: {
|
|
dev: {
|
|
vars: {},
|
|
regions: {
|
|
'us-east-1': {
|
|
vars: {},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
|
|
beforeEach(() => {
|
|
serverless = new Serverless();
|
|
serverless.utils.writeFileSync(serverlessYmlPath, serverlessYml);
|
|
serverless.utils.writeFileSync(serverlessEnvYmlPath, serverlessEnvYml);
|
|
serverless.config.servicePath = tmpDirPath;
|
|
const options = {
|
|
stage: 'dev',
|
|
region: 'us-east-1',
|
|
};
|
|
awsDeploy = new AwsDeploy(serverless, options);
|
|
awsDeploy.serverless.service.service = `service-${(new Date()).getTime().toString()}`;
|
|
awsDeploy.serverless.cli = new serverless.classes.CLI();
|
|
});
|
|
|
|
describe('#create()', () => {
|
|
it('should create a stack with the core CloudFormation template', () => {
|
|
const coreCloudFormationTemplate = awsDeploy.serverless.utils.readFileSync(
|
|
path.join(__dirname,
|
|
'..',
|
|
'lib',
|
|
'core-cloudformation-template.json')
|
|
);
|
|
|
|
const createStackStub = sinon
|
|
.stub(awsDeploy.sdk, 'request').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.create().then(() => {
|
|
expect(createStackStub.args[0][1]).to.equal('createStack');
|
|
expect(JSON.parse(createStackStub.args[0][2].TemplateBody))
|
|
.to.deep.equal(coreCloudFormationTemplate);
|
|
expect(createStackStub.calledOnce).to.be.equal(true);
|
|
expect(createStackStub.calledWith(awsDeploy.options.stage, awsDeploy.options.region));
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#monitorCreate()', () => {
|
|
it('should keep monitoring until CREATE_COMPLETE stack status', () => {
|
|
const describeStacksStub = sinon.stub(awsDeploy.sdk, 'request');
|
|
const cfDataMock = {
|
|
StackId: 'new-service-dev',
|
|
};
|
|
const DescribeReturn = {
|
|
Stacks: [
|
|
{
|
|
StackStatus: 'CREATE_IN_PROGRESS',
|
|
},
|
|
],
|
|
};
|
|
const FinalDescribeReturn = {
|
|
Stacks: [
|
|
{
|
|
StackStatus: 'CREATE_COMPLETE',
|
|
},
|
|
],
|
|
};
|
|
|
|
describeStacksStub.onCall(0).returns(BbPromise.resolve(DescribeReturn));
|
|
describeStacksStub.onCall(1).returns(BbPromise.resolve(DescribeReturn));
|
|
describeStacksStub.onCall(2).returns(BbPromise.resolve(FinalDescribeReturn));
|
|
|
|
return awsDeploy.monitorCreate(cfDataMock, 10).then((stack) => {
|
|
expect(describeStacksStub.callCount).to.be.equal(3);
|
|
expect(stack.StackStatus).to.be.equal('CREATE_COMPLETE');
|
|
expect(describeStacksStub.calledWith(awsDeploy.options.stage, awsDeploy.options.region));
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
|
|
it('should throw an error if CloudFormation returned unusual stack status', () => {
|
|
const describeStacksStub = sinon.stub(awsDeploy.sdk, 'request');
|
|
const cfDataMock = {
|
|
StackId: 'new-service-dev',
|
|
};
|
|
const DescribeReturn = {
|
|
Stacks: [
|
|
{
|
|
StackStatus: 'CREATE_IN_PROGRESS',
|
|
},
|
|
],
|
|
};
|
|
const FinalDescribeReturn = {
|
|
Stacks: [
|
|
{
|
|
StackStatus: 'UNUSUAL_STATUS',
|
|
},
|
|
],
|
|
};
|
|
|
|
describeStacksStub.onCall(0).returns(BbPromise.resolve(DescribeReturn));
|
|
describeStacksStub.onCall(1).returns(BbPromise.resolve(DescribeReturn));
|
|
describeStacksStub.onCall(2).returns(BbPromise.resolve(FinalDescribeReturn));
|
|
|
|
return awsDeploy.monitorCreate(cfDataMock, 10).catch((e) => {
|
|
expect(e.name).to.be.equal('ServerlessError');
|
|
expect(describeStacksStub.callCount).to.be.equal(3);
|
|
expect(describeStacksStub.calledWith(awsDeploy.options.stage, awsDeploy.options.region));
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#postCreate()', () => {
|
|
it('should resolve', (done) => {
|
|
awsDeploy.postCreate().then(() => done());
|
|
});
|
|
});
|
|
|
|
describe('#createStack()', () => {
|
|
beforeEach(() => {
|
|
awsDeploy.serverless.service.environment.stages = {
|
|
dev: {
|
|
regions: {
|
|
'us-east-1': {
|
|
vars: {},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
});
|
|
|
|
it('should store the core CloudFormation template in the provider object', () => {
|
|
sinon.stub(awsDeploy.sdk, 'request').returns(BbPromise.resolve());
|
|
|
|
const coreCloudFormationTemplate = awsDeploy.loadCoreCloudFormationTemplate();
|
|
|
|
return awsDeploy.createStack().then(() => {
|
|
expect(awsDeploy.serverless.service.provider.compiledCloudFormationTemplate)
|
|
.to.deep.equal(coreCloudFormationTemplate);
|
|
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
|
|
it('should resolve if stack already created', () => {
|
|
const createStub = sinon
|
|
.stub(awsDeploy, 'create').returns(BbPromise.resolve());
|
|
|
|
sinon.stub(awsDeploy.sdk, 'request').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.createStack().then(() => {
|
|
expect(createStub.called).to.be.equal(false);
|
|
awsDeploy.create.restore();
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
|
|
it('should resolve if no deploy', () => {
|
|
awsDeploy.options.noDeploy = true;
|
|
|
|
const errorMock = {
|
|
message: 'does not exist',
|
|
};
|
|
|
|
sinon.stub(awsDeploy.sdk, 'request').returns(BbPromise.reject(errorMock));
|
|
|
|
const writeCreateTemplateToDiskStub = sinon
|
|
.stub(awsDeploy, 'writeCreateTemplateToDisk').returns(BbPromise.resolve());
|
|
const createStub = sinon
|
|
.stub(awsDeploy, 'create').returns(BbPromise.resolve());
|
|
const monitorStub = sinon
|
|
.stub(awsDeploy, 'monitorCreate').returns(BbPromise.resolve());
|
|
const postCreateStub = sinon
|
|
.stub(awsDeploy, 'postCreate').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.createStack().then(() => {
|
|
expect(writeCreateTemplateToDiskStub.calledOnce).to.be.equal(true);
|
|
expect(createStub.called).to.be.equal(false);
|
|
expect(monitorStub.called).to.be.equal(false);
|
|
expect(postCreateStub.called).to.be.equal(false);
|
|
|
|
awsDeploy.create.restore();
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
|
|
it('should run promise chain in order', () => {
|
|
const errorMock = {
|
|
message: 'does not exist',
|
|
};
|
|
|
|
sinon.stub(awsDeploy.sdk, 'request').returns(BbPromise.reject(errorMock));
|
|
|
|
const createStub = sinon
|
|
.stub(awsDeploy, 'create').returns(BbPromise.resolve());
|
|
const monitorStub = sinon
|
|
.stub(awsDeploy, 'monitorCreate').returns(BbPromise.resolve());
|
|
const postCreateStub = sinon
|
|
.stub(awsDeploy, 'postCreate').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.createStack().then(() => {
|
|
expect(createStub.calledOnce).to.be.equal(true);
|
|
expect(monitorStub.calledAfter(createStub)).to.be.equal(true);
|
|
expect(postCreateStub.calledAfter(monitorStub)).to.be.equal(true);
|
|
|
|
awsDeploy.create.restore();
|
|
awsDeploy.monitorCreate.restore();
|
|
awsDeploy.postCreate.restore();
|
|
awsDeploy.sdk.request.restore();
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('#loadCoreCloudFormationTemplate', () => {
|
|
it('should load the core CloudFormation template', () => {
|
|
const template = awsDeploy.loadCoreCloudFormationTemplate();
|
|
|
|
expect(template.Resources.ServerlessDeploymentBucket.Type)
|
|
.to.equal('AWS::S3::Bucket');
|
|
});
|
|
});
|
|
|
|
describe('#writeCreateTemplateToDisk', () => {
|
|
it('should write the compiled CloudFormation template into the .serverless directory', () => {
|
|
awsDeploy.serverless.service.provider.compiledCloudFormationTemplate = { key: 'value' };
|
|
|
|
const templatePath = path.join(tmpDirPath,
|
|
'.serverless',
|
|
'cloudformation-template-create-stack.json');
|
|
|
|
return awsDeploy.writeCreateTemplateToDisk().then(() => {
|
|
expect(serverless.utils.fileExistsSync(templatePath)).to.equal(true);
|
|
expect(serverless.utils.readFileSync(templatePath)).to.deep.equal({ key: 'value' });
|
|
});
|
|
});
|
|
});
|
|
});
|