2012-02-08 18:05:56 +00:00
|
|
|
/*
|
2012-02-08 18:30:13 +00:00
|
|
|
* Copyright (c) 2012 Trent Mick. All rights reserved.
|
2012-02-08 18:05:56 +00:00
|
|
|
*
|
|
|
|
* Test type checking on creation of the Logger.
|
|
|
|
*/
|
|
|
|
|
2012-04-27 23:20:57 +00:00
|
|
|
var bunyan = require('../lib/bunyan'),
|
|
|
|
Logger = bunyan;
|
|
|
|
|
2013-01-07 19:18:12 +00:00
|
|
|
// node-tap API
|
|
|
|
if (require.cache[__dirname + '/tap4nodeunit.js'])
|
|
|
|
delete require.cache[__dirname + '/tap4nodeunit.js'];
|
|
|
|
var tap4nodeunit = require('./tap4nodeunit.js');
|
|
|
|
var after = tap4nodeunit.after;
|
|
|
|
var before = tap4nodeunit.before;
|
|
|
|
var test = tap4nodeunit.test;
|
|
|
|
|
2012-02-08 18:05:56 +00:00
|
|
|
|
|
|
|
|
2012-02-08 18:30:13 +00:00
|
|
|
test('ensure Logger creation options', function (t) {
|
|
|
|
t.throws(function () { new Logger(); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'options (object) is required',
|
2012-02-08 18:30:13 +00:00
|
|
|
'no options should throw');
|
|
|
|
|
|
|
|
t.throws(function () { new Logger({}); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'options.name (string) is required',
|
2012-02-08 18:30:13 +00:00
|
|
|
'no options.name should throw');
|
|
|
|
|
|
|
|
t.doesNotThrow(function () { new Logger({name: 'foo'}); },
|
|
|
|
'just options.name should be sufficient');
|
|
|
|
|
|
|
|
var options = {name: 'foo', stream: process.stdout, streams: []};
|
|
|
|
t.throws(function () { new Logger(options); },
|
|
|
|
'cannot use "stream" and "streams"');
|
|
|
|
|
|
|
|
// https://github.com/trentm/node-bunyan/issues/3
|
|
|
|
options = {name: 'foo', streams: {}};
|
|
|
|
t.throws(function () { new Logger(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.streams: must be an array',
|
2012-02-08 18:30:13 +00:00
|
|
|
'"streams" must be an array');
|
|
|
|
|
2012-02-10 08:14:33 +00:00
|
|
|
options = {name: 'foo', serializers: 'a string'};
|
2012-02-08 18:30:13 +00:00
|
|
|
t.throws(function () { new Logger(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.serializers: must be an object',
|
2012-02-08 18:30:13 +00:00
|
|
|
'"serializers" cannot be a string');
|
|
|
|
|
2012-04-28 00:40:56 +00:00
|
|
|
options = {name: 'foo', serializers: [1, 2, 3]};
|
2012-02-08 18:30:13 +00:00
|
|
|
t.throws(function () { new Logger(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.serializers: must be an object',
|
2012-02-08 18:30:13 +00:00
|
|
|
'"serializers" cannot be an array');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-04-27 23:20:57 +00:00
|
|
|
test('ensure Logger creation options (createLogger)', function (t) {
|
|
|
|
t.throws(function () { bunyan.createLogger(); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'options (object) is required',
|
2012-04-27 23:20:57 +00:00
|
|
|
'no options should throw');
|
|
|
|
|
|
|
|
t.throws(function () { bunyan.createLogger({}); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'options.name (string) is required',
|
2012-04-27 23:20:57 +00:00
|
|
|
'no options.name should throw');
|
|
|
|
|
|
|
|
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
|
|
|
|
'just options.name should be sufficient');
|
|
|
|
|
|
|
|
var options = {name: 'foo', stream: process.stdout, streams: []};
|
|
|
|
t.throws(function () { bunyan.createLogger(options); },
|
|
|
|
'cannot use "stream" and "streams"');
|
|
|
|
|
|
|
|
// https://github.com/trentm/node-bunyan/issues/3
|
|
|
|
options = {name: 'foo', streams: {}};
|
|
|
|
t.throws(function () { bunyan.createLogger(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.streams: must be an array',
|
2012-04-27 23:20:57 +00:00
|
|
|
'"streams" must be an array');
|
|
|
|
|
|
|
|
options = {name: 'foo', serializers: 'a string'};
|
|
|
|
t.throws(function () { bunyan.createLogger(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.serializers: must be an object',
|
2012-04-27 23:20:57 +00:00
|
|
|
'"serializers" cannot be a string');
|
|
|
|
|
2012-04-28 00:40:56 +00:00
|
|
|
options = {name: 'foo', serializers: [1, 2, 3]};
|
2012-04-27 23:20:57 +00:00
|
|
|
t.throws(function () { bunyan.createLogger(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.serializers: must be an object',
|
2012-04-27 23:20:57 +00:00
|
|
|
'"serializers" cannot be an array');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-02-08 18:30:13 +00:00
|
|
|
test('ensure Logger child() options', function (t) {
|
|
|
|
var log = new Logger({name: 'foo'});
|
|
|
|
|
|
|
|
t.doesNotThrow(function () { log.child(); },
|
|
|
|
'no options should be fine');
|
|
|
|
|
|
|
|
t.doesNotThrow(function () { log.child({}); },
|
|
|
|
'empty options should be fine too');
|
|
|
|
|
|
|
|
t.throws(function () { log.child({name: 'foo'}); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.name: child cannot set logger name',
|
2012-02-08 18:30:13 +00:00
|
|
|
'child cannot change name');
|
|
|
|
|
|
|
|
var options = {stream: process.stdout, streams: []};
|
|
|
|
t.throws(function () { log.child(options); },
|
|
|
|
'cannot use "stream" and "streams"');
|
|
|
|
|
|
|
|
// https://github.com/trentm/node-bunyan/issues/3
|
|
|
|
options = {streams: {}};
|
|
|
|
t.throws(function () { log.child(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.streams: must be an array',
|
2012-02-08 18:30:13 +00:00
|
|
|
'"streams" must be an array');
|
|
|
|
|
2012-04-28 00:40:56 +00:00
|
|
|
options = {serializers: 'a string'};
|
2012-02-08 18:30:13 +00:00
|
|
|
t.throws(function () { log.child(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.serializers: must be an object',
|
2012-02-08 18:30:13 +00:00
|
|
|
'"serializers" cannot be a string');
|
|
|
|
|
2012-04-28 00:40:56 +00:00
|
|
|
options = {serializers: [1, 2, 3]};
|
2012-02-08 18:30:13 +00:00
|
|
|
t.throws(function () { log.child(options); },
|
2013-01-07 19:18:12 +00:00
|
|
|
'invalid options.serializers: must be an object',
|
2012-02-08 18:30:13 +00:00
|
|
|
'"serializers" cannot be an array');
|
|
|
|
|
2012-02-08 18:05:56 +00:00
|
|
|
t.end();
|
|
|
|
});
|