test: stub logging in unit tests
This commit is contained in:
parent
522c822304
commit
6fbadb6c42
|
@ -1,9 +1,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var sinon = require('sinon');
|
||||||
var Service = require('../lib/service');
|
var Service = require('../lib/service');
|
||||||
var BitcoreNode = require('../lib/node');
|
var BitcoreNode = require('../lib/node');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var should = require('chai').should();
|
var should = require('chai').should();
|
||||||
|
var index = require('../lib');
|
||||||
|
var log = index.log;
|
||||||
|
|
||||||
var TestService = function(options) {
|
var TestService = function(options) {
|
||||||
this.node = options.node;
|
this.node = options.node;
|
||||||
|
@ -41,6 +44,14 @@ TestService.prototype.unsubscribe = function(name, emitter) {
|
||||||
|
|
||||||
|
|
||||||
describe('Bus Functionality', function() {
|
describe('Bus Functionality', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
it('should subscribe to testEvent', function(done) {
|
it('should subscribe to testEvent', function(done) {
|
||||||
var node = new BitcoreNode({
|
var node = new BitcoreNode({
|
||||||
datadir: './',
|
datadir: './',
|
||||||
|
|
|
@ -7,6 +7,8 @@ var Networks = bitcore.Networks;
|
||||||
var proxyquire = require('proxyquire');
|
var proxyquire = require('proxyquire');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
var BaseService = require('../lib/service');
|
var BaseService = require('../lib/service');
|
||||||
|
var index = require('../lib');
|
||||||
|
var log = index.log;
|
||||||
|
|
||||||
describe('Bitcore Node', function() {
|
describe('Bitcore Node', function() {
|
||||||
|
|
||||||
|
@ -171,6 +173,13 @@ describe('Bitcore Node', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#_startService', function() {
|
describe('#_startService', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will instantiate an instance and load api methods', function() {
|
it('will instantiate an instance and load api methods', function() {
|
||||||
var node = new Node(baseConfig);
|
var node = new Node(baseConfig);
|
||||||
function TestService() {}
|
function TestService() {}
|
||||||
|
@ -213,6 +222,13 @@ describe('Bitcore Node', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#start', function() {
|
describe('#start', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will call start for each service', function(done) {
|
it('will call start for each service', function(done) {
|
||||||
var node = new Node(baseConfig);
|
var node = new Node(baseConfig);
|
||||||
|
|
||||||
|
@ -302,6 +318,13 @@ describe('Bitcore Node', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#stop', function() {
|
describe('#stop', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will call stop for each service', function(done) {
|
it('will call stop for each service', function(done) {
|
||||||
var node = new Node(baseConfig);
|
var node = new Node(baseConfig);
|
||||||
function TestService() {}
|
function TestService() {}
|
||||||
|
|
|
@ -4,9 +4,19 @@ var should = require('chai').should();
|
||||||
var sinon = require('sinon');
|
var sinon = require('sinon');
|
||||||
var proxyquire = require('proxyquire');
|
var proxyquire = require('proxyquire');
|
||||||
var BitcoinService = require('../../lib/services/bitcoind');
|
var BitcoinService = require('../../lib/services/bitcoind');
|
||||||
|
var index = require('../../lib');
|
||||||
|
var log = index.log;
|
||||||
|
|
||||||
describe('#start', function() {
|
describe('#start', function() {
|
||||||
|
|
||||||
|
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() {
|
describe('will dynamically create a node from a configuration', function() {
|
||||||
|
|
||||||
it('require each bitcore-node service with default config', function(done) {
|
it('require each bitcore-node service with default config', function(done) {
|
||||||
|
|
|
@ -140,6 +140,13 @@ describe('Bitcoin Service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#subscribe', function() {
|
describe('#subscribe', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will push to subscriptions', function() {
|
it('will push to subscriptions', function() {
|
||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
var emitter = {};
|
var emitter = {};
|
||||||
|
@ -153,6 +160,13 @@ describe('Bitcoin Service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#unsubscribe', function() {
|
describe('#unsubscribe', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will remove item from subscriptions', function() {
|
it('will remove item from subscriptions', function() {
|
||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
var emitter1 = {};
|
var emitter1 = {};
|
||||||
|
@ -1106,6 +1120,13 @@ describe('Bitcoin Service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#_spawnChildProcess', function() {
|
describe('#_spawnChildProcess', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will give error from spawn config', function(done) {
|
it('will give error from spawn config', function(done) {
|
||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
bitcoind._loadSpawnConfiguration = sinon.stub().throws(new Error('test'));
|
bitcoind._loadSpawnConfiguration = sinon.stub().throws(new Error('test'));
|
||||||
|
@ -1263,6 +1284,13 @@ describe('Bitcoin Service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#start', function() {
|
describe('#start', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
it('will give error if "spawn" and "connect" are both not configured', function(done) {
|
it('will give error if "spawn" and "connect" are both not configured', function(done) {
|
||||||
var bitcoind = new BitcoinService(baseConfig);
|
var bitcoind = new BitcoinService(baseConfig);
|
||||||
bitcoind.options = {};
|
bitcoind.options = {};
|
||||||
|
|
|
@ -5,6 +5,9 @@ var sinon = require('sinon');
|
||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var proxyquire = require('proxyquire');
|
var proxyquire = require('proxyquire');
|
||||||
|
|
||||||
|
var index = require('../../lib');
|
||||||
|
var log = index.log;
|
||||||
|
|
||||||
var httpStub = {
|
var httpStub = {
|
||||||
createServer: sinon.spy()
|
createServer: sinon.spy()
|
||||||
};
|
};
|
||||||
|
@ -237,6 +240,14 @@ describe('WebService', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#socketHandler', function() {
|
describe('#socketHandler', function() {
|
||||||
|
var sandbox = sinon.sandbox.create();
|
||||||
|
beforeEach(function() {
|
||||||
|
sandbox.stub(log, 'info');
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
sandbox.restore();
|
||||||
|
});
|
||||||
|
|
||||||
var bus = new EventEmitter();
|
var bus = new EventEmitter();
|
||||||
bus.remoteAddress = '127.0.0.1';
|
bus.remoteAddress = '127.0.0.1';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue