Merge pull request #1266 from serverless/rename-invoke-plugin

Rename invokeAws to awsInvoke
This commit is contained in:
Philipp Muens 2016-06-06 08:28:13 +02:00
commit aca94fd89a
4 changed files with 49 additions and 49 deletions

View File

@ -6,7 +6,7 @@
"./remove/remove.js",
"./awsRemoveResources/awsRemoveResources.js",
"./invoke/invoke.js",
"./invokeAws/invokeAws.js",
"./awsInvoke/awsInvoke.js",
"./helloWorld/helloWorld.js"
]
}

View File

@ -6,7 +6,7 @@ const path = require('path');
const AWS = require('aws-sdk');
const moment = require('moment');
class InvokeAws {
class AwsInvoke {
constructor(serverless) {
this.serverless = serverless;
this.options = {};
@ -126,4 +126,4 @@ class InvokeAws {
}
}
module.exports = InvokeAws;
module.exports = AwsInvoke;

View File

@ -4,34 +4,34 @@ const expect = require('chai').expect;
const sinon = require('sinon');
const path = require('path');
const os = require('os');
const InvokeAws = require('../invokeAws');
const AwsInvoke = require('../awsInvoke');
const Serverless = require('../../../Serverless');
const BbPromise = require('bluebird');
const AWS = require('aws-sdk');
const serverless = new Serverless();
const invokeAws = new InvokeAws(serverless);
const awsInvoke = new AwsInvoke(serverless);
describe('InvokeAws', () => {
describe('awsInvoke', () => {
describe('#constructor()', () => {
it('should have hooks', () => expect(invokeAws.hooks).to.be.not.empty);
it('should have hooks', () => expect(awsInvoke.hooks).to.be.not.empty);
it('should run promise chain in order', () => {
const validateStub = sinon
.stub(invokeAws, 'validate').returns(BbPromise.resolve());
.stub(awsInvoke, 'validate').returns(BbPromise.resolve());
const invokeStub = sinon
.stub(invokeAws, 'invoke').returns(BbPromise.resolve());
.stub(awsInvoke, 'invoke').returns(BbPromise.resolve());
const logStub = sinon
.stub(invokeAws, 'log').returns(BbPromise.resolve());
.stub(awsInvoke, 'log').returns(BbPromise.resolve());
return invokeAws.hooks['invoke:invoke']().then(() => {
return awsInvoke.hooks['invoke:invoke']().then(() => {
expect(validateStub.calledOnce).to.be.equal(true);
expect(invokeStub.calledAfter(validateStub)).to.be.equal(true);
expect(logStub.calledAfter(invokeStub)).to.be.equal(true);
invokeAws.validate.restore();
invokeAws.invoke.restore();
invokeAws.log.restore();
awsInvoke.validate.restore();
awsInvoke.invoke.restore();
awsInvoke.log.restore();
});
});
});
@ -57,15 +57,15 @@ describe('InvokeAws', () => {
handler: true,
},
};
invokeAws.options = {
awsInvoke.options = {
stage: 'dev',
region: 'us-east-1',
function: 'hello',
};
});
it('it should resolve if all config is valid', () => invokeAws.validate()
.then(() => expect(typeof invokeAws.Lambda).to.not.be.equal('undefined'))
it('it should resolve if all config is valid', () => awsInvoke.validate()
.then(() => expect(typeof awsInvoke.Lambda).to.not.be.equal('undefined'))
);
it('it should parse file if file path is provided', () => {
@ -75,43 +75,43 @@ describe('InvokeAws', () => {
};
serverless.utils.writeFileSync(path
.join(serverless.config.servicePath, 'data.json'), JSON.stringify(data));
invokeAws.options.path = 'data.json';
return invokeAws.validate().then(() => {
expect(invokeAws.options.data).to.deep.equal(data);
invokeAws.options.path = false;
awsInvoke.options.path = 'data.json';
return awsInvoke.validate().then(() => {
expect(awsInvoke.options.data).to.deep.equal(data);
awsInvoke.options.path = false;
serverless.config.servicePath = true;
});
});
it('it should throw error if function is missing', () => {
invokeAws.options.function = false;
expect(() => invokeAws.validate()).to.throw(Error);
invokeAws.options.function = 'hello';
awsInvoke.options.function = false;
expect(() => awsInvoke.validate()).to.throw(Error);
awsInvoke.options.function = 'hello';
});
it('it should throw error if stage is missing', () => {
invokeAws.options.stage = null;
expect(() => invokeAws.validate()).to.throw(Error);
invokeAws.options.stage = 'dev';
awsInvoke.options.stage = null;
expect(() => awsInvoke.validate()).to.throw(Error);
awsInvoke.options.stage = 'dev';
});
it('it should throw error if region is missing', () => {
invokeAws.options.region = null;
expect(() => invokeAws.validate()).to.throw(Error);
invokeAws.options.region = 'us-east-1';
awsInvoke.options.region = null;
expect(() => awsInvoke.validate()).to.throw(Error);
awsInvoke.options.region = 'us-east-1';
});
it('it should throw error if service path is not set', () => {
serverless.config.servicePath = false;
expect(() => invokeAws.validate()).to.throw(Error);
expect(() => awsInvoke.validate()).to.throw(Error);
serverless.config.servicePath = true;
});
it('it should throw error if file path does not exist', () => {
serverless.config.servicePath = path.join(os.tmpdir(), (new Date).getTime().toString());
invokeAws.options.path = 'some/path';
expect(() => invokeAws.validate()).to.throw(Error);
invokeAws.options.path = false;
awsInvoke.options.path = 'some/path';
expect(() => awsInvoke.validate()).to.throw(Error);
awsInvoke.options.path = false;
serverless.config.servicePath = true;
});
});
@ -119,48 +119,48 @@ describe('InvokeAws', () => {
describe('#invoke()', () => {
let invokeStub;
beforeEach(() => {
invokeAws.Lambda = new AWS.Lambda({ region: 'us-east-1' });
BbPromise.promisifyAll(invokeAws.Lambda, { suffix: 'Promised' });
invokeAws.serverless.service.service = 'new-service';
invokeAws.options = {
awsInvoke.Lambda = new AWS.Lambda({ region: 'us-east-1' });
BbPromise.promisifyAll(awsInvoke.Lambda, { suffix: 'Promised' });
awsInvoke.serverless.service.service = 'new-service';
awsInvoke.options = {
function: 'hello',
};
invokeStub = sinon.stub(invokeAws.Lambda, 'invokePromised').returns(BbPromise.resolve());
invokeStub = sinon.stub(awsInvoke.Lambda, 'invokePromised').returns(BbPromise.resolve());
});
it('should invoke with correct params', () => invokeAws.invoke()
it('should invoke with correct params', () => awsInvoke.invoke()
.then(() => {
expect(invokeStub.calledOnce).to.be.equal(true);
expect(invokeStub.args[0][0].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][0].InvocationType).to.be.equal('RequestResponse');
expect(invokeStub.args[0][0].LogType).to.be.equal('None');
expect(typeof invokeStub.args[0][0].Payload).to.not.be.equal('undefined');
invokeAws.Lambda.invokePromised.restore();
awsInvoke.Lambda.invokePromised.restore();
})
);
it('should invoke and log', () => {
invokeAws.options.log = true;
return invokeAws.invoke().then(() => {
awsInvoke.options.log = true;
return awsInvoke.invoke().then(() => {
expect(invokeStub.calledOnce).to.be.equal(true);
expect(invokeStub.args[0][0].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][0].InvocationType).to.be.equal('RequestResponse');
expect(invokeStub.args[0][0].LogType).to.be.equal('Tail');
expect(typeof invokeStub.args[0][0].Payload).to.not.be.equal('undefined');
invokeAws.Lambda.invokePromised.restore();
awsInvoke.Lambda.invokePromised.restore();
});
});
it('should invoke with other invocation type', () => {
invokeAws.options.type = 'OtherType';
return invokeAws.invoke().then(() => {
awsInvoke.options.type = 'OtherType';
return awsInvoke.invoke().then(() => {
expect(invokeStub.calledOnce).to.be.equal(true);
expect(invokeStub.args[0][0].FunctionName).to.be.equal('new-service-hello');
expect(invokeStub.args[0][0].InvocationType).to.be.equal('OtherType');
expect(invokeStub.args[0][0].LogType).to.be.equal('None');
expect(typeof invokeStub.args[0][0].Payload).to.not.be.equal('undefined');
invokeAws.Lambda.invokePromised.restore();
awsInvoke.Lambda.invokePromised.restore();
});
});
});
@ -176,7 +176,7 @@ describe('InvokeAws', () => {
LogResult: 'test',
};
return invokeAws.log(invocationReplyMock);
return awsInvoke.log(invocationReplyMock);
});
});
});

View File

@ -22,4 +22,4 @@ require('../lib/plugins/remove/tests/remove');
require('../lib/plugins/awsDeploy/tests/all');
require('../lib/plugins/awsRemoveResources/tests/all');
require('../lib/plugins/invoke/tests/invoke');
require('../lib/plugins/invokeAws/tests/invokeAws');
require('../lib/plugins/awsInvoke/tests/awsInvoke');