Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Always honor config.debug. Fixes #87 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanmikaelian authored May 5, 2017
1 parent fa8e058 commit 257f61a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
2 changes: 0 additions & 2 deletions lib/librato.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,6 @@ exports.init = function libratoInit(startupTime, config, events, logger) {
logAll = debug = config.debug;
if (typeof logger !== 'undefined') {
util = logger;
// override the default
logAll = true;
}
// Config options are nested under the top-level 'librato' hash
if (config.librato) {
Expand Down
71 changes: 71 additions & 0 deletions test/librato_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const events = require('events');
const serverPort = 36001;
const librato = require('../lib/librato.js');
const nock = require('nock');
const sinon = require('sinon');

const config = {
debug: false,
Expand All @@ -15,6 +16,76 @@ const config = {
},
};

module.exports.debugConfig = {
setUp: function(callback) {
this.emitter = new events.EventEmitter();
global.util = this.util = require('util');
this.apiServer = nock('http://127.0.0.1:36001')
.defaultReplyHeaders({'Content-Type': 'application/json'});


this.logSpy = sinon.spy(global.util, 'log');

callback();
},

tearDown: function(callback) {
config.debug = false;
global.util.log.restore();
callback();
},

testDebugConfigTrue: function(test) {
test.expect(1);

config.debug = true;
let metrics = {gauges: {my_gauge: 1}};

librato.init(null, config, this.emitter, this.util);
this.emitter.emit('flush', 123, metrics);

test.ok(this.logSpy.called);
test.done();
},

testDebugConfigFalse: function(test) {
test.expect(1);

let metrics = {gauges: {my_gauge: 1}};

librato.init(null, config, this.emitter, this.util);
test.ok(!this.logSpy.called);

this.emitter.emit('flush', 123, metrics);
test.done();
},

testNoLogger: function(test) {
test.expect(1);

let metrics = {gauges: {my_gauge: 1}};

librato.init(null, config, this.emitter);
test.ok(!this.logSpy.called);

this.emitter.emit('flush', 123, metrics);
test.done();
},

testLoggerNoDebugConfig: function(test) {
test.expect(1);
let metrics = {gauges: {my_gauge: 1}};
config.debug = null;

librato.init(null, config, this.emitter, this.util);
test.ok(!this.logSpy.called);

this.emitter.emit('flush', 123, metrics);
test.done();
},

};

module.exports.tags = {
setUp: function(callback) {
this.emitter = new events.EventEmitter();
Expand Down

0 comments on commit 257f61a

Please sign in to comment.