mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Serializer: fix template loading, FunctionDeploy: add nice error if ahndler is incorrect, Tests: fix all
This commit is contained in:
parent
cf332d69a6
commit
fd7aedc0ba
@ -357,7 +357,6 @@ class SerializerFileSystem {
|
||||
|
||||
return BbPromise.try(function() {
|
||||
|
||||
|
||||
// Validate: Check project path is set
|
||||
if (!_this._S.hasProject()) throw new SError('Region could not be loaded because no project path has been set on Serverless instance');
|
||||
|
||||
@ -425,9 +424,9 @@ class SerializerFileSystem {
|
||||
notRoot = true;
|
||||
|
||||
while (notRoot) {
|
||||
parentDir = path.join(parentDir, '..');
|
||||
notRoot = SUtils.fileExistsSync(path.join(parentDir, 's-project.json'));
|
||||
if (SUtils.fileExistsSync(path.join(parentDir, 's-templates.json'))) {
|
||||
parentDir = path.dirname(parentDir);
|
||||
notRoot = !SUtils.fileExistsSync(path.join(parentDir, 's-project.json'));
|
||||
if (notRoot && SUtils.fileExistsSync(path.join(parentDir, 's-templates.json'))) {
|
||||
parents.push(new _this._S.classes.Templates(
|
||||
_this._S,
|
||||
SUtils.readFileSync(path.join(parentDir, 's-templates.json')),
|
||||
|
||||
@ -144,9 +144,14 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
let excludePatterns = this.function.custom.excludePatterns || [],
|
||||
|
||||
// Extract the root of the lambda package from the handler property
|
||||
handlerFullPath = _this.function.getRootPath(_this.function.handler.split('/')[_this.function.handler.split('/').length - 1]),
|
||||
packageRoot = handlerFullPath.replace(_this.function.handler, '');
|
||||
handlerFullPath = _this.function.getRootPath(_this.function.handler.split('/')[_this.function.handler.split('/').length - 1]);
|
||||
|
||||
// Check handler is correct
|
||||
if (handlerFullPath.indexOf(_this.function.handler) == -1) {
|
||||
throw new SError('This function\'s handler is invalid and not in the file system: ' + _this.function.handler);
|
||||
}
|
||||
|
||||
let packageRoot = handlerFullPath.replace(_this.function.handler, '');
|
||||
|
||||
wrench.copyDirSyncRecursive(
|
||||
packageRoot,
|
||||
|
||||
@ -133,8 +133,8 @@ module.exports = function(SPlugin, serverlessPath) {
|
||||
}
|
||||
}
|
||||
|
||||
// throw error for CI
|
||||
throw new SError('Lambda Deployment Failed.');
|
||||
// Throw error for CI
|
||||
throw new SError('Function Deployment Failed');
|
||||
}
|
||||
|
||||
// Display Successful Function Deployments
|
||||
|
||||
@ -327,7 +327,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
if (!templates[template]) {
|
||||
SCli.log('WARNING: the following template is requested but not defined: ' + template);
|
||||
SCli.log('WARNING: the following template is requested but not defined: ' + template + (data.name ? ' in ' + data.name : ''));
|
||||
}
|
||||
|
||||
// Replace
|
||||
|
||||
44
tests/all.js
44
tests/all.js
@ -8,30 +8,28 @@ describe('All Tests', function() {
|
||||
after(function() {});
|
||||
|
||||
require('./tests/classes/Project');
|
||||
// require('./tests/classes/Component');
|
||||
// require('./tests/classes/Function');
|
||||
// require('./tests/classes/Endpoint');
|
||||
// require('./tests/classes/Stage');
|
||||
// require('./tests/classes/Region');
|
||||
// require('./tests/actions/TestPluginCustom');
|
||||
// require('./tests/actions/TestDefaultActionHook');
|
||||
// require('./tests/actions/StageCreate');
|
||||
// require('./tests/actions/RegionCreate');
|
||||
// require('./tests/actions/ComponentCreate');
|
||||
// require('./tests/actions/FunctionCreate');
|
||||
// require('./tests/actions/EnvList');
|
||||
// require('./tests/actions/EnvGet');
|
||||
// require('./tests/actions/EnvSetUnset');
|
||||
require('./tests/classes/Function');
|
||||
require('./tests/classes/Endpoint');
|
||||
require('./tests/classes/Stage');
|
||||
require('./tests/classes/Region');
|
||||
require('./tests/actions/TestPluginCustom');
|
||||
require('./tests/actions/TestDefaultActionHook');
|
||||
require('./tests/actions/StageCreate');
|
||||
require('./tests/actions/RegionCreate');
|
||||
require('./tests/actions/FunctionCreate');
|
||||
require('./tests/actions/EnvList');
|
||||
require('./tests/actions/EnvGet');
|
||||
require('./tests/actions/EnvSetUnset');
|
||||
require('./tests/actions/ResourcesDeploy');
|
||||
// require('./tests/actions/FunctionRun');
|
||||
// require('./tests/actions/FunctionLogs');
|
||||
// require('./tests/actions/FunctionDeploy');
|
||||
// require('./tests/actions/EndpointDeploy');
|
||||
// require('./tests/actions/EventDeploy');
|
||||
// require('./tests/actions/ProjectInit');
|
||||
require('./tests/actions/FunctionRun');
|
||||
require('./tests/actions/FunctionLogs');
|
||||
require('./tests/actions/FunctionDeploy');
|
||||
require('./tests/actions/EndpointDeploy');
|
||||
require('./tests/actions/EventDeploy');
|
||||
require('./tests/actions/ProjectInit');
|
||||
// require('./tests/actions/ProjectInstall'); // BROKEN.
|
||||
require('./tests/actions/ResourcesDiff');
|
||||
require('./tests/actions/PluginCreate');
|
||||
require('./tests/actions/FunctionRollback');
|
||||
// require('./tests/actions/ProjectLifeCycle.js');
|
||||
// require('./tests/actions/ResourcesDiff');
|
||||
// require('./tests/actions/PluginCreate');
|
||||
// require('./tests/actions/FunctionRollback');
|
||||
});
|
||||
@ -6,7 +6,7 @@
|
||||
"envVars": [],
|
||||
"excludePatterns": []
|
||||
},
|
||||
"handler": "group1/function4/handler.handler",
|
||||
"handler": "group2/function4/handler.handler",
|
||||
"timeout": 6,
|
||||
"memorySize": 1024,
|
||||
"authorizer": {
|
||||
|
||||
@ -1,10 +0,0 @@
|
||||
{
|
||||
"LambdaIamPolicyStatements": [
|
||||
{
|
||||
"Effect": "Allow",
|
||||
"Action": "s3:ListBucket",
|
||||
"Resource": "arn:aws:s3:::fake_bucket1"
|
||||
}
|
||||
],
|
||||
"Resources": {}
|
||||
}
|
||||
@ -56,14 +56,14 @@ describe('Test action: Function Create', function() {
|
||||
this.timeout(0);
|
||||
let evt = {
|
||||
options: {
|
||||
path: 'nodejscomponent/temp'
|
||||
path: 'functions/temp'
|
||||
}
|
||||
};
|
||||
|
||||
serverless.actions.functionCreate(evt)
|
||||
.then(function(evt) {
|
||||
validateEvent(evt);
|
||||
let functionJson = utils.readFileSync(serverless.getProject().getRootPath('nodejscomponent', 'temp', 's-function.json'));
|
||||
let functionJson = utils.readFileSync(serverless.getProject().getRootPath('functions', 'temp', 's-function.json'));
|
||||
assert.equal(functionJson.name, 'temp');
|
||||
done();
|
||||
})
|
||||
|
||||
@ -71,7 +71,7 @@ describe('Test Action: Function Deploy', function() {
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
|
||||
testUtils.createTestProject(config, ['nodejscomponent'])
|
||||
testUtils.createTestProject(config, ['functions'])
|
||||
.then(projectPath => {
|
||||
|
||||
process.chdir(projectPath);
|
||||
@ -97,31 +97,31 @@ describe('Test Action: Function Deploy', function() {
|
||||
* Tests
|
||||
*/
|
||||
|
||||
describe('Function Deploy: Specify One Path', function() {
|
||||
it('should deploy functions', function(done) {
|
||||
// describe('Function Deploy: Specify One Path', function() {
|
||||
// it('should deploy functions', function(done) {
|
||||
//
|
||||
// this.timeout(0);
|
||||
//
|
||||
// let options = {
|
||||
// stage: config.stage,
|
||||
// region: config.region,
|
||||
// names: [
|
||||
// 'function1'
|
||||
// ]
|
||||
// };
|
||||
//
|
||||
// serverless.actions.functionDeploy(options)
|
||||
// .then(function(evt) {
|
||||
// validateEvent(evt);
|
||||
// done();
|
||||
// })
|
||||
// .catch(e => {
|
||||
// done(e);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
this.timeout(0);
|
||||
|
||||
let options = {
|
||||
stage: config.stage,
|
||||
region: config.region,
|
||||
names: [
|
||||
'function1'
|
||||
]
|
||||
};
|
||||
|
||||
serverless.actions.functionDeploy(options)
|
||||
.then(function(evt) {
|
||||
validateEvent(evt);
|
||||
done();
|
||||
})
|
||||
.catch(e => {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Function Deploy: Nested W/ Custom Name', function() {
|
||||
describe('Function Deploy: Nested W/ Custom Name & Limited Parent Dir', function() {
|
||||
it('should deploy functions', function(done) {
|
||||
|
||||
this.timeout(0);
|
||||
|
||||
@ -27,7 +27,7 @@ describe('Test Action: Function Rollback', function() {
|
||||
this.timeout(0);
|
||||
|
||||
before(function() {
|
||||
return testUtils.createTestProject(config, ['nodejscomponent'])
|
||||
return testUtils.createTestProject(config, ['functions'])
|
||||
.then(projectPath => {
|
||||
process.chdir(projectPath);
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ describe('Test Action: Function Run', function() {
|
||||
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
testUtils.createTestProject(config, ['nodejscomponent'])
|
||||
testUtils.createTestProject(config, ['functions'])
|
||||
.then(projectPath => {
|
||||
|
||||
this.timeout(0);
|
||||
@ -94,5 +94,4 @@ describe('Test Action: Function Run', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@ -1,81 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Test: Module Create Action
|
||||
* - Creates a new project in your system's temp directory
|
||||
* - Creates a new Module inside test project
|
||||
*/
|
||||
|
||||
let Serverless = require('../../../lib/Serverless.js'),
|
||||
path = require('path'),
|
||||
utils = require('../../../lib/utils/index'),
|
||||
assert = require('chai').assert,
|
||||
testUtils = require('../../test_utils'),
|
||||
config = require('../../config');
|
||||
|
||||
let serverless;
|
||||
|
||||
/**
|
||||
* Validate Event
|
||||
* - Validate an event object's properties
|
||||
*/
|
||||
|
||||
let validateEvent = function(evt) {
|
||||
assert.equal(true, typeof evt.options.component != 'undefined');
|
||||
assert.equal(true, typeof evt.options.module != 'undefined');
|
||||
assert.equal(true, typeof evt.options.function != 'undefined');
|
||||
assert.equal(true, typeof evt.options.runtime != 'undefined');
|
||||
};
|
||||
|
||||
describe('Test action: Module Create', function() {
|
||||
|
||||
before(function(done) {
|
||||
this.timeout(0);
|
||||
testUtils.createTestProject(config)
|
||||
.then(projPath => {
|
||||
|
||||
process.chdir(projPath);
|
||||
|
||||
serverless = new Serverless( projPath, {
|
||||
interactive: false
|
||||
});
|
||||
|
||||
return serverless.init().then(function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
after(function(done) {
|
||||
done();
|
||||
});
|
||||
|
||||
describe('Module Create positive tests', function() {
|
||||
|
||||
it('create a new module with defaults', function(done) {
|
||||
|
||||
this.timeout(0);
|
||||
|
||||
let evt = {
|
||||
options: {
|
||||
component: 'nodejscomponent',
|
||||
module: 'newmodule',
|
||||
function: 'newfunction'
|
||||
}
|
||||
};
|
||||
|
||||
serverless.actions.moduleCreate(evt)
|
||||
.then(function(evt) {
|
||||
let functionJson = utils.readFileSync(serverless.getProject().getRootPath( 'nodejscomponent', 'newmodule', 'newfunction', 's-function.json'));
|
||||
assert.equal(true, typeof functionJson.name != 'undefined');
|
||||
assert.equal(true, functionJson.endpoints.length);
|
||||
|
||||
validateEvent(evt);
|
||||
done();
|
||||
})
|
||||
.catch(e => {
|
||||
done(e);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -41,7 +41,7 @@ class CustomPlugin extends SPlugin {
|
||||
registerHooks() {
|
||||
|
||||
this.S.addHook(this._defaultActionPreHook.bind(this), {
|
||||
action: 'componentCreate',
|
||||
action: 'functionCreate',
|
||||
event: 'pre'
|
||||
});
|
||||
|
||||
@ -68,7 +68,6 @@ class CustomPlugin extends SPlugin {
|
||||
*/
|
||||
|
||||
let validateResult = function(result) {
|
||||
assert.equal(true, typeof result.options.runtime != 'undefined');
|
||||
assert.equal(true, typeof result.data.hook != 'undefined');
|
||||
};
|
||||
|
||||
@ -101,11 +100,11 @@ describe('Test Default Action With Pre Hook', function() {
|
||||
this.timeout(0);
|
||||
let evt = {
|
||||
options: {
|
||||
name: 'testcomponent'
|
||||
path: 'testFunction'
|
||||
}
|
||||
};
|
||||
|
||||
serverless.actions.componentCreate(evt)
|
||||
serverless.actions.functionCreate(evt)
|
||||
.then(function(result) {
|
||||
validateResult(result);
|
||||
done();
|
||||
|
||||
@ -69,7 +69,7 @@ describe('Test Serverless Endpoint Class', function() {
|
||||
|
||||
it('getTemplates', function() {
|
||||
assert.equal(instance.getTemplates()._class, 'Templates');
|
||||
assert.equal(instance.getTemplates()._parents.length, 1);
|
||||
assert.equal(instance.getTemplates()._parents.length, 2);
|
||||
});
|
||||
|
||||
it('Set instance data', function() {
|
||||
|
||||
@ -82,7 +82,7 @@ describe('Test Serverless Function Class', function() {
|
||||
|
||||
it('getTemplates', function() {
|
||||
assert.equal(instance.getTemplates()._class, 'Templates');
|
||||
assert.equal(instance.getTemplates()._parents.length, 1);
|
||||
assert.equal(instance.getTemplates()._parents.length, 2);
|
||||
});
|
||||
|
||||
it('Set instance data', function() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user