fixed merging conflicts

This commit is contained in:
Eslam A. Hefnawy 2016-05-20 13:41:06 +02:00
commit e5104fc0ea
6 changed files with 105 additions and 14 deletions

View File

@ -41,8 +41,7 @@ class Service {
that.custom = serverlessYaml.custom;
that.plugins = serverlessYaml.plugins;
that.resources = serverlessYaml.resources;
// TODO load functions
that.functions = serverlessYaml.functions;
})
.then(() => {
that.S.instances.yamlParser.parse(path.join(servicePath, 'serverless.env.yaml'));
@ -128,19 +127,25 @@ class Service {
}
getAllFunctions() {
return Object.keys(this.functions);
}
getFunction(functionName) {
if (functionName in this.functions) {
return this.functions[functionName];
}
throw new SError(`function ${functionName} doesn't exist in this Service`);
}
getEventInFunction(eventName) {
getEventInFunction(eventName, functionName) {
if (eventName in this.getFunction(functionName).events) {
return this.getFunction(functionName).events[eventName];
}
throw new SError(`event ${eventName} doesn't exist in function ${functionName}`);
}
getAllEventsInFunction() {
getAllEventsInFunction(functionName) {
return Object.keys(this.getFunction(functionName).events);
}
getStage(stageName) {
@ -165,7 +170,6 @@ class Service {
return Object.keys(this.getStage(stageName).regions);
}
// return object
getVariables(stageName, regionName) {
if (stageName && regionName) {
return this.getRegionInStage(stageName, regionName).vars;

View File

@ -82,8 +82,8 @@ class Utils {
});
}
generateShortId(maxLen) {
return (Math.round((Math.random() * Math.pow(36, maxLen)))).toString(36);
generateShortId(length) {
return Math.random().toString(36).substr(2, length);
}
}

View File

@ -9,3 +9,4 @@ require('./tests/classes/Utils');
require('./tests/classes/Config');
require('./tests/classes/Service');
require('./tests/classes/YamlParser');

View File

@ -7,7 +7,7 @@ describe('Serverless', () => {
describe('#getVersion()', () => {
it('should get the correct serverless version', () => {
const serverless = new Serverless();
expect(serverless.getVersion()).to.be.equal('0.5.5');
expect(serverless.getVersion()).to.match(/^(\d+\.)?(\d+\.)?(\*|\d+)$/);
});
});
});

View File

@ -213,6 +213,91 @@ describe('Service', () => {
});
});
describe('#getFunction()', () => {
let serviceInstance;
before(() => {
const S = new Serverless();
serviceInstance = new Service(S);
serviceInstance.functions = {
create: {
handler: 'users.create'
}
};
});
it('should return function object', () => {
expect(serviceInstance.getFunction('create')).to.deep.equal({ handler: 'users.create' });
});
it('should throw error if function does not exist', () => {
expect(()=> { serviceInstance.getFunction('random') }).to.throw(Error);
});
});
describe('#getAllFunctions()', () => {
it('should return an array of function names in Service', () => {
const S = new Serverless();
const serviceInstance = new Service(S);
serviceInstance.functions = {
create: {
handler: 'users.create'
},
list: {
handler: 'users.list'
}
};
expect(serviceInstance.getAllFunctions()).to.deep.equal(['create', 'list']);
});
});
describe('#getEventInFunction()', () => {
let serviceInstance;
before(() => {
const S = new Serverless();
serviceInstance = new Service(S);
serviceInstance.functions = {
create: {
events: {
schedule: 'rate(5 minutes)'
}
}
};
});
it('should return an event object based on provided function', () => {
expect(serviceInstance.getEventInFunction('schedule', 'create')).to.be.equal('rate(5 minutes)');
});
it('should throw error if function does not exist in service', () => {
expect(() => {serviceInstance.getEventInFunction(null, 'list')}).to.throw(Error);
});
it('should throw error if event doesnt exist in function', () => {
expect(() => {serviceInstance.getEventInFunction('randomEvent', 'create')}).to.throw(Error);
});
});
describe('#getAllEventsInFunction()', () => {
it('should return an array of events in a specified function', () => {
const S = new Serverless();
const serviceInstance = new Service(S);
serviceInstance.functions = {
create: {
events: {
schedule: 'rate(5 minutes)',
bucket: 'my_bucket'
}
}
};
expect(serviceInstance.getAllEventsInFunction('create')).to.deep.equal(['schedule', 'bucket']);
});
});
describe('#getStage()', () => {
let serviceInstance;
before(() => {
@ -272,6 +357,7 @@ describe('Service', () => {
});
});
describe('#getRegionInStage()', () => {
let serviceInstance;
before(() => {

View File

@ -14,13 +14,13 @@ const yamlParser = new YamlParser(S);
describe('Utils', () => {
describe('#generateShortId()', () => {
it('should generate a shortId', () => {
const id = SUtils.generateShortId(6);
const id = SUtils.generateShortId();
expect(id).to.be.a('string');
});
it('should generate a shortId for the given length', () => {
const id = SUtils.generateShortId(6);
expect(id.length).to.equal(6);
expect(id.length).to.be.equal(6);
});
});