fixed action tests

This commit is contained in:
Eslam A. Hefnawy 2016-03-02 02:51:01 +07:00
parent a44fae84c6
commit dd598ca4f1
37 changed files with 321 additions and 336 deletions

View File

@ -128,7 +128,7 @@ class Function extends SerializerFileSystem {
let e = _this.events[i];
if (!added && e.name == event.name) {
let instance = new _this._S.classes.Event(_this._S, _this);
e = instance.fromObject(event);
_this.events[i] = instance.fromObject(event);
added = true;
}
}

View File

@ -188,6 +188,10 @@ class Project extends SerializerFileSystem {
)
}
getResources() {
return this.resources.defaultResources;
}
setResources(resources) {
this.resources[ resources.getName() ] = resources;
}
@ -218,12 +222,6 @@ class Project extends SerializerFileSystem {
let stage = this.stages[ name ];
delete this.stages[ name ];
return BbPromise.try(function(){
if( stage ){
return stage.destroy();
}
});
}
validateStageExists( name ){

View File

@ -143,7 +143,7 @@ module.exports = function(SPlugin, serverlessPath) {
let excludePatterns = this.function.custom.excludePatterns || [];
wrench.copyDirSyncRecursive(
_this.function.getComponent()._config.filePath.split(path.sep).slice(0, -1).join(path.sep),
path.join(_this.project.getRootPath(), _this.function.getComponent().getName()),
_this.pathDist,
{
exclude: function(name, prefix) {

View File

@ -262,7 +262,7 @@ module.exports = function(SPlugin, serverlessPath) {
};
// List all Resources for this REST API
return _this.aws.request('APIGateway', 'getAllResources', params, _this.evt.options.stage, _this.evt.options.region)
return _this.aws.request('APIGateway', 'getResources', params, _this.evt.options.stage, _this.evt.options.region)
.then(function(response) {
_this.apiResources = response.items;

View File

@ -176,7 +176,7 @@ module.exports = function(SPlugin, serverlessPath) {
});
}
// If CLI and no endpoint names targeted, deploy from CWD if Function
// If CLI and no endpoint names targeted, deploy from CWD
if (_this.S.cli &&
!_this.evt.options.names.length &&
!_this.evt.options.all) {

View File

@ -59,8 +59,8 @@ module.exports = function(SPlugin, serverlessPath) {
],
parameters: [
{
parameter: 'paths',
description: 'One or multiple paths to your event',
parameter: 'names',
description: 'One or multiple event names',
position: '0->'
}
]
@ -102,7 +102,7 @@ module.exports = function(SPlugin, serverlessPath) {
let region = _this.deployed[Object.keys(_this.deployed)[i]];
SCli.log(Object.keys(_this.deployed)[i] + ' ------------------------');
for (let j = 0; j < region.length; j++) {
SCli.log(' ' + region[j].eventSPath);
SCli.log(' ' + region[j].name);
}
}
}
@ -114,7 +114,7 @@ module.exports = function(SPlugin, serverlessPath) {
let region = _this.failed[Object.keys(_this.failed)[i]];
SCli.log(Object.keys(_this.failed)[i] + ' ------------------------');
for (let j = 0; j < region.length; j++) {
SCli.log(' ' + region[j].eventSPath + ': ' + region[j].message );
SCli.log(' ' + region[j].name + ': ' + region[j].message );
// Show Error Stacktrace if in debug mode
SUtils.sDebug(region[j].stack);
}
@ -141,43 +141,41 @@ module.exports = function(SPlugin, serverlessPath) {
_validateAndPrepare() {
let _this = this;
let _this = this,
cwdType = SUtils.getCwdType();
// Instantiate Classes
_this.project = _this.S.getProject();
_this.meta = _this.S.state.getMeta();
_this.project = _this.S.getProject();
_this.aws = _this.S.getProvider();
_this.events = [];
// Set defaults
_this.evt.options.paths = _this.evt.options.paths ? _this.evt.options.paths : [];
_this.evt.options.names = _this.evt.options.names ? _this.evt.options.names : [];
_this.regions = _this.evt.options.region ? [_this.evt.options.region] : Object.keys(_this.meta.stages[_this.evt.options.stage].regions);
// If CLI and no paths targeted, deploy from CWD if Function
if (_this.evt.options.names.length) {
_this.evt.options.names.forEach(function(endpointName) {
_this.events.push(_this.project.getEvent(endpointName));
});
}
// If CLI and no endpoint names targeted, deploy from CWD
if (_this.S.cli &&
!_this.evt.options.paths.length &&
!_this.evt.options.names.length &&
!_this.evt.options.all) {
// Get all functions in CWD
let sPath = _this.getSPathFromCwd(_this.S.getProject().getFilePath());
if (!sPath) {
throw new SError(`You must be in a component to deploy events`);
if(cwdType.function) {
_this.endpoints = _this.project.getFunction(cwdType.function).getAllEvents();
} else if (cwdType.component) {
_this.endpoints = _this.project.getComponent(cwdType.component).getAllEvents();
} else {
_this.endpoints = _this.project.getAllEvents();
}
_this.evt.options.paths = _this.S.getProject().getAllEvents({
paths: [sPath],
returnPaths: true
});
if (!_this.evt.options.paths.length) {
throw new SError(`No events found in this location: ` + sPath);
}
SCli.log('Deploying all events in: ' + sPath + '...');
}
// If --all is selected, load all paths
if (_this.evt.options.all) {
_this.evt.options.paths = _this.S.getProject().getAllEvents({ returnPaths: true });
_this.events = _this.project.getAllEvents();
}
// Validate Stage
@ -229,11 +227,7 @@ module.exports = function(SPlugin, serverlessPath) {
return new BbPromise(function(resolve, reject) {
async.eachSeries(_this.evt.options.paths, function(path, eCb) {
let event = _this.S.getProject().getEvent( path );
if(!event) throw new SError(`Event could not be found: ${path}`);
async.eachSeries(_this.events, function(event, eCb) {
let eventType = event.type.toLowerCase(),
subAction,
@ -241,7 +235,7 @@ module.exports = function(SPlugin, serverlessPath) {
options: {
stage: _this.evt.options.stage,
region: region,
path: path
name: event.name
}
};
@ -258,14 +252,12 @@ module.exports = function(SPlugin, serverlessPath) {
return _this.S.actions[subAction](newEvt)
.then(function (result) {
// Stash deployed endpoints
// Stash deployed events
if (!_this.deployed) _this.deployed = {};
if (!_this.deployed[region]) _this.deployed[region] = [];
_this.deployed[region].push({
module: event._config.module,
function: event._config.function,
name: event.name,
eventSPath: path
function: event._function,
name: event.name
});
return eCb();
@ -275,9 +267,7 @@ module.exports = function(SPlugin, serverlessPath) {
if (!_this.failed) _this.failed = {};
if (!_this.failed[region]) _this.failed[region] = [];
_this.failed[region].push({
module: event ? event._config.module : 'unknown',
function: event ? event._config.function : 'unknown',
eventSPath: path,
function: event ? event._function : 'unknown',
name: event.name,
message: e.message,
stack: e.stack

View File

@ -46,14 +46,15 @@ module.exports = function(SPlugin, serverlessPath) {
let _this = this;
_this.evt = evt;
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region or path.`));
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.name) {
return BbPromise.reject(new SError(`Missing stage, region or event name.`));
}
let event = _this.S.getProject().getEvent( _this.evt.options.path ),
let event = _this.S.getProject().getEvent( _this.evt.options.name ),
populatedEvent = event.toObjectPopulated({stage: _this.evt.options.stage, region: _this.evt.options.region}),
functionName = _this.S.getProject().getFunction( _this.evt.options.path.split('#')[0] ).getDeployedName(_this.evt.options),
functionName = event.getFunction().getDeployedName(_this.evt.options),
statementId = 'sEvents-' + functionName + '-' + event.name + '-' + _this.evt.options.stage,
awsAccountId = _this.S.state.meta.get().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables.iamRoleArnLambda.split('::')[1].split(':')[0],
regionVars = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region).getVariables(),
awsAccountId = regionVars.iamRoleArnLambda.split('::')[1].split(':')[0],
lambdaArn = 'arn:aws:lambda:' + _this.evt.options.region + ':' + awsAccountId + ':function:' + functionName + ':' + _this.evt.options.stage;
_this.aws = _this.S.getProvider('aws');
@ -83,7 +84,7 @@ module.exports = function(SPlugin, serverlessPath) {
return _this.aws.request('Lambda', 'addPermission', params, _this.evt.options.stage, _this.evt.options.region)
})
.then(function() {
let s3Region = _this.S.state.getMeta().variables.projectBucket.split('.')[1];
let projectBucketRegion = _this.S.getProject().getVariables().projectBucketRegion;
let params = {
Bucket: populatedEvent.config.bucket,
NotificationConfiguration: {
@ -111,7 +112,7 @@ module.exports = function(SPlugin, serverlessPath) {
};
}
return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, s3Region);
return _this.aws.request('S3', 'putBucketNotificationConfiguration', params, _this.evt.options.stage, projectBucketRegion);
})
.then(function(data) {

View File

@ -43,15 +43,16 @@ module.exports = function(SPlugin, serverlessPath) {
let _this = this;
_this.evt = evt;
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region or path.`));
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.name) {
return BbPromise.reject(new SError(`Missing stage, region or event name.`));
}
let event = _this.S.getProject().getEvent( _this.evt.options.path ),
let event = _this.S.getProject().getEvent( _this.evt.options.name ),
populatedEvent = event.toObjectPopulated({stage: _this.evt.options.stage, region: _this.evt.options.region}),
functionName = _this.S.getProject().getFunction( _this.evt.options.path.split('#')[0] ).getDeployedName(_this.evt.options),
functionName = event.getFunction().getDeployedName(_this.evt.options),
statementId = 'sEvents-' + functionName + '-' + event.name + '-' + _this.evt.options.stage,
awsAccountId = _this.S.state.meta.get().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables.iamRoleArnLambda.split('::')[1].split(':')[0],
regionVars = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region).getVariables(),
awsAccountId = regionVars.iamRoleArnLambda.split('::')[1].split(':')[0],
topicArn = 'arn:aws:sns:' + _this.evt.options.region + ':' + awsAccountId + ':' + populatedEvent.config.topicName,
lambdaArn = 'arn:aws:lambda:' + _this.evt.options.region + ':' + awsAccountId + ':function:' + functionName + ':' + _this.evt.options.stage;

View File

@ -43,14 +43,15 @@ module.exports = function (SPlugin, serverlessPath) {
let _this = this;
_this.evt = evt;
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region or path.`));
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.name) {
return BbPromise.reject(new SError(`Missing stage, region or event name.`));
}
let event = _this.S.getProject().getEvent( _this.evt.options.path ),
let event = _this.S.getProject().getEvent( _this.evt.options.name ),
populatedEvent = event.toObjectPopulated({stage: _this.evt.options.stage, region: _this.evt.options.region}),
functionName = _this.S.getProject().getFunction( _this.evt.options.path.split('#')[0] ).getDeployedName(_this.evt.options),
functionName = event.getFunction().getDeployedName(_this.evt.options),
ruleName = functionName + '-' + event.name,
awsAccountId = _this.S.state.meta.get().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables.iamRoleArnLambda.split('::')[1].split(':')[0],
regionVars = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region).getVariables(),
awsAccountId = regionVars.iamRoleArnLambda.split('::')[1].split(':')[0],
lambdaArn = 'arn:aws:lambda:' + _this.evt.options.region + ':' + awsAccountId + ':function:' + functionName,
stage = _this.evt.options.stage;

View File

@ -47,18 +47,18 @@ module.exports = function(SPlugin, serverlessPath) {
let _this = this;
_this.evt = evt;
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.path) {
return BbPromise.reject(new SError(`Missing stage, region, or event path.`));
if (!_this.evt.options.stage || !_this.evt.options.region || !_this.evt.options.name) {
return BbPromise.reject(new SError(`Missing stage, region, or event name.`));
}
_this.aws = _this.S.getProvider('aws');
let event = _this.S.getProject().getEvent( _this.evt.options.path ),
let event = _this.S.getProject().getEvent( _this.evt.options.name ),
populatedEvent = event.toObjectPopulated({stage: _this.evt.options.stage, region: _this.evt.options.region}),
functionName = _this.S.getProject().getFunction( _this.evt.options.path.split('#')[0] ).getDeployedName(_this.evt.options),
regionVars = _this.S.state.getMeta().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables,
eventVar = 'eventID:' + event._config.sPath,
awsAccountId = _this.S.state.meta.get().stages[_this.evt.options.stage].regions[_this.evt.options.region].variables.iamRoleArnLambda.split('::')[1].split(':')[0],
functionName = event.getFunction().getDeployedName(_this.evt.options),
regionVars = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region).getVariables(),
eventVar = 'eventID:' + event.name,
awsAccountId = regionVars.iamRoleArnLambda.split('::')[1].split(':')[0],
lambdaArn = 'arn:aws:lambda:' + _this.evt.options.region + ':' + awsAccountId + ':function:' + functionName + ':' + _this.evt.options.stage;
populatedEvent.config.startingPosition = populatedEvent.config.startingPosition || 'TRIM_HORIZON';
@ -84,7 +84,6 @@ module.exports = function(SPlugin, serverlessPath) {
});
} else {
params.EventSourceArn = populatedEvent.config.streamArn;
params.StartingPosition = populatedEvent.config.startingPosition;
@ -93,8 +92,11 @@ module.exports = function(SPlugin, serverlessPath) {
SUtils.sDebug(`Created stream event source ${populatedEvent.config.streamArn} for lambda ${lambdaArn}`);
// save UUID
regionVars[eventVar] = data.UUID;
_this.S.state.save();
let newVar = {},
regionInstance = _this.S.getProject().getRegion(_this.evt.options.stage, _this.evt.options.region);
newVar[eventVar] = data.UUID;
regionInstance.addVariables(newVar);
regionInstance.save();
return BbPromise.resolve(data);
});

View File

@ -8,6 +8,7 @@
module.exports = function(SPlugin, serverlessPath) {
const path = require('path'),
SError = require(path.join(serverlessPath, 'Error')),
SUtils = require(path.join(serverlessPath, 'utils/index')),
BbPromise = require('bluebird'),
chalk = require('chalk'),
SCli = require( path.join( serverlessPath, 'utils', 'cli'));
@ -170,7 +171,7 @@ module.exports = function(SPlugin, serverlessPath) {
// ClientContext: new Buffer(JSON.stringify({x: 1, y: [3,4]})).toString('base64'),
InvocationType: _this.evt.options.invocationType,
LogType: _this.evt.options.logType,
Payload: new Buffer(JSON.stringify(require(path.join(_this.function.getRootPath(), 'event')))),
Payload: new Buffer(JSON.stringify(SUtils.readAndParseJsonSync(path.join(_this.function.getRootPath(), 'event.json')))),
Qualifier: _this.evt.options.stage
};

View File

@ -53,7 +53,7 @@ usage: serverless plugin create <plugin>`,
],
parameters: [
{
parameter: 'pluginName',
parameter: 'name',
description: 'The name of your plugin',
position: '0'
}
@ -76,12 +76,12 @@ usage: serverless plugin create <plugin>`,
.then(_this._createPluginSkeleton)
.then(function() {
SCli.log('Successfully created plugin scaffold with the name: "' + _this.evt.options.pluginName + '"');
SCli.log('Successfully created plugin scaffold with the name: "' + _this.evt.options.name + '"');
/**
* Return Event
*/
_this.evt.data.pluginName = _this.evt.options.pluginName;
_this.evt.data.name = _this.evt.options.name;
return _this.evt;
});
@ -97,7 +97,7 @@ usage: serverless plugin create <plugin>`,
overrides = {};
// If non-interactive, skip
if (!_this.S.config.interactive) return BbPromise.resolve();
if (!_this.S.config.interactive || _this.evt.options.name) return BbPromise.resolve();
let prompts = {
properties: {
@ -114,7 +114,7 @@ usage: serverless plugin create <plugin>`,
return _this.cliPromptInput(prompts, overrides)
.then(function(answers) {
_this.evt.options.pluginName = answers.name;
_this.evt.options.name = answers.name;
});
};
@ -123,8 +123,10 @@ usage: serverless plugin create <plugin>`,
*/
_createPluginSkeleton() {
if (!SUtils.isPluginNameValid(this.evt.options.name)) throw new SError(`Invalid Plugin name`);
// Name of the plugin
let pluginName = this.evt.options.pluginName;
let pluginName = this.evt.options.name;
// Paths
let projectPath = this.S.getProject().getFilePath();
let serverlessPath = this.S.getServerlessPath();

View File

@ -90,7 +90,7 @@ usage: serverless project remove`,
return BbPromise.each(stages, (stage) => {
let evt = {
options: {
stage: stage,
stage: stage.name,
noExeCf: !!this.evt.options.noExeCf
}
};

View File

@ -379,5 +379,22 @@ module.exports = {
if (_functions) data.functions = _.mapValues(_functions, (f) => f.toObjectPopulated({stage, region}));
return data;
},
/**
* NPM Install
* - Programatically install NPM dependencies
*
* This function is here only for purpose of running testsuite.
*/
npmInstall: function(dir) {
process.chdir(dir);
if (exec('npm install ', { silent: false }).code !== 0) {
throw new SError(`Error executing NPM install on ${dir}`, SError.errorCodes.UNKNOWN);
}
process.chdir(process.cwd());
}
};

View File

@ -10,30 +10,30 @@ 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/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/ProjectInstall');
//require('./tests/actions/ProjectLifeCycle.js');
//require('./tests/actions/ResourcesDiff');
//require('./tests/actions/PluginCreate');
require('./tests/classes/Project'); // working
require('./tests/classes/Component'); // working
require('./tests/classes/Function'); // working
require('./tests/classes/Endpoint'); // working
require('./tests/classes/Stage'); // working
require('./tests/classes/Region'); // working
require('./tests/actions/TestPluginCustom'); // working
//require('./tests/actions/TestDefaultActionHook'); // BROKEN. Something has to do with getParentTemplate
require('./tests/actions/StageCreate'); // working
require('./tests/actions/RegionCreate'); // working
require('./tests/actions/ComponentCreate'); // working
require('./tests/actions/FunctionCreate'); // working
require('./tests/actions/EnvList'); // working
require('./tests/actions/EnvGet'); // working
require('./tests/actions/EnvSetUnset'); // working
require('./tests/actions/ResourcesDeploy'); // working
require('./tests/actions/FunctionRun'); // working. HOWEVER, test handler.js doesn't use lodash template syntax, which is broken
require('./tests/actions/FunctionLogs'); // working
require('./tests/actions/FunctionDeploy'); // working
require('./tests/actions/EndpointDeploy'); // working
require('./tests/actions/EventDeploy'); // working
require('./tests/actions/ProjectInit'); // working
//require('./tests/actions/ProjectInstall'); // BROKEN. Something has to do with getParentTemplate
require('./tests/actions/ProjectLifeCycle.js'); // test again with CF ON!
require('./tests/actions/ResourcesDiff'); // working
require('./tests/actions/PluginCreate'); // working
});

View File

@ -48,12 +48,6 @@
}
]
}
},
"fakeBucket": {
"Type" : "AWS::S3::Bucket",
"Properties" : {
"BucketName" : "fakeBucket"
}
}
},
"Outputs": {

View File

@ -22,7 +22,7 @@ module.exports.createTestProject = function(config, npmInstallDirs) {
projectStage = config.stage,
projectRegion = config.region,
projectLambdaIAMRole = config.iamRoleArnLambda,
projectDomain = projectName + '.com';
projectBucket = 'serverless.' + projectRegion + '.' + projectName + '.com';
// Create Test Project
let tmpProjectPath = path.join(os.tmpdir(), projectName);
@ -44,8 +44,8 @@ module.exports.createTestProject = function(config, npmInstallDirs) {
let commonVariablesPrivate = {
project: projectName,
projectBucket: SUtils.generateProjectBucketName(projectDomain, projectRegion),
projectBucketRegion: projectDomain,
projectBucket: projectBucket,
projectBucketRegion: projectRegion,
endpointVariable: "none"
};
@ -59,7 +59,7 @@ module.exports.createTestProject = function(config, npmInstallDirs) {
iamRoleArnLambda: projectLambdaIAMRole,
testEventBucket: config.testEventBucket,
streamArn: config.streamArn,
'eventID:nodejscomponent/group1/function1#dynamodb': config.streamUUID,
'eventID:dynamodb': config.streamUUID,
topicArn: config.topicArn
};

View File

@ -22,7 +22,7 @@ let serverless;
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.runtime != 'undefined');
assert.equal(true, typeof evt.data.sPath != 'undefined');
assert.equal(true, typeof evt.data.name != 'undefined');
};
describe('Test action: Component Create', function() {
@ -30,12 +30,15 @@ describe('Test action: Component Create', function() {
before(function(done) {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
interactive: false
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
});
return serverless.init().then(function() {
@ -55,11 +58,13 @@ describe('Test action: Component Create', function() {
this.timeout(0);
serverless.actions.componentCreate({
sPath: 'newcomponent',
name: 'newcomponent',
runtime: 'nodejs'
})
.then(function(evt) {
validateEvent(evt);
let componentJson = utils.readAndParseJsonSync(serverless.getProject().getFilePath( 'newcomponent', 's-component.json'));
assert.equal(componentJson.name, 'newcomponent');
done();
})
.catch(e => {

View File

@ -21,7 +21,7 @@ let serverless;
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.stage != 'undefined');
assert.equal(true, typeof evt.options.region != 'undefined');
assert.equal(true, typeof evt.options.paths != 'undefined');
assert.equal(true, typeof evt.options.names != 'undefined');
assert.equal(true, typeof evt.data.deployed != 'undefined');
if (evt.data.failed) {
@ -44,11 +44,12 @@ describe('Test Action: Endpoint Deploy', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -76,8 +77,8 @@ describe('Test Action: Endpoint Deploy', function() {
let event = {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/function1@group1/function1~GET'
names: [
'group1/function1#GET'
]
};
@ -105,7 +106,7 @@ describe('Test Action: Endpoint Deploy', function() {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/group2/function4@group2/function4~GET'
'group2/function4#GET'
]
};
@ -120,24 +121,4 @@ describe('Test Action: Endpoint Deploy', function() {
});
});
//describe('Endpoint Deploy: Specify All Paths', function() {
// it('should deploy endpoints', function(done) {
// this.timeout(0);
//
// let event = {
// stage: config.stage,
// region: config.region,
// all: true
// };
//
// serverless.actions.endpointDeploy(event)
// .then(function(evt) {
// validateEvent(evt);
// done();
// })
// .catch(e => {
// done(e);
// });
// });
//});
});

View File

@ -31,12 +31,13 @@ describe('Test Action: Env Get', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
this.timeout(0);
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey

View File

@ -33,12 +33,13 @@ describe('Test Action: Env List', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
this.timeout(0);
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -62,7 +63,7 @@ describe('Test Action: Env List', function() {
let evt = {
stage: config.stage,
region: config.region,
region: config.region
};
serverless.actions.envList(evt)

View File

@ -35,12 +35,13 @@ describe('Test Env Set & Env Unset actions', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
this.timeout(0);
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey

View File

@ -21,7 +21,7 @@ let serverless;
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.stage != 'undefined');
assert.equal(true, typeof evt.options.region != 'undefined');
assert.equal(true, typeof evt.options.paths != 'undefined');
assert.equal(true, typeof evt.options.names != 'undefined');
assert.equal(true, typeof evt.data.deployed != 'undefined');
if (evt.data.failed) {
@ -44,11 +44,12 @@ describe('Test Action: Event Deploy', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -75,8 +76,8 @@ describe('Test Action: Event Deploy', function() {
let event = {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/function1#dynamodb'
names: [
'dynamodb'
]
};
@ -99,8 +100,8 @@ describe('Test Action: Event Deploy', function() {
let event = {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/function1#schedule'
names: [
's3'
]
};
@ -123,8 +124,8 @@ describe('Test Action: Event Deploy', function() {
let event = {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/function1#sns'
names: [
'sns'
]
};
@ -147,8 +148,8 @@ describe('Test Action: Event Deploy', function() {
let event = {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/function1#s3'
names: [
'schedule'
]
};

View File

@ -21,9 +21,7 @@ let serverless;
*/
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.sPath != 'undefined');
assert.equal(true, typeof evt.options.name != 'undefined');
assert.equal(true, typeof evt.data.sPath != 'undefined');
assert.equal(true, typeof evt.options.path != 'undefined');
};
describe('Test action: Function Create', function() {
@ -31,12 +29,15 @@ describe('Test action: Function Create', function() {
before(function(done) {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
interactive: false
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
});
return serverless.init().then(function() {
@ -51,21 +52,19 @@ describe('Test action: Function Create', function() {
describe('Function Create positive tests', function() {
it('create a new Function inside the users Module', function(done) {
it('create a new Function inside the users Component', function(done) {
this.timeout(0);
let evt = {
options: {
sPath: 'nodejscomponent/temp',
name: 'new'
path: 'nodejscomponent/temp'
}
};
serverless.actions.functionCreate(evt)
.then(function(evt) {
validateEvent(evt);
let functionJson = utils.readAndParseJsonSync(serverless.getProject().getFilePath( 'nodejscomponent', 'group1', 'function1', 's-function.json'));
assert.equal(true, typeof functionJson.name != 'undefined');
assert.equal(true, functionJson.endpoints.length);
let functionJson = utils.readAndParseJsonSync(serverless.getProject().getFilePath( 'nodejscomponent', 'temp', 's-function.json'));
assert.equal(functionJson.name, 'temp');
done();
})
.catch(e => {

View File

@ -23,7 +23,7 @@ let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.stage != 'undefined');
assert.equal(true, typeof evt.options.region != 'undefined');
assert.equal(true, typeof evt.options.aliasFunction != 'undefined');
assert.equal(true, typeof evt.options.paths != 'undefined');
assert.equal(true, typeof evt.options.names != 'undefined');
if (evt.data.failed) {
for (let i = 0; i < Object.keys(evt.data.failed).length; i++) {
@ -72,12 +72,13 @@ describe('Test Action: Function Deploy', function() {
this.timeout(0);
testUtils.createTestProject(config, ['nodejscomponent'])
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
interactive: false,
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
});
@ -104,8 +105,8 @@ describe('Test Action: Function Deploy', function() {
let options = {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/function1'
names: [
'function1'
]
};
@ -129,7 +130,7 @@ describe('Test Action: Function Deploy', function() {
stage: config.stage,
region: config.region,
paths: [
'nodejscomponent/group1/group2/function4'
'function4'
]
};

View File

@ -29,7 +29,7 @@ const evt = {
stage: config.stage,
region: config.region,
duration: '7days',
path: 'nodejscomponent/group1/function1'
name: 'function1'
}
};
@ -38,14 +38,16 @@ describe('Test action: Function Logs', function() {
before(function() {
return testUtils.createTestProject(config)
.then(projPath => {
process.chdir(projPath);
.then(projectPath => {
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey,
interactive: false
awsAdminSecretKey: config.awsAdminSecretKey
});
return serverless.init();
})
.then(() => {

View File

@ -19,7 +19,7 @@ let serverless;
*/
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.path != 'undefined');
assert.equal(true, typeof evt.options.name != 'undefined');
assert.equal(true, typeof evt.data.result.response != 'undefined');
assert.equal(true, evt.data.result.status === 'success');
};
@ -30,17 +30,19 @@ describe('Test Action: Function Run', function() {
before(function(done) {
this.timeout(0);
testUtils.createTestProject(config, ['nodejscomponent'])
.then(projPath => {
.then(projectPath => {
this.timeout(0);
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
interactive: true,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
});
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
});
return serverless.init()
.then(function() {
@ -59,7 +61,7 @@ describe('Test Action: Function Run', function() {
this.timeout(0);
let options = {
path: 'nodejscomponent/group1/function1'
name: 'function1'
};
serverless.actions.functionRun(options)
@ -78,7 +80,7 @@ describe('Test Action: Function Run', function() {
this.timeout(0);
let options = {
path: 'nodejscomponent/group1/function1',
name: 'function1',
stage: 'development'
};

View File

@ -19,7 +19,7 @@ let serverless;
let validateEvent = function(evt) {
assert.equal(true, typeof evt.data !== 'undefined');
assert.equal(true, typeof evt.data.pluginName !== 'undefined');
assert.equal(true, typeof evt.data.name !== 'undefined');
};
/**
@ -32,8 +32,13 @@ describe('Test Action: Plugin Create', function() {
before(function() {
return testUtils.createTestProject(config)
.then(projPath => {
serverless = new Serverless( projPath, {
.then(projectPath => {
this.timeout(0);
process.chdir(projectPath);
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -49,7 +54,7 @@ describe('Test Action: Plugin Create', function() {
let evt = {
options: {
skipNpm: true,
pluginName: 'test-plugin'
name: 'test-plugin'
}
};

View File

@ -32,7 +32,6 @@ let serverless = new Serverless( undefined, {
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.name !== 'undefined');
assert.equal(true, typeof evt.options.bucket !== 'undefined');
assert.equal(true, typeof evt.options.notificationEmail !== 'undefined');
assert.equal(true, typeof evt.options.region !== 'undefined');
assert.equal(true, typeof evt.options.noExeCf !== 'undefined');
assert.equal(true, typeof evt.options.stage !== 'undefined');
@ -44,13 +43,10 @@ let validateEvent = function(evt) {
* - Remove Stage CloudFormation Stack
*/
let cleanup = function(Meta, cb, evt) {
// Project Create no longer creates a Project Bucket if noExeCf is set
if (evt.options.noExeCf) return cb();
let cleanup = function(project, cb) {
AWS.config.update({
region: config.region,
region: project.getVariables().projectBucketRegion,
accessKeyId: config.awsAdminKeyId,
secretAccessKey: config.awsAdminSecretKey
});
@ -60,12 +56,12 @@ let cleanup = function(Meta, cb, evt) {
// Delete All Objects in Bucket first, this is required
s3.listObjects({
Bucket: Meta.variables.projectBucket
Bucket: project.getVariables().projectBucket
}, function(err, data) {
if (err) return console.log(err);
let params = {
Bucket: Meta.variables.projectBucket
Bucket: project.getVariables().projectBucket
};
params.Delete = {};
params.Delete.Objects = [];
@ -78,17 +74,14 @@ let cleanup = function(Meta, cb, evt) {
// Delete Bucket
s3.deleteBucket({
Bucket: Meta.variables.projectBucket
Bucket: project.getVariables().projectBucket
}, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
// If no stack, skip
if (config.noExecuteCf) return cb();
// Delete CloudFormation Resources Stack
let cloudformation = new AWS.CloudFormation();
cloudformation.deleteStack({
StackName: serverless.getProject().getRegion(config.stage, config.region)._variables.resourcesStackName
StackName: project.getRegion(config.stage, config.region).getVariables().resourcesStackName
}, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
@ -128,7 +121,6 @@ describe('Test action: Project Init', function() {
options: {
name: name,
bucket: bucket,
notificationEmail: config.notifyEmail,
stage: config.stage,
region: config.region,
profile: config.profile,
@ -139,7 +131,6 @@ describe('Test action: Project Init', function() {
serverless.actions.projectInit(evt)
.then(function(evt) {
// Validate Meta
let project = serverless.getProject();
let stage = project.getStage(config.stage);
let region = project.getRegion(config.stage, config.region);
@ -157,10 +148,8 @@ describe('Test action: Project Init', function() {
// Validate Event
validateEvent(evt);
done();
// Cleanup
//cleanup(serverless, done, evt);
evt.options.noExeCf ? done() : cleanup(project, done);
})
.catch(SError, function(e) {

View File

@ -44,13 +44,13 @@ let validateEvent = function(evt) {
* - Remove Stage CloudFormation Stack
*/
let cleanup = function(Meta, cb, evt) {
let cleanup = function(project, cb) {
// Project Create no longer creates a Project Bucket if noExeCf is set
if (evt.options.noExeCf) return cb();
AWS.config.update({
region: config.region,
region: project.getVariables().projectBucketRegion,
accessKeyId: config.awsAdminKeyId,
secretAccessKey: config.awsAdminSecretKey
});
@ -60,12 +60,12 @@ let cleanup = function(Meta, cb, evt) {
// Delete All Objects in Bucket first, this is required
s3.listObjects({
Bucket: Meta.variables.projectBucket
Bucket: project.getVariables().projectBucket
}, function(err, data) {
if (err) return console.log(err);
let params = {
Bucket: Meta.variables.projectBucket
Bucket: project.getVariables().projectBucket
};
params.Delete = {};
params.Delete.Objects = [];
@ -78,17 +78,14 @@ let cleanup = function(Meta, cb, evt) {
// Delete Bucket
s3.deleteBucket({
Bucket: Meta.variables.projectBucket
Bucket: project.getVariables().projectBucket
}, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
// If no stack, skip
if (config.noExecuteCf) return cb();
// Delete CloudFormation Resources Stack
let cloudformation = new AWS.CloudFormation();
cloudformation.deleteStack({
StackName: Meta.stages[config.stage].regions[config.region].variables.resourcesStackName
StackName: project.getRegion(config.stage, config.region).getVariables().resourcesStackName
}, function (err, data) {
if (err) console.log(err, err.stack); // an error occurred
return cb();
@ -127,9 +124,9 @@ describe('Test action: Project Install', function() {
options: {
name: name,
domain: domain,
notificationEmail: config.notifyEmail,
stage: config.stage,
region: config.region,
profile: config.profile,
noExeCf: config.noExecuteCf,
project: 'serverless-starter'
}
@ -138,27 +135,25 @@ describe('Test action: Project Install', function() {
serverless.actions.projectInstall(evt)
.then(function(evt) {
// Validate Meta
let Meta = serverless.state.getMeta();
let stage = serverless.getProject().getStage(config.stage);
let region = serverless.getProject().getRegion(config.stage, config.region);
let project = serverless.getProject();
let stage = project.getStage(config.stage);
let region = project.getRegion(config.stage, config.region);
assert.equal(true, typeof Meta.variables.project != 'undefined');
assert.equal(true, typeof Meta.variables.domain != 'undefined');
assert.equal(true, typeof Meta.variables.projectBucket != 'undefined');
assert.equal(true, typeof stage._variables.stage != 'undefined');
assert.equal(true, typeof region._variables.region != 'undefined');
assert.equal(true, typeof project.getVariables().project != 'undefined');
assert.equal(true, typeof project.getVariables().projectBucket != 'undefined');
assert.equal(true, typeof project.getVariables().projectBucketRegion != 'undefined');
assert.equal(true, typeof stage.getVariables().stage != 'undefined');
assert.equal(true, typeof region.getVariables().region != 'undefined');
if (!config.noExecuteCf) {
assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined');
assert.equal(true, typeof region._variables.resourcesStackName != 'undefined');
assert.equal(true, typeof region.getVariables().iamRoleArnLambda != 'undefined');
assert.equal(true, typeof region.getVariables().resourcesStackName != 'undefined');
}
// Validate Event
validateEvent(evt);
// Cleanup
cleanup(Meta, done, evt);
evt.options.noExeCf ? done() : cleanup(serverless, done);
})
.catch(SError, function(e) {

View File

@ -32,10 +32,10 @@ let validateEvent = function(evt) {
* - Remove Stage CloudFormation Stack
*/
let cleanup = function(Meta, cb) {
let cleanup = function(project, cb) {
AWS.config.update({
region: Meta.variables.projectBucket.split('.')[1],
region: project.getVariables().projectBucketRegion,
accessKeyId: config.awsAdminKeyId,
secretAccessKey: config.awsAdminSecretKey,
});
@ -43,10 +43,10 @@ let cleanup = function(Meta, cb) {
let s3 = new AWS.S3();
let params = {
Bucket: Meta.variables.projectBucket,
Bucket: project.getVariables().projectBucket,
Delete: {
Objects: [{
Key: `${Meta.variables.projectBucket}/serverless/${Meta.variables.project}/${config.stage}/${config.region2}/`
Key: `${project.getVariables().projectBucket}/serverless/${project.getVariables().project}/${config.stage}/${config.region2}/`
}]
}
};
@ -67,11 +67,12 @@ describe('Test Action: Region Create', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
this.timeout(0);
process.chdir(projPath); // Ror some weird reason process.chdir adds /private/ before cwd path
process.chdir(projectPath); // Ror some weird reason process.chdir adds /private/ before cwd path
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -102,17 +103,15 @@ describe('Test Action: Region Create', function() {
serverless.actions.regionCreate(evt)
.then(function(evt) {
let project = serverless.getProject();
assert.equal(project.getRegion(config.stage, config.region2).getVariables().region, config.region2);
let Meta = serverless.state.meta;
//console.log(serverless.state.meta.stages)
assert.equal(true, typeof serverless.getProject().getRegion(config.stage, config.region2)._variables.region != 'undefined');
// Validate Event
validateEvent(evt);
// Cleanup
cleanup(Meta, done);
cleanup(project, done);
})
.catch(e => {
done(e);

View File

@ -35,11 +35,12 @@ describe('Test action: Resources Deploy', function() {
before(function(done) {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -47,16 +48,14 @@ describe('Test action: Resources Deploy', function() {
return serverless.init()
.then(function() {
done();
SUtils.sDebug('Adding test bucket resource');
// Adding new Module resource
serverless.getProject().cloudFormation.Resources['testBucket' + (new Date).getTime().toString()] = { "Type" : "AWS::S3::Bucket" };
let defaultResources = serverless.getProject().getResources().toObject();
defaultResources.Resources['testBucket' + (new Date).getTime().toString()] = { "Type" : "AWS::S3::Bucket" };
serverless.getProject().getResources().fromObject(defaultResources);
return serverless.state.save()
.then(function() {
done();
});
});
});
});

View File

@ -40,11 +40,12 @@ describe('Test action: Resources Diff', function() {
before(function() {
return testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -56,10 +57,11 @@ describe('Test action: Resources Diff', function() {
SUtils.sDebug('Adding test bucket resource');
// Adding new Module resource
serverless.getProject().cloudFormation.Resources[testBucketName] = { "Type" : "AWS::S3::Bucket" };
return serverless.state.save();
let defaultResources = serverless.getProject().getResources().toObject();
defaultResources.Resources[testBucketName] = { "Type" : "AWS::S3::Bucket" };
serverless.getProject().getResources().fromObject(defaultResources);
});
});
@ -70,7 +72,7 @@ describe('Test action: Resources Diff', function() {
const evt = {
stage: config.stage,
region: config.region,
region: config.region
};
return serverless.actions.resourcesDiff(evt).then(validateEvent);

View File

@ -32,10 +32,10 @@ let validateEvent = function(evt) {
* - Remove Stage CloudFormation Stack
*/
let cleanup = function(Meta, cb) {
let cleanup = function(project, cb) {
AWS.config.update({
region: Meta.variables.projectBucket.split('.')[1],
region: project.getVariables().projectBucketRegion,
accessKeyId: config.awsAdminKeyId,
secretAccessKey: config.awsAdminSecretKey
});
@ -43,10 +43,10 @@ let cleanup = function(Meta, cb) {
let s3 = new AWS.S3();
let params = {
Bucket: Meta.variables.projectBucket,
Bucket: project.getVariables().projectBucket,
Delete: {
Objects: [{
Key: `${Meta.variables.projectBucket}/serverless/${Meta.variables.project}/${config.stage2}/`
Key: `${project.getVariables().projectBucket}/serverless/${project.getVariables().project}/${config.stage2}/`
}]
}
};
@ -63,12 +63,13 @@ describe('Test Action: Stage Create', function() {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
this.timeout(0);
process.chdir(projPath);
process.chdir(projectPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false,
awsAdminKeyId: config.awsAdminKeyId,
awsAdminSecretKey: config.awsAdminSecretKey
@ -89,23 +90,23 @@ describe('Test Action: Stage Create', function() {
options: {
stage: config.stage2,
region: config.region,
profile: config.profile,
noExeCf: config.noExecuteCf
}
};
serverless.actions.stageCreate(evt)
.then(function(evt) {
let Meta = serverless.state.meta;
let project = serverless.getProject();
assert.equal(true, typeof project.getStage(config.stage2)._variables.stage != 'undefined');
assert.equal(true, typeof project.getRegion(config.stage2, config.region)._variables.region != 'undefined');
assert.equal(project.getStage(config.stage2).getVariables().stage, config.stage2);
assert.equal(project.getRegion(config.stage2, config.region).getVariables().region, config.region);
// Validate EVT
validateEvent(evt);
// Cleanup
cleanup(Meta, done);
evt.options.noExeCf ? done() : cleanup(project, done);
})
.catch(e => {
done(e);

View File

@ -78,10 +78,10 @@ describe('Test Default Action With Pre Hook', function() {
before(function(done) {
this.timeout(0);
testUtils.createTestProject(config)
.then(projPath => {
.then(projectPath => {
process.chdir(projPath);
serverless = new Serverless( projPath, {
serverless = new Serverless({
projectPath,
interactive: false
});
@ -104,7 +104,7 @@ describe('Test Default Action With Pre Hook', function() {
this.timeout(0);
let evt = {
options: {
sPath: 'testcomponent'
name: 'testcomponent'
}
};

View File

@ -34,23 +34,23 @@ let serverless = new Serverless( undefined, {
// Removes project S3 bucket
let cleanup = function(evt) {
let Meta = serverless.state.getMeta();
let project = serverless.getProject();
// Project Create no longer creates a Project Bucket if noExeCf is set
if (evt.options.noExeCf) return;
let s3 = require('../../../lib/utils/aws/S3')({
region: config.region,
region: project.getVariables().projectBucketRegion,
accessKeyId: config.awsAdminKeyId,
secretAccessKey: config.awsAdminSecretKey
});
// Delete Region Bucket
// Delete All Objects in Bucket first, this is required
s3.listObjectsPromised({Bucket: Meta.variables.projectBucket})
s3.listObjectsPromised({Bucket: project.getVariables().projectBucket})
.then(function(data) {
let params = {
Bucket: Meta.variables.projectBucket,
Bucket: project.getVariables().projectBucket,
Delete: {}
};
@ -58,7 +58,7 @@ let cleanup = function(evt) {
return s3.deleteObjectsPromised(params);
})
.then(() => s3.deleteBucketPromised({Bucket: Meta.variables.projectBucket}))
.then(() => s3.deleteBucketPromised({Bucket: project.getVariables().projectBucket}))
};
/**
@ -79,17 +79,17 @@ describe('Test: Project Live Cycle', function() {
});
describe('Project Init', function() {
it('should create a new private in temp directory', function() {
it('should create a new project in temp directory', function() {
this.timeout(0);
let name = ('testprj-' + uuid.v4()).replace(/-/g, '');
let domain = name + '.com';
let bucket = name + '.com';
let evt = {
options: {
name: name,
domain: domain,
notificationEmail: config.notifyEmail,
bucket: bucket,
profile: config.profile,
stage: config.stage,
region: config.region,
noExeCf: config.noExecuteCf
@ -103,8 +103,7 @@ describe('Test: Project Live Cycle', function() {
let validateEvent = function(evt) {
assert.equal(true, typeof evt.options.name !== 'undefined');
assert.equal(true, typeof evt.options.domain !== 'undefined');
assert.equal(true, typeof evt.options.notificationEmail !== 'undefined');
assert.equal(true, typeof evt.options.bucket !== 'undefined');
assert.equal(true, typeof evt.options.region !== 'undefined');
assert.equal(true, typeof evt.options.noExeCf !== 'undefined');
assert.equal(true, typeof evt.options.stage !== 'undefined');
@ -114,20 +113,19 @@ describe('Test: Project Live Cycle', function() {
return serverless.actions.projectInit(evt)
.then(function(evt) {
// Validate Meta
let Meta = serverless.state.getMeta();
let stage = serverless.getProject().getStage(config.stage);
let region = serverless.getProject().getRegion(config.stage, config.region);
let project = serverless.getProject();
let stage = project.getStage(config.stage);
let region = project.getRegion(config.stage, config.region);
assert.equal(true, typeof Meta.variables.project != 'undefined');
assert.equal(true, typeof Meta.variables.domain != 'undefined');
assert.equal(true, typeof Meta.variables.projectBucket != 'undefined');
assert.equal(true, typeof stage._variables.stage != 'undefined');
assert.equal(true, typeof region._variables.region != 'undefined');
assert.equal(true, typeof project.getVariables().project != 'undefined');
assert.equal(true, typeof project.getVariables().projectBucket != 'undefined');
assert.equal(true, typeof project.getVariables().projectBucketRegion != 'undefined');
assert.equal(true, typeof stage.getVariables().stage != 'undefined');
assert.equal(true, typeof region.getVariables().region != 'undefined');
if (!config.noExecuteCf) {
assert.equal(true, typeof region._variables.iamRoleArnLambda != 'undefined');
assert.equal(true, typeof region._variables.resourcesStackName != 'undefined');
assert.equal(true, typeof region.getVariables().iamRoleArnLambda != 'undefined');
assert.equal(true, typeof region.getVariables().resourcesStackName != 'undefined');
}
// Validate Event
@ -146,6 +144,7 @@ describe('Test: Project Live Cycle', function() {
options: {
stage: config.stage2,
region: config.region,
profile: config.profile,
noExeCf: config.noExecuteCf
}
};
@ -159,12 +158,9 @@ describe('Test: Project Live Cycle', function() {
return serverless.actions.stageCreate(evt)
.then(function(evt) {
let Meta = serverless.state.meta;
let stage = serverless.getProject().getStage(config.stage2);
let region = serverless.getProject().getRegion(config.stage2, config.region);
assert.equal(true, typeof stage._variables.stage != 'undefined');
assert.equal(true, typeof region._variables.region != 'undefined');
let project = serverless.getProject();
assert.equal(project.getStage(config.stage2).getVariables().stage, config.stage2);
assert.equal(project.getRegion(config.stage2, config.region).getVariables().region, config.region);
// Validate EVT
validateEvent(evt);
@ -195,7 +191,7 @@ describe('Test: Project Live Cycle', function() {
return serverless.actions.regionCreate(evt)
.then(function(evt) {
assert.equal(true, typeof serverless.getProject().getRegion(config.stage2, config.region2)._variables.region != 'undefined');
assert.equal(true, typeof serverless.getProject().getRegion(config.stage2, config.region2).getVariables().region != 'undefined');
// Validate Event
validateEvent(evt);

View File

@ -117,14 +117,12 @@ describe('Test Serverless Project Class', function() {
it('Get resources (unpopulated)', function() {
let resources = instance.getAllResources().toObject();
assert.equal(true, JSON.stringify(resources).indexOf('${') !== -1);
assert.equal(true, JSON.stringify(resources).indexOf('fakeBucket') !== -1);
});
it('Get resources (populated)', function() {
let resources = instance.getAllResources().toObjectPopulated({populate: true, stage: config.stage, region: config.region})
assert.equal(true, JSON.stringify(resources).indexOf('$${') == -1);
assert.equal(true, JSON.stringify(resources).indexOf('${') == -1);
assert.equal(true, JSON.stringify(resources).indexOf('fakeBucket') !== -1);
});
it('Validate region exists', function() {