bitcore-node-zcash/test/scaffold/start.integration.js

137 lines
3.3 KiB
JavaScript
Raw Permalink Normal View History

'use strict';
var should = require('chai').should();
var sinon = require('sinon');
2015-08-25 10:57:54 -07:00
var proxyquire = require('proxyquire');
var BitcoinService = require('../../lib/services/bitcoind');
2016-05-17 21:33:57 -07:00
var index = require('../../lib');
var log = index.log;
describe('#start', function() {
2016-05-17 21:33:57 -07:00
var sandbox = sinon.sandbox.create();
beforeEach(function() {
sandbox.stub(log, 'error');
});
afterEach(function() {
sandbox.restore();
});
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({
name: 'bitcoind',
module: BitcoinService,
2016-04-20 08:55:45 -07:00
config: {
spawn: {
datadir: './data'
}
}
2015-08-27 13:09:27 -07:00
});
2015-08-25 10:57:54 -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
});
2016-04-19 17:10:32 -07:00
starttest.registerExitHandlers = sinon.stub();
2015-08-25 10:57:54 -07:00
node = starttest({
path: __dirname,
config: {
2015-08-31 06:00:00 -07:00
services: [
'bitcoind'
2015-08-25 10:57:54 -07:00
],
2016-04-20 08:55:45 -07:00
servicesConfig: {
bitcoind: {
spawn: {
datadir: './data'
}
}
}
2015-08-25 10:57:54 -07:00
}
});
node.should.be.instanceof(TestNode);
done();
});
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();
2016-04-19 17:10:32 -07:00
starttest.registerExitHandlers = sinon.stub();
starttest({
path: __dirname,
config: {
services: [],
2016-04-20 08:55:45 -07:00
servicesConfig: {}
}
});
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: 'bitcoind',
module: BitcoinService,
2015-08-31 10:37:11 -07:00
config: {
2016-04-20 08:55:45 -07:00
param: 'test',
spawn: {
datadir: './data'
}
2015-08-31 10:37:11 -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
});
2016-04-19 17:10:32 -07:00
starttest.registerExitHandlers = sinon.stub();
2015-08-31 10:37:11 -07:00
node = starttest({
path: __dirname,
config: {
services: [
'bitcoind'
2015-08-31 10:37:11 -07:00
],
2015-08-31 10:38:21 -07:00
servicesConfig: {
'bitcoind': {
2016-04-20 08:55:45 -07:00
param: 'test',
spawn: {
datadir: './data'
}
2015-08-31 10:38:21 -07:00
}
},
2016-04-20 08:55:45 -07:00
2015-08-31 10:37:11 -07:00
}
});
node.should.be.instanceof(TestNode);
done();
});
});
});