From 6fbadb6c42530735134b785196669379a66df359 Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 18 May 2016 00:33:57 -0400 Subject: [PATCH] test: stub logging in unit tests --- test/bus.integration.js | 11 +++++++++++ test/node.unit.js | 23 +++++++++++++++++++++++ test/scaffold/start.integration.js | 10 ++++++++++ test/services/bitcoind.unit.js | 28 ++++++++++++++++++++++++++++ test/services/web.unit.js | 11 +++++++++++ 5 files changed, 83 insertions(+) diff --git a/test/bus.integration.js b/test/bus.integration.js index 0573695d..42a27d84 100644 --- a/test/bus.integration.js +++ b/test/bus.integration.js @@ -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: './', diff --git a/test/node.unit.js b/test/node.unit.js index 1e843fe0..192cb992 100644 --- a/test/node.unit.js +++ b/test/node.unit.js @@ -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() {} diff --git a/test/scaffold/start.integration.js b/test/scaffold/start.integration.js index 5523f29d..887572b6 100644 --- a/test/scaffold/start.integration.js +++ b/test/scaffold/start.integration.js @@ -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) { diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 92353bcf..96ad398f 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -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 = {}; diff --git a/test/services/web.unit.js b/test/services/web.unit.js index 57490932..3d0ff593 100644 --- a/test/services/web.unit.js +++ b/test/services/web.unit.js @@ -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';