node: handle undefined service config
This commit is contained in:
parent
e87f628e7a
commit
3043263e3b
15
lib/node.js
15
lib/node.js
|
@ -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);
|
||||
|
|
|
@ -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() {}
|
||||
|
|
Loading…
Reference in New Issue