2015-08-19 13:14:44 -07:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var should = require('chai').should();
|
|
|
|
var sinon = require('sinon');
|
2015-08-25 10:57:54 -07:00
|
|
|
var proxyquire = require('proxyquire');
|
2015-08-31 06:00:00 -07:00
|
|
|
var AddressService = require('../../lib/services/address');
|
2015-08-19 13:14:44 -07:00
|
|
|
|
|
|
|
describe('#start', function() {
|
|
|
|
|
|
|
|
describe('will dynamically create a node from a configuration', function() {
|
|
|
|
|
2015-08-31 10:37:11 -07:00
|
|
|
it('require each bitcore-node service with default config', function(done) {
|
2015-08-25 10:57:54 -07:00
|
|
|
var node;
|
|
|
|
var TestNode = function(options) {
|
2015-08-31 06:00:00 -07:00
|
|
|
options.services[0].should.deep.equal({
|
2015-08-27 13:09:27 -07:00
|
|
|
name: 'address',
|
2015-08-31 06:00:00 -07:00
|
|
|
module: AddressService,
|
2015-08-31 10:37:11 -07:00
|
|
|
config: {}
|
2015-08-27 13:09:27 -07:00
|
|
|
});
|
2015-08-25 10:57:54 -07:00
|
|
|
};
|
2015-09-04 12:05:32 -07:00
|
|
|
TestNode.prototype.start = sinon.stub().callsArg(0);
|
2015-08-25 10:57:54 -07:00
|
|
|
TestNode.prototype.on = sinon.stub();
|
|
|
|
TestNode.prototype.chain = {
|
|
|
|
on: sinon.stub()
|
|
|
|
};
|
|
|
|
|
|
|
|
var starttest = proxyquire('../../lib/scaffold/start', {
|
|
|
|
'../node': TestNode
|
|
|
|
});
|
|
|
|
|
|
|
|
node = starttest({
|
|
|
|
path: __dirname,
|
|
|
|
config: {
|
2015-08-31 06:00:00 -07:00
|
|
|
services: [
|
2015-08-25 10:57:54 -07:00
|
|
|
'address'
|
|
|
|
],
|
|
|
|
datadir: './data'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
node.should.be.instanceof(TestNode);
|
|
|
|
done();
|
2015-08-19 13:14:44 -07:00
|
|
|
});
|
2015-09-04 12:05:32 -07:00
|
|
|
it('shutdown with an error from start', function(done) {
|
|
|
|
var TestNode = proxyquire('../../lib/node', {});
|
|
|
|
TestNode.prototype.start = function(callback) {
|
|
|
|
setImmediate(function() {
|
|
|
|
callback(new Error('error'));
|
|
|
|
});
|
|
|
|
};
|
|
|
|
var starttest = proxyquire('../../lib/scaffold/start', {
|
|
|
|
'../node': TestNode
|
|
|
|
});
|
|
|
|
starttest.cleanShutdown = sinon.stub();
|
|
|
|
starttest({
|
|
|
|
path: __dirname,
|
|
|
|
config: {
|
|
|
|
services: [],
|
|
|
|
datadir: './testdir'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
setImmediate(function() {
|
|
|
|
starttest.cleanShutdown.callCount.should.equal(1);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2015-08-31 10:37:11 -07:00
|
|
|
it('require each bitcore-node service with explicit config', function(done) {
|
|
|
|
var node;
|
|
|
|
var TestNode = function(options) {
|
|
|
|
options.services[0].should.deep.equal({
|
|
|
|
name: 'address',
|
|
|
|
module: AddressService,
|
|
|
|
config: {
|
|
|
|
param: 'test'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
2015-09-04 12:05:32 -07:00
|
|
|
TestNode.prototype.start = sinon.stub().callsArg(0);
|
2015-08-31 10:37:11 -07:00
|
|
|
TestNode.prototype.on = sinon.stub();
|
|
|
|
TestNode.prototype.chain = {
|
|
|
|
on: sinon.stub()
|
|
|
|
};
|
|
|
|
|
|
|
|
var starttest = proxyquire('../../lib/scaffold/start', {
|
|
|
|
'../node': TestNode
|
|
|
|
});
|
|
|
|
|
|
|
|
node = starttest({
|
|
|
|
path: __dirname,
|
|
|
|
config: {
|
|
|
|
services: [
|
2015-08-31 10:38:21 -07:00
|
|
|
'address'
|
2015-08-31 10:37:11 -07:00
|
|
|
],
|
2015-08-31 10:38:21 -07:00
|
|
|
servicesConfig: {
|
|
|
|
'address': {
|
|
|
|
param: 'test'
|
|
|
|
}
|
|
|
|
},
|
2015-08-31 10:37:11 -07:00
|
|
|
datadir: './data'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
node.should.be.instanceof(TestNode);
|
|
|
|
done();
|
|
|
|
});
|
2015-08-19 13:14:44 -07:00
|
|
|
});
|
|
|
|
});
|