node-bunyan-lite/test/ringbuffer.test.js

48 lines
1.3 KiB
JavaScript
Raw Permalink Normal View History

2012-06-19 21:36:02 +00:00
/*
* Test the RingBuffer output stream.
*/
var Logger = require('../lib/bunyan');
var ringbuffer = new Logger.RingBuffer({ 'limit': 5 });
2013-01-07 19:18:12 +00:00
// node-tap API
if (require.cache[__dirname + '/tap4nodeunit.js'])
2013-03-29 00:42:32 +00:00
delete require.cache[__dirname + '/tap4nodeunit.js'];
2013-01-07 19:18:12 +00:00
var tap4nodeunit = require('./tap4nodeunit.js');
var after = tap4nodeunit.after;
var before = tap4nodeunit.before;
var test = tap4nodeunit.test;
2012-06-19 21:36:02 +00:00
var log1 = new Logger({
2013-03-29 00:42:32 +00:00
name: 'log1',
streams: [
{
stream: ringbuffer,
type: 'raw',
level: 'info'
}
]
2012-06-19 21:36:02 +00:00
});
test('ringbuffer', function (t) {
2013-03-29 00:42:32 +00:00
log1.info('hello');
log1.trace('there');
log1.error('android');
t.equal(ringbuffer.records.length, 2);
t.equal(ringbuffer.records[0]['msg'], 'hello');
t.equal(ringbuffer.records[1]['msg'], 'android');
log1.error('one');
log1.error('two');
log1.error('three');
t.equal(ringbuffer.records.length, 5);
log1.error('four');
t.equal(ringbuffer.records.length, 5);
t.equal(ringbuffer.records[0]['msg'], 'android');
t.equal(ringbuffer.records[1]['msg'], 'one');
t.equal(ringbuffer.records[2]['msg'], 'two');
t.equal(ringbuffer.records[3]['msg'], 'three');
t.equal(ringbuffer.records[4]['msg'], 'four');
t.end();
2012-06-19 21:36:02 +00:00
});