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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var test = require('tap').test;
|
|
|
|
var Logger = require('../lib/bunyan');
|
|
|
|
|
|
|
|
|
2012-02-08 18:30:13 +00:00
|
|
|
test('ensure Logger creation options', function (t) {
|
|
|
|
t.throws(function () { new Logger(); },
|
|
|
|
{name: 'TypeError', message: 'options (object) is required'},
|
|
|
|
'no options should throw');
|
|
|
|
|
|
|
|
t.throws(function () { new Logger({}); },
|
|
|
|
{name: 'TypeError', message: 'options.name (string) is required'},
|
|
|
|
'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"');
|
|
|
|
|
|
|
|
options = {name: 'foo', level: 'info', streams: []};
|
|
|
|
t.throws(function () { new Logger(options); },
|
|
|
|
'cannot use "level" and "streams"');
|
|
|
|
|
|
|
|
// https://github.com/trentm/node-bunyan/issues/3
|
|
|
|
options = {name: 'foo', streams: {}};
|
|
|
|
t.throws(function () { new Logger(options); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.streams: must be an array'},
|
|
|
|
'"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); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.serializers: must be an object'},
|
|
|
|
'"serializers" cannot be a string');
|
|
|
|
|
|
|
|
options = {name: 'foo', serializers: [1,2,3]};
|
|
|
|
t.throws(function () { new Logger(options); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.serializers: must be an object'},
|
|
|
|
'"serializers" cannot be an array');
|
|
|
|
|
|
|
|
t.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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'}); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.name: child cannot set logger name'},
|
|
|
|
'child cannot change name');
|
|
|
|
|
|
|
|
var options = {stream: process.stdout, streams: []};
|
|
|
|
t.throws(function () { log.child(options); },
|
|
|
|
'cannot use "stream" and "streams"');
|
|
|
|
|
|
|
|
options = {level: 'info', streams: []};
|
|
|
|
t.throws(function () { log.child(options); },
|
|
|
|
'cannot use "level" and "streams"');
|
|
|
|
|
|
|
|
// https://github.com/trentm/node-bunyan/issues/3
|
|
|
|
options = {streams: {}};
|
|
|
|
t.throws(function () { log.child(options); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.streams: must be an array'},
|
|
|
|
'"streams" must be an array');
|
|
|
|
|
|
|
|
options = {serializers: "a string"};
|
|
|
|
t.throws(function () { log.child(options); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.serializers: must be an object'},
|
|
|
|
'"serializers" cannot be a string');
|
|
|
|
|
|
|
|
options = {serializers: [1,2,3]};
|
|
|
|
t.throws(function () { log.child(options); },
|
|
|
|
{name: 'TypeError', message: 'invalid options.serializers: must be an object'},
|
|
|
|
'"serializers" cannot be an array');
|
|
|
|
|
2012-02-08 18:05:56 +00:00
|
|
|
t.end();
|
|
|
|
});
|