Merge pull request #441 from braydonf/undef-config
node: handle undefined service config
This commit is contained in:
commit
be8a5c7db1
11
lib/node.js
11
lib/node.js
|
@ -179,13 +179,18 @@ Node.prototype.getServiceOrder = function() {
|
||||||
Node.prototype._startService = function(serviceInfo, callback) {
|
Node.prototype._startService = function(serviceInfo, callback) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
log.info('Starting ' + serviceInfo.name);
|
||||||
|
|
||||||
|
var config;
|
||||||
|
if (serviceInfo.config) {
|
||||||
$.checkState(_.isObject(serviceInfo.config));
|
$.checkState(_.isObject(serviceInfo.config));
|
||||||
$.checkState(!serviceInfo.config.node);
|
$.checkState(!serviceInfo.config.node);
|
||||||
$.checkState(!serviceInfo.config.name);
|
$.checkState(!serviceInfo.config.name);
|
||||||
|
config = serviceInfo.config;
|
||||||
|
} else {
|
||||||
|
config = {};
|
||||||
|
}
|
||||||
|
|
||||||
log.info('Starting ' + serviceInfo.name);
|
|
||||||
|
|
||||||
var config = serviceInfo.config;
|
|
||||||
config.node = this;
|
config.node = this;
|
||||||
config.name = serviceInfo.name;
|
config.name = serviceInfo.name;
|
||||||
var service = new serviceInfo.module(config);
|
var service = new serviceInfo.module(config);
|
||||||
|
|
|
@ -233,6 +233,33 @@ describe('Bitcore Node', function() {
|
||||||
getData.callCount.should.equal(1);
|
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() {
|
it('will give an error from start', function() {
|
||||||
var node = new Node(baseConfig);
|
var node = new Node(baseConfig);
|
||||||
function TestService() {}
|
function TestService() {}
|
||||||
|
|
Loading…
Reference in New Issue