test: stub logging in unit tests

This commit is contained in:
Braydon Fuller 2016-05-18 00:33:57 -04:00
parent 522c822304
commit 6fbadb6c42
5 changed files with 83 additions and 0 deletions

View File

@ -1,9 +1,12 @@
'use strict';
var sinon = require('sinon');
var Service = require('../lib/service');
var BitcoreNode = require('../lib/node');
var util = require('util');
var should = require('chai').should();
var index = require('../lib');
var log = index.log;
var TestService = function(options) {
this.node = options.node;
@ -41,6 +44,14 @@ TestService.prototype.unsubscribe = function(name, emitter) {
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) {
var node = new BitcoreNode({
datadir: './',

View File

@ -7,6 +7,8 @@ var Networks = bitcore.Networks;
var proxyquire = require('proxyquire');
var util = require('util');
var BaseService = require('../lib/service');
var index = require('../lib');
var log = index.log;
describe('Bitcore Node', function() {
@ -171,6 +173,13 @@ describe('Bitcore Node', 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() {
var node = new Node(baseConfig);
function TestService() {}
@ -213,6 +222,13 @@ describe('Bitcore Node', 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) {
var node = new Node(baseConfig);
@ -302,6 +318,13 @@ describe('Bitcore Node', 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) {
var node = new Node(baseConfig);
function TestService() {}

View File

@ -4,9 +4,19 @@ var should = require('chai').should();
var sinon = require('sinon');
var proxyquire = require('proxyquire');
var BitcoinService = require('../../lib/services/bitcoind');
var index = require('../../lib');
var log = index.log;
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() {
it('require each bitcore-node service with default config', function(done) {

View File

@ -140,6 +140,13 @@ describe('Bitcoin Service', 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() {
var bitcoind = new BitcoinService(baseConfig);
var emitter = {};
@ -153,6 +160,13 @@ describe('Bitcoin Service', 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() {
var bitcoind = new BitcoinService(baseConfig);
var emitter1 = {};
@ -1106,6 +1120,13 @@ describe('Bitcoin Service', 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) {
var bitcoind = new BitcoinService(baseConfig);
bitcoind._loadSpawnConfiguration = sinon.stub().throws(new Error('test'));
@ -1263,6 +1284,13 @@ describe('Bitcoin Service', 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) {
var bitcoind = new BitcoinService(baseConfig);
bitcoind.options = {};

View File

@ -5,6 +5,9 @@ var sinon = require('sinon');
var EventEmitter = require('events').EventEmitter;
var proxyquire = require('proxyquire');
var index = require('../../lib');
var log = index.log;
var httpStub = {
createServer: sinon.spy()
};
@ -237,6 +240,14 @@ describe('WebService', function() {
});
describe('#socketHandler', function() {
var sandbox = sinon.sandbox.create();
beforeEach(function() {
sandbox.stub(log, 'info');
});
afterEach(function() {
sandbox.restore();
});
var bus = new EventEmitter();
bus.remoteAddress = '127.0.0.1';