Merge pull request #441 from braydonf/undef-config

node: handle undefined service config
This commit is contained in:
Chris Kleeschulte 2016-06-10 18:06:37 -04:00 committed by GitHub
commit be8a5c7db1
2 changed files with 37 additions and 5 deletions

View File

@ -179,13 +179,18 @@ Node.prototype.getServiceOrder = function() {
Node.prototype._startService = function(serviceInfo, callback) {
var self = this;
$.checkState(_.isObject(serviceInfo.config));
$.checkState(!serviceInfo.config.node);
$.checkState(!serviceInfo.config.name);
log.info('Starting ' + serviceInfo.name);
var config = serviceInfo.config;
var config;
if (serviceInfo.config) {
$.checkState(_.isObject(serviceInfo.config));
$.checkState(!serviceInfo.config.node);
$.checkState(!serviceInfo.config.name);
config = serviceInfo.config;
} else {
config = {};
}
config.node = this;
config.name = serviceInfo.name;
var service = new serviceInfo.module(config);

View File

@ -233,6 +233,33 @@ describe('Bitcore Node', function() {
getData.callCount.should.equal(1);
});
});
it('will handle config not being set', function() {
var node = new Node(baseConfig);
function TestService() {}
util.inherits(TestService, BaseService);
TestService.prototype.start = sinon.stub().callsArg(0);
var getData = sinon.stub();
TestService.prototype.getData = getData;
TestService.prototype.getAPIMethods = function() {
return [
['getData', this, this.getData, 1]
];
};
var service = {
name: 'testservice',
module: TestService,
};
node._startService(service, function(err) {
if (err) {
throw err;
}
TestService.prototype.start.callCount.should.equal(1);
should.exist(node.services.testservice);
should.exist(node.getData);
node.getData();
getData.callCount.should.equal(1);
});
});
it('will give an error from start', function() {
var node = new Node(baseConfig);
function TestService() {}