mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
basic deployment plugin mocked by SinonJs
This commit is contained in:
parent
341844b02d
commit
b00e4f42cb
@ -52,7 +52,7 @@ class PluginManager {
|
||||
}
|
||||
|
||||
addPlugin(Plugin) {
|
||||
this.plugins.push(new Plugin());
|
||||
this.plugins.push(new Plugin(this.serverless));
|
||||
|
||||
this.loadCommands(Plugin);
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"plugins": [
|
||||
"./HelloWorld/HelloWorld.js"
|
||||
"./deploy/deploy.js"
|
||||
]
|
||||
}
|
||||
|
||||
1
lib/plugins/deploy/README.md
Normal file
1
lib/plugins/deploy/README.md
Normal file
@ -0,0 +1 @@
|
||||
# Deploy
|
||||
41
lib/plugins/deploy/deploy.js
Normal file
41
lib/plugins/deploy/deploy.js
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict';
|
||||
|
||||
const AWS = require('aws-sdk');
|
||||
const BbPromise = require('bluebird');
|
||||
const Zip = require('node-zip');
|
||||
|
||||
class Deploy {
|
||||
constructor(S) {
|
||||
this.S = S;
|
||||
this.commands = {
|
||||
deploy: {
|
||||
usage: 'deploy lambda zip.',
|
||||
lifeCycleEvents: [
|
||||
'deploy',
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
this.hooks = {
|
||||
'deploy:deploy': this.deploy,
|
||||
};
|
||||
|
||||
const config = {
|
||||
region: 'us-east-1',
|
||||
};
|
||||
this.Lambda = new AWS.Lambda(config);
|
||||
BbPromise.promisifyAll(this.Lambda, {suffix: 'Promised'});
|
||||
}
|
||||
|
||||
deploy() {
|
||||
return this.S.instances.service.getAllFunctions().forEach((f) => {
|
||||
const params = {
|
||||
FunctionName: `${this.S.instances.service.service}-${f}`,
|
||||
ZipFile: new Zip(),
|
||||
};
|
||||
return this.Lambda.updateFunctionCodePromised(params);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Deploy;
|
||||
13
lib/plugins/deploy/package.json
Normal file
13
lib/plugins/deploy/package.json
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "deploy",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "node_modules/.bin/mocha ./tests/deploy.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "^3.5.0",
|
||||
"mocha": "^2.4.5"
|
||||
}
|
||||
}
|
||||
57
lib/plugins/deploy/tests/deploy.js
Normal file
57
lib/plugins/deploy/tests/deploy.js
Normal file
@ -0,0 +1,57 @@
|
||||
'use strict';
|
||||
|
||||
const expect = require('chai').expect;
|
||||
const sinon = require('sinon');
|
||||
const Deploy = require('../deploy');
|
||||
const BbPromise = require('bluebird');
|
||||
const Serverless = require('../../../Serverless');
|
||||
|
||||
|
||||
|
||||
describe('Deploy', () => {
|
||||
let deploy;
|
||||
let codeStub;
|
||||
|
||||
beforeEach(() => {
|
||||
const S = new Serverless();
|
||||
deploy = new Deploy(S);
|
||||
codeStub = sinon.stub(deploy.Lambda, 'updateFunctionCodePromised')
|
||||
.returns(BbPromise.resolve());
|
||||
S.instances.service.service = 'myService';
|
||||
S.instances.service.functions = {
|
||||
create: {
|
||||
handler: 'users.create',
|
||||
description: 'fake function',
|
||||
memory_size: 512,
|
||||
timeout: 6,
|
||||
},
|
||||
list: {
|
||||
handler: 'users.list',
|
||||
description: 'fake function',
|
||||
memory_size: 1024,
|
||||
timeout: 6,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
deploy.Lambda.updateFunctionCodePromised.restore();
|
||||
});
|
||||
|
||||
describe('#constructor()', () => {
|
||||
it('should have commands', () => expect(deploy.commands).to.be.not.empty);
|
||||
|
||||
it('should have hooks', () => expect(deploy.hooks).to.be.not.empty);
|
||||
});
|
||||
|
||||
describe('#deploy()', () => {
|
||||
it('should deploy lambda', () => {
|
||||
deploy.deploy();
|
||||
expect(codeStub.calledTwice).to.be.equal(true);
|
||||
expect(codeStub.args[0][0].FunctionName).to.be.equal('myService-create');
|
||||
expect(typeof codeStub.args[0][0].ZipFile).to.not.be.equal('undefined');
|
||||
expect(codeStub.args[1][0].FunctionName).to.be.equal('myService-list');
|
||||
expect(typeof codeStub.args[1][0].ZipFile).to.not.be.equal('undefined');
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -74,6 +74,7 @@
|
||||
"replaceall": "^0.1.6",
|
||||
"shelljs": "^0.6.0",
|
||||
"shortid": "^2.2.2",
|
||||
"traverse": "^0.6.6"
|
||||
"traverse": "^0.6.6",
|
||||
"sinon": "^1.17.4"
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user