more tests, simplified the standard tests for the loggers

This commit is contained in:
Spencer Alger
2013-12-04 12:49:39 -07:00
parent 4e5f08a29c
commit c070c9e741
30 changed files with 535 additions and 505 deletions

View File

@ -0,0 +1,23 @@
var sinon = require('sinon');
exports.make = function () {
var log = [];
afterEach(function () {
var stub;
while (stub = log.pop()) {
stub.restore();
}
});
var stubber = function () {
log.push(sinon.stub.apply(sinon, arguments));
};
stubber.autoRelease = function (item) {
if (item.restore && !~log.indexOf(item)) {
log.push(item);
}
};
return stubber;
};

View File

@ -1,79 +1,65 @@
describe('Logger Abstract', function () {
var Log = require('../../src/lib/log');
var LoggerAbstract = require('../../src/lib/logger');
var now = new Date('2013-03-01T00:00:00Z');
var sinon = require('sinon');
var sinon = require('sinon');
var now = new Date('2013-03-01T00:00:00Z');
var Log = require('../../src/lib/log');
var LoggerAbstract = require('../../src/lib/logger');
var parentLog;
var stubs = [];
function stub() {
stubs.push(sinon.stub.apply(sinon, arguments));
}
function makeLogger(levels) {
return new LoggerAbstract(parentLog, {
levels: levels || []
});
}
beforeEach(function () {
parentLog = new Log();
});
module.exports = function (makeLogger) {
var stub = require('./auto_release_stub').make();
var parent = new Log();
afterEach(function () {
var stub;
while (stub = stubs.pop()) {
stub.restore();
}
parentLog.close();
parent.close();
});
describe('Constuctor', function () {
it('calls setupListeners', function () {
stub(LoggerAbstract.prototype, 'setupListeners');
var logger = makeLogger();
it('calls setupListeners, passes its new levels', function () {
var logger = makeLogger(parent);
stub(logger.constructor.prototype, 'setupListeners');
parent.close();
logger = makeLogger(parent);
logger.setupListeners.callCount.should.eql(1);
});
it('listens for the loggers\' "closing" event', function () {
var logger = makeLogger();
parentLog.listenerCount('closing').should.eql(1);
var logger = makeLogger(parent);
parent.listenerCount('closing').should.eql(1);
});
});
describe('#setupListeners', function () {
it('calls cleanUpListeners', function () {
describe('listening levels', function () {
it('calls cleanUpListeners when the listeners are being setup', function () {
var logger = makeLogger();
stub(logger, 'cleanUpListeners');
logger.setupListeners([]);
logger.cleanUpListeners.callCount.should.eql(1);
});
it('explicitly listens for the events specified', function () {
var logger = makeLogger();
logger.setupListeners(['error']);
parentLog.listenerCount('error').should.eql(1);
parentLog.listenerCount('warning').should.eql(0);
parentLog.listenerCount('info').should.eql(0);
parentLog.listenerCount('debug').should.eql(0);
parentLog.listenerCount('trace').should.eql(0);
it('listens to just error when log is explicitly error', function () {
var logger = makeLogger(parent, 'error');
parent.listenerCount('error').should.eql(1);
parent.listenerCount('warning').should.eql(0);
parent.listenerCount('info').should.eql(0);
parent.listenerCount('debug').should.eql(0);
parent.listenerCount('trace').should.eql(0);
});
logger.setupListeners(['warning', 'trace']);
parentLog.listenerCount('error').should.eql(0);
parentLog.listenerCount('warning').should.eql(1);
parentLog.listenerCount('info').should.eql(0);
parentLog.listenerCount('debug').should.eql(0);
parentLog.listenerCount('trace').should.eql(1);
it('listens for all the events when level is "trace"', function () {
var logger = makeLogger(parent, 'trace');
parent.listenerCount('error').should.eql(1);
parent.listenerCount('warning').should.eql(1);
parent.listenerCount('info').should.eql(1);
parent.listenerCount('debug').should.eql(1);
parent.listenerCount('trace').should.eql(1);
});
logger.setupListeners(['debug', 'debug']);
parentLog.listenerCount('error').should.eql(0);
parentLog.listenerCount('warning').should.eql(0);
parentLog.listenerCount('info').should.eql(0);
parentLog.listenerCount('debug').should.eql(2);
parentLog.listenerCount('trace').should.eql(0);
it('listens for specific events when level is an array', function () {
var logger = makeLogger(parent, ['error', 'trace']);
parent.listenerCount('error').should.eql(1);
parent.listenerCount('warning').should.eql(0);
parent.listenerCount('info').should.eql(0);
parent.listenerCount('debug').should.eql(0);
parent.listenerCount('trace').should.eql(1);
});
it('sets the logLevel property to the new levels', function () {
@ -86,7 +72,6 @@ describe('Logger Abstract', function () {
logger.setupListeners(levels);
logger.listeningLevels.should.eql(levels).and.not.be.exactly(levels);
levels = ['debug', 'debug'];
logger.setupListeners(levels);
logger.listeningLevels.should.eql(levels).and.not.be.exactly(levels);
@ -98,19 +83,39 @@ describe('Logger Abstract', function () {
logger.setupListeners(['scream']);
}).should.throw(/unable to listen/i);
});
it('emits events because something is listening', function () {
var logger = makeLogger(parent, 'trace');
stub(parent, 'emit');
parent.error(new Error('error message'));
parent.emit.lastCall.args[0].should.eql('error');
parent.warning('warning');
parent.emit.lastCall.args[0].should.eql('warning');
parent.info('info');
parent.emit.lastCall.args[0].should.eql('info');
parent.debug('debug');
parent.emit.lastCall.args[0].should.eql('debug');
parent.trace('GET', {}, '', '', 200);
parent.emit.lastCall.args[0].should.eql('trace');
});
});
describe('#timestamp', function () {
it('returns in the right format', function () {
stubs.push(sinon.useFakeTimers(now.getTime()));
stub.autoRelease(sinon.useFakeTimers(now.getTime()));
var logger = makeLogger();
logger.timestamp().should.eql('2013-03-01T00:00:00Z');
});
});
describe('#formate', function () {
describe('#format', function () {
it('returns a single string with the message indented', function () {
stubs.push(sinon.useFakeTimers(now.getTime()));
stub.autoRelease(sinon.useFakeTimers(now.getTime()));
var logger = makeLogger();
logger.format('LABEL', 'MSG').should.eql(
'LABEL: 2013-03-01T00:00:00Z\n' +
@ -120,7 +125,7 @@ describe('Logger Abstract', function () {
});
it('properly indents multi-line messages', function () {
stubs.push(sinon.useFakeTimers(now.getTime()));
stub.autoRelease(sinon.useFakeTimers(now.getTime()));
var logger = makeLogger();
logger.format('LABEL', 'MSG\nwith\nseveral lines').should.eql(
'LABEL: 2013-03-01T00:00:00Z\n' +
@ -132,15 +137,6 @@ describe('Logger Abstract', function () {
});
});
describe('#write', function () {
it('requires that it is overwritten', function () {
(function () {
var logger = makeLogger();
logger.write();
}).should.throw(/overwritten/);
});
});
describe('#onError', function () {
it('uses the Error name when it is not just "Error"', function () {
var logger = makeLogger();
@ -246,5 +242,4 @@ describe('Logger Abstract', function () {
logger.write.callCount.should.eql(1);
});
});
});
};

View File

@ -0,0 +1,35 @@
describe('Logger Abstract', function () {
var sinon = require('sinon');
var Log = require('../../src/lib/log');
var LoggerAbstract = require('../../src/lib/logger');
var parentLog;
var stub = require('./auto_release_stub').make();
function makeLogger(parent, levels) {
return new LoggerAbstract(parent || parentLog, {
levels: Log.parseLevels(levels || [])
});
}
beforeEach(function () {
parentLog = new Log();
});
afterEach(function () {
parentLog.close();
});
describe('#write', function () {
it('requires that it is overwritten', function () {
(function () {
var logger = makeLogger();
logger.write();
}).should.throw(/overwritten/);
});
});
require('./generic_logger_tests')(makeLogger);
});

View File

@ -515,7 +515,7 @@ describe('Client Action runner', function () {
params.query.two.should.equal('-69');
params.query.three.should.equal('15');
params.query.four.should.equal('' + now.getTime());
params.query.five.should.equal('-11162941200000');
params.query.five.should.equal('-11162948400000');
done();
});
});

View File

@ -3,13 +3,7 @@ var Host = require('../../src/lib/host');
var sinon = require('sinon');
var _ = require('lodash');
var stubs = [];
afterEach(function () {
var stub;
while (stub = stubs.pop()) {
stub.restore();
}
});
var stub = require('./auto_release_stub').make();
describe('Connection Abstract', function () {
var host = new Host('localhost:9200');
@ -83,7 +77,7 @@ describe('Connection Abstract', function () {
it('sets a timeout when set to dead, and removed when alive', function () {
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stubs.push(clock);
stub.autoRelease(clock);
var conn = new ConnectionAbstract(host);
var start = _.size(clock.timeouts);
@ -112,7 +106,7 @@ describe('Connection Abstract', function () {
it('should ping the connection after the deadTimeout, and set the status to "alive" on pong', function (done) {
var conn = new ConnectionAbstract(host);
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stubs.push(clock);
stub.autoRelease(clock);
// schedules the resuscitate
conn.setStatus('dead');
@ -138,7 +132,7 @@ describe('Connection Abstract', function () {
it('should ping the connection after the deadTimeout, and set the status to "dead" on error', function (done) {
var conn = new ConnectionAbstract(host);
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stubs.push(clock);
stub.autoRelease(clock);
// schedules the resuscitate
conn.setStatus('dead');

View File

@ -0,0 +1,28 @@
var Log = require('../../src/lib/log');
var StdioLogger = require('../../src/lib/loggers/console');
var sinon = require('sinon');
var parentLog;
beforeEach(function () {
parentLog = new Log();
});
afterEach(function () {
parentLog.close();
});
function makeLogger(parent, levels) {
parent = parent || parentLog;
var config = {
levels: Log.parseLevels(levels || 'trace')
};
return new StdioLogger(parent, config);
}
var stub = require('./auto_release_stub').make();
describe('Console Logger', function () {
require('./generic_logger_tests')(makeLogger);
});

View File

@ -0,0 +1,29 @@
var Log = require('../../src/lib/log');
var FileLogger = require('../../src/lib/loggers/file');
var sinon = require('sinon');
var parentLog;
beforeEach(function () {
parentLog = new Log();
});
afterEach(function () {
parentLog.close();
});
function makeLogger(parent, levels, path) {
parent = parent || parentLog;
var config = {
levels: Log.parseLevels(levels || 'trace'),
path: path === void 0 ? 'elasticsearch.log' : path
};
return new FileLogger(parent, config);
}
var stub = require('./auto_release_stub').make();
describe('File Logger', function () {
require('./generic_logger_tests')(makeLogger);
});

View File

@ -154,7 +154,14 @@ describe('Host class', function () {
});
describe('#toString', function () {
// just calls makeUrl without any params
it('produces the same output as makeUrl when it is called without params', function () {
var host = new Host({
path: '/pasta',
host: 'google.com'
});
host.toString().should.eql(host.makeUrl());
});
});
});

View File

@ -17,14 +17,7 @@ describe('Http Connector', function () {
nock.disableNetConnect();
afterEach(function () {
if (http.request.restore) {
http.request.restore();
}
if (https.request.restore) {
https.request.restore();
}
});
var stub = require('./auto_release_stub').make();
function makeStubReqMethod(prep) {
return function (params, cb) {
@ -195,8 +188,8 @@ describe('Http Connector', function () {
describe('#request', function () {
beforeEach(function () {
sinon.stub(http, 'request', makeStubReqMethod(whereReqDies()));
sinon.stub(https, 'request', makeStubReqMethod(whereReqDies()));
stub(http, 'request', makeStubReqMethod(whereReqDies()));
stub(https, 'request', makeStubReqMethod(whereReqDies()));
});
it('calls http based on the host', function (done) {
@ -220,10 +213,14 @@ describe('Http Connector', function () {
it('logs error events, and sets the connection to dead when an error occurs', function (done) {
var con = new HttpConnection(new Host('http://google.com'));
sinon.stub(con.log);
stub(con.log, 'error');
stub(con.log, 'trace');
stub(con.log, 'info');
stub(con.log, 'warning');
stub(con.log, 'debug');
http.request.restore();
sinon.stub(http, 'request', makeStubReqMethod(whereReqDies(new Error('actual error'))));
stub(http, 'request', makeStubReqMethod(whereReqDies(new Error('actual error'))));
con.request({}, function (err) {
// error should have been sent to the
@ -246,10 +243,9 @@ describe('Http Connector', function () {
it('logs error events, and sets the connection to dead', function (done) {
var con = new HttpConnection(new Host('http://google.com'));
sinon.stub(con.log);
stub(con.log, 'error');
http.request.restore();
sinon.stub(http, 'request', makeStubReqMethod(whereReqDies(new Error('actual error'))));
http.request.func = makeStubReqMethod(whereReqDies(new Error('actual error')));
con.request({}, function (err) {
// error should have been sent to the
@ -274,8 +270,8 @@ describe('Http Connector', function () {
it('logs error event', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
sinon.stub(con.log, 'error');
sinon.stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
stub(con.log, 'error');
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
con.request({}, function (err, resp, status) {
con.log.error.callCount.should.eql(1);
@ -285,7 +281,7 @@ describe('Http Connector', function () {
it('and sets the connection to dead', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
sinon.stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
con.request({}, function (err, resp, status) {
con.status.should.eql('dead');
@ -295,7 +291,7 @@ describe('Http Connector', function () {
it('passes the original error on', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
sinon.stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody(new Error('no more message :(')));
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody(new Error('no more message :(')));
con.request({}, function (err, resp, status) {
should.exist(err);
@ -306,7 +302,7 @@ describe('Http Connector', function () {
it('does not pass the partial body along', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
sinon.stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
con.request({}, function (err, resp, status) {
should.not.exist(resp);
@ -316,7 +312,7 @@ describe('Http Connector', function () {
it('does not pass the status code along', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
sinon.stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
stub(https, 'request', makeStubReqWithMsgWhichErrorsMidBody());
con.request({}, function (err, resp, status) {
should.not.exist(status);

View File

@ -0,0 +1,99 @@
var JsonSerializer = require('../../src/lib/serializers/json');
var should = require('should');
describe('JSON serializer', function () {
var stub = require('./auto_release_stub').make();
function makeSerializer() {
return new JsonSerializer();
}
describe('#serialize', function () {
it('defers to JSON.stringify', function () {
stub(JSON, 'stringify');
var ser = makeSerializer();
ser.serialize({ some: 'object' });
JSON.stringify.callCount.should.eql(1);
});
it('does not modify strings', function () {
var ser = makeSerializer();
var thing = 'pretend that I am serialized';
ser.serialize(thing).should.be.exactly(thing);
});
it('returns nothing for invalid values', function () {
var ser = makeSerializer();
should.not.exist(ser.serialize(null));
should.not.exist(ser.serialize(false));
});
it('throws serialization errors', function () {
var ser = makeSerializer();
var thing = { name: 'thing' };
thing.self = thing;
(function () {
ser.serialize(thing);
}).should.throw();
});
});
describe('#deserialize', function () {
it('defers to JSON.parse', function () {
stub(JSON, 'parse');
var ser = makeSerializer();
ser.deserialize('{ "some": "JSON" }');
JSON.parse.callCount.should.eql(1);
});
it('ignores non string values', function () {
var ser = makeSerializer();
var thing = ['pretend that I am not here'];
should.not.exist(ser.deserialize(thing));
should.not.exist(ser.deserialize(null));
should.not.exist(ser.deserialize(false));
});
it('catches serialization errors, returns nothing', function () {
var ser = makeSerializer();
var thing = '{ name: \'thing\' }';
should.not.exist(ser.deserialize(thing));
});
});
describe('#bulkBody', function () {
var body = [
{ index: 'thing' },
{ document: 'hi' }
];
var bulk = '{"index":"thing"}\n{"document":"hi"}\n';
it('creates a string out of an array of obejcts', function () {
var ser = makeSerializer();
ser.bulkBody(body).should.eql(bulk);
});
it('adds a newline to the end of strings', function () {
var ser = makeSerializer();
ser.bulkBody(bulk.substr(0, bulk.length - 1)).should.eql(bulk);
});
it('throws an error for anything else', function () {
var ser = makeSerializer();
(function () {
ser.bulkBody({});
}).should.throw();
(function () {
ser.bulkBody(null);
}).should.throw();
(function () {
ser.bulkBody(false);
}).should.throw();
});
});
});

View File

@ -1,7 +1,6 @@
var Log = require('../../src/lib/log');
var StdioLogger = require('../../src/lib/loggers/stdio');
var sinon = require('sinon');
var stubs = [];
var parentLog;
beforeEach(function () {
@ -9,60 +8,22 @@ beforeEach(function () {
});
afterEach(function () {
var stub;
while (stub = stubs.pop()) {
stub.restore();
}
parentLog.close();
});
function stub() {
stubs.push(sinon.stub.apply(sinon, arguments));
function makeLogger(parent, levels) {
parent = parent || parentLog;
var config = {
levels: Log.parseLevels(levels || 'trace')
};
return new StdioLogger(parent, config);
}
function makeLogger(colors) {
var config = {
levels: Log.parseLevels('trace')
};
if (colors !== void 0) {
config.colors = colors;
}
return new StdioLogger(parentLog, config);
}
var stub = require('./auto_release_stub').make();
describe('Stdio Logger', function () {
describe('pays attention to the level setting', function () {
beforeEach(function () {
var logger = makeLogger();
stub(parentLog, 'emit');
});
it('listens for all the events', function () {
parentLog.listenerCount('error').should.eql(1);
parentLog.listenerCount('warning').should.eql(1);
parentLog.listenerCount('info').should.eql(1);
parentLog.listenerCount('debug').should.eql(1);
parentLog.listenerCount('trace').should.eql(1);
});
it('emits events because something is listening', function () {
parentLog.error(new Error('error message'));
parentLog.emit.lastCall.args[0].should.eql('error');
parentLog.warning('warning');
parentLog.emit.lastCall.args[0].should.eql('warning');
parentLog.info('info');
parentLog.emit.lastCall.args[0].should.eql('info');
parentLog.debug('debug');
parentLog.emit.lastCall.args[0].should.eql('debug');
parentLog.trace('GET', {}, '', '', 200);
parentLog.emit.lastCall.args[0].should.eql('trace');
});
});
require('./generic_logger_tests')(makeLogger);
describe('colorizing', function () {
var chalk = require('chalk');
@ -72,7 +33,7 @@ describe('Stdio Logger', function () {
var clock;
beforeEach(function () {
stubs.push(sinon.useFakeTimers(nowTime));
stub.autoRelease(sinon.useFakeTimers(nowTime));
});
it('uses colors when it\'s supported', function () {
@ -92,7 +53,8 @@ describe('Stdio Logger', function () {
});
it('obeys the logger.color === true', function () {
var logger = makeLogger(false);
var logger = makeLogger();
stub(process.stdout, 'write');
var withoutColor = 'TRACE: ' + now + '\n curl\n msg\n\n';
@ -103,110 +65,4 @@ describe('Stdio Logger', function () {
});
});
describe('#onError', function () {
it('uses the Error name when it is not just "Error"', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
label.should.eql('TypeError');
});
logger.onError(new TypeError('Typerr'));
logger.write.callCount.should.eql(1);
});
it('uses "ERROR" when the error name is "Error"', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
label.should.eql('ERROR');
});
logger.onError(new Error('thing'));
logger.write.callCount.should.eql(1);
});
});
describe('#onWarning', function () {
it('uses the "WARNING" label', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
label.should.eql('WARNING');
});
logger.onWarning('message');
logger.write.callCount.should.eql(1);
});
it('echos the message', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
msg.should.eql('message');
});
logger.onWarning('message');
logger.write.callCount.should.eql(1);
});
});
describe('#onInfo', function () {
it('uses the "INFO" label', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
label.should.eql('INFO');
});
logger.onInfo('message');
logger.write.callCount.should.eql(1);
});
it('echos the message', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
msg.should.eql('message');
});
logger.onInfo('message');
logger.write.callCount.should.eql(1);
});
});
describe('#onDebug', function () {
it('uses the "DEBUG" label', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
label.should.eql('DEBUG');
});
logger.onDebug('message');
logger.write.callCount.should.eql(1);
});
it('echos the message', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
msg.should.eql('message');
});
logger.onDebug('message');
logger.write.callCount.should.eql(1);
});
});
describe('#onTrace', function () {
it('uses the "TRACE" label', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
label.should.eql('TRACE');
});
logger.onTrace('message');
logger.write.callCount.should.eql(1);
});
it('joins the message and curl call with a newline', function () {
var logger = makeLogger();
stub(logger, 'write', function (to, label, colorize, msg) {
msg.should.eql('curlcall\nmessage');
});
logger.onTrace('message', 'curlcall');
logger.write.callCount.should.eql(1);
});
});
});

View File

@ -1,76 +1,37 @@
var Log = require('../../src/lib/log');
var StreamLogger = require('../../src/lib/loggers/stream');
var MockWritableStream = require('../mocks/writable_stream');
var MockOldWritableStream = require('../mocks/old_writable_stream');
var once = require('events').EventEmitter.prototype.once;
var write = require('stream').Writable.prototype.write;
var sinon = require('sinon');
var stubs = [];
var parentLog;
var stream = new MockWritableStream();
var _ = require('lodash');
var util = require('util');
var parentLog;
var stub = require('./auto_release_stub').make();
beforeEach(function () {
parentLog = new Log();
stub(stream, 'write', function () { console.log('stubbed write'); });
stub(stream, 'end', function () { console.log('stubbed close'); });
stub(stream, 'write');
stub(stream, 'end');
});
afterEach(function () {
parentLog.close();
var stub;
while (stub = stubs.pop()) {
stub.restore();
}
});
function stub() {
stubs.push(sinon.stub.apply(sinon, arguments));
}
function makeLogger() {
function makeLogger(parent, levels) {
parent = parent || parentLog;
var config = {
levels: Log.parseLevels('trace'),
levels: Log.parseLevels(levels || 'trace'),
stream: stream
};
return new StreamLogger(parentLog, config);
return new StreamLogger(parent, config);
}
describe('Stream Logger', function () {
describe('pays attention to the level setting', function () {
beforeEach(function () {
var logger = makeLogger();
stub(parentLog, 'emit');
});
it('listens for all the events', function () {
parentLog.listenerCount('error').should.eql(1);
parentLog.listenerCount('warning').should.eql(1);
parentLog.listenerCount('info').should.eql(1);
parentLog.listenerCount('debug').should.eql(1);
parentLog.listenerCount('trace').should.eql(1);
});
it('emits events because something is listening', function () {
parentLog.error(new Error('error message'));
parentLog.emit.lastCall.args[0].should.eql('error');
parentLog.warning('warning');
parentLog.emit.lastCall.args[0].should.eql('warning');
parentLog.info('info');
parentLog.emit.lastCall.args[0].should.eql('info');
parentLog.debug('debug');
parentLog.emit.lastCall.args[0].should.eql('debug');
parentLog.trace('GET', {}, '', '', 200);
parentLog.emit.lastCall.args[0].should.eql('trace');
});
});
describe('buffer flushing', function () {
it('writes everything in the buffer to console.error', function () {
var onExitCallback;
@ -99,8 +60,14 @@ describe('Stream Logger', function () {
// empty the buffer manually
stream._writableState.buffer.splice(0);
flushedOutput.match(new RegExp(line, 'g')).length.should.above(0);
// the first line is stuck "in writing" and there is nothing we can do about that
flushedOutput.match(new RegExp(line, 'g')).length.should.eql(9);
});
it('works with older streams');
});
require('./generic_logger_tests')(makeLogger);
});

View File

@ -4,17 +4,7 @@ var Host = require('../../src/lib/host');
var sinon = require('sinon');
var nodeList = require('../fixtures/short_node_list.json');
var stubs = [];
function stub() {
stubs.push(sinon.stub.apply(sinon, arguments));
}
afterEach(function () {
var stub;
while (stub = stubs.pop()) {
stub.restore();
}
});
var stub = require('./auto_release_stub').make();
describe('Transport Class', function () {

View File

@ -134,8 +134,8 @@ describe('Utils', function () {
_.camelCase('Json_parser').should.eql('jsonParser');
});
it('handles trailing _', function () {
_.camelCase('_thing_one_').should.eql('thingOne');
it('handles leading _', function () {
_.camelCase('_thing_one_').should.eql('_thingOne');
});
});
@ -148,8 +148,8 @@ describe('Utils', function () {
_.studlyCase('Json_parser').should.eql('JsonParser');
});
it('handles trailing _', function () {
_.studlyCase('_thing_one_').should.eql('ThingOne');
it('handles leading _', function () {
_.studlyCase('_thing_one_').should.eql('_ThingOne');
});
});
@ -162,8 +162,8 @@ describe('Utils', function () {
_.snakeCase('Json_parser').should.eql('json_parser');
});
it('handles trailing _', function () {
_.snakeCase('_thing_one_').should.eql('thing_one');
it('handles leading _', function () {
_.snakeCase('_thing_one_').should.eql('_thing_one');
});
});
@ -317,13 +317,22 @@ describe('Utils', function () {
_.funcEnum(config, 'config key name', { toString: 'pizza' }, 'toJSON')
.should.be.exactly('pizza');
});
it('throws an error if the selection if invalid', function () {
it('throws an informative error if the selection if invalid', function () {
var config = {
'config': 'val'
};
(function () {
_.funcEnum(config, 'config', {});
}).should.throw(/expected a function/i);
(function () {
_.funcEnum(config, 'config', { main: 'default' }, 'main');
}).should.throw(/invalid config/i);
}).should.throw(/expected a function or main/i);
(function () {
_.funcEnum(config, 'config', { main: 'default', other: 'default' }, 'main');
}).should.throw(/expected a function or one of main, other/i);
});
});
});