mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
100 lines
3.9 KiB
JavaScript
100 lines
3.9 KiB
JavaScript
'use strict';
|
|
|
|
const AwsDeploy = require('../index');
|
|
const Serverless = require('../../../../Serverless');
|
|
const expect = require('chai').expect;
|
|
const BbPromise = require('bluebird');
|
|
const sinon = require('sinon');
|
|
|
|
describe('AwsDeploy', () => {
|
|
const serverless = new Serverless();
|
|
const options = {
|
|
stage: 'dev',
|
|
region: 'us-east-1',
|
|
};
|
|
const awsDeploy = new AwsDeploy(serverless, options);
|
|
awsDeploy.serverless.cli = new serverless.classes.CLI();
|
|
|
|
describe('#constructor()', () => {
|
|
it('should have hooks', () => expect(awsDeploy.hooks).to.be.not.empty);
|
|
|
|
it('should set the provider variable to "aws"', () => expect(awsDeploy.provider)
|
|
.to.equal('aws'));
|
|
|
|
it('should run "before:deploy:initialize" hook promise chain in order', () => {
|
|
const validateStub = sinon
|
|
.stub(awsDeploy, 'validate').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.hooks['before:deploy:initialize']().then(() => {
|
|
expect(validateStub.calledOnce).to.be.equal(true);
|
|
awsDeploy.validate.restore();
|
|
});
|
|
});
|
|
|
|
it('should run "deploy:setupProviderConfiguration" hook promise chain in order', () => {
|
|
const createStackStub = sinon
|
|
.stub(awsDeploy, 'createStack').returns(BbPromise.resolve());
|
|
const monitorStackStub = sinon
|
|
.stub(awsDeploy, 'monitorStack').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.hooks['deploy:setupProviderConfiguration']().then(() => {
|
|
expect(createStackStub.calledOnce).to.be.equal(true);
|
|
expect(monitorStackStub.calledOnce).to.be.equal(true);
|
|
awsDeploy.createStack.restore();
|
|
awsDeploy.monitorStack.restore();
|
|
});
|
|
});
|
|
|
|
it('should run "before:deploy:compileFunctions" promise chain in order', () => {
|
|
const generateArtifactDirectoryNameStub = sinon
|
|
.stub(awsDeploy, 'generateArtifactDirectoryName').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.hooks['before:deploy:compileFunctions']().then(() => {
|
|
expect(generateArtifactDirectoryNameStub.calledOnce).to.be.equal(true);
|
|
awsDeploy.generateArtifactDirectoryName.restore();
|
|
});
|
|
});
|
|
|
|
it('should run "before:deploy:deploy" promise chain in order', () => {
|
|
const mergeCustomProviderResourcesStub = sinon
|
|
.stub(awsDeploy, 'mergeCustomProviderResources').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.hooks['before:deploy:deploy']().then(() => {
|
|
expect(mergeCustomProviderResourcesStub.calledOnce).to.be.equal(true);
|
|
awsDeploy.mergeCustomProviderResources.restore();
|
|
});
|
|
});
|
|
|
|
it('should run "deploy:deploy" promise chain in order', () => {
|
|
const setBucketNameStub = sinon
|
|
.stub(awsDeploy, 'setBucketName').returns(BbPromise.resolve());
|
|
const cleanupS3BucketStub = sinon
|
|
.stub(awsDeploy, 'cleanupS3Bucket').returns(BbPromise.resolve());
|
|
const uploadArtifactsStub = sinon
|
|
.stub(awsDeploy, 'uploadArtifacts').returns(BbPromise.resolve());
|
|
const updateStackStub = sinon
|
|
.stub(awsDeploy, 'updateStack').returns(BbPromise.resolve());
|
|
const monitorStackStub = sinon
|
|
.stub(awsDeploy, 'monitorStack').returns(BbPromise.resolve());
|
|
|
|
return awsDeploy.hooks['deploy:deploy']().then(() => {
|
|
expect(setBucketNameStub.calledOnce).to.be.equal(true);
|
|
expect(cleanupS3BucketStub.calledAfter(setBucketNameStub))
|
|
.to.be.equal(true);
|
|
expect(uploadArtifactsStub.calledAfter(cleanupS3BucketStub))
|
|
.to.be.equal(true);
|
|
expect(updateStackStub.calledAfter(uploadArtifactsStub))
|
|
.to.be.equal(true);
|
|
expect(monitorStackStub.calledAfter(updateStackStub))
|
|
.to.be.equal(true);
|
|
|
|
awsDeploy.setBucketName.restore();
|
|
awsDeploy.cleanupS3Bucket.restore();
|
|
awsDeploy.uploadArtifacts.restore();
|
|
awsDeploy.updateStack.restore();
|
|
awsDeploy.monitorStack.restore();
|
|
});
|
|
});
|
|
});
|
|
});
|