move test suite to nodeunit
This commit is contained in:
parent
51fda28eb9
commit
bd4dec5bec
17 changed files with 260 additions and 117 deletions
|
@ -8,7 +8,8 @@ Known issues:
|
||||||
|
|
||||||
## bunyan 0.17.1 (not yet released)
|
## bunyan 0.17.1 (not yet released)
|
||||||
|
|
||||||
(nothing yet)
|
- Switch test suite to nodeunit (still using a node-tap'ish API via
|
||||||
|
a helper).
|
||||||
|
|
||||||
|
|
||||||
## bunyan 0.17.0
|
## bunyan 0.17.0
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -1,7 +1,7 @@
|
||||||
|
|
||||||
#---- Tools
|
#---- Tools
|
||||||
|
|
||||||
TAP := ./node_modules/.bin/tap
|
NODEUNIT := ./node_modules/.bin/nodeunit
|
||||||
SUDO := sudo
|
SUDO := sudo
|
||||||
ifeq ($(shell uname -s),SunOS)
|
ifeq ($(shell uname -s),SunOS)
|
||||||
# On SunOS (e.g. SmartOS) we expect to run the test suite as the
|
# On SunOS (e.g. SmartOS) we expect to run the test suite as the
|
||||||
|
@ -16,7 +16,7 @@ endif
|
||||||
|
|
||||||
JSSTYLE_FILES := $(shell find lib test tools examples -name "*.js") bin/bunyan
|
JSSTYLE_FILES := $(shell find lib test tools examples -name "*.js") bin/bunyan
|
||||||
# All test files *except* dtrace.test.js.
|
# All test files *except* dtrace.test.js.
|
||||||
TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs)
|
NON_DTRACE_TEST_FILES := $(shell ls -1 test/*.test.js | grep -v dtrace | xargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -66,11 +66,11 @@ distclean:
|
||||||
#---- test
|
#---- test
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: $(TAP)
|
test: $(NODEUNIT)
|
||||||
[[ -n "$(SKIP_DTRACE)" ]] || \
|
[[ -n "$(SKIP_DTRACE)" ]] || \
|
||||||
node -e 'require("dtrace-provider").createDTraceProvider("isthisthingon")' && \
|
node -e 'require("dtrace-provider").createDTraceProvider("isthisthingon")' && \
|
||||||
$(SUDO) $(TAP) --tap test/dtrace.test.js
|
$(SUDO) $(NODEUNIT) test/dtrace.test.js
|
||||||
$(TAP) --tap $(TEST_FILES)
|
$(NODEUNIT) $(NON_DTRACE_TEST_FILES)
|
||||||
|
|
||||||
# Test will all node supported versions (presumes install locations I use on
|
# Test will all node supported versions (presumes install locations I use on
|
||||||
# my machine).
|
# my machine).
|
||||||
|
|
|
@ -601,7 +601,7 @@ function handleLogLine(file, line, opts, stylize) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isValidRecord(rec)) {
|
if (!isValidRecord(rec)) {
|
||||||
if (!opts.strict) emitRecord(rec, line, opts, stylize);
|
if (!opts.strict) emit(line + '\n');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,12 +23,12 @@
|
||||||
"mv": "0.0.4"
|
"mv": "0.0.4"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tap": "0.3.3",
|
"nodeunit": "0.7.4",
|
||||||
"ben": "0.0.0",
|
"ben": "0.0.0",
|
||||||
"verror": "1.3.3"
|
"verror": "1.3.3"
|
||||||
},
|
},
|
||||||
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "tap test/*.js"
|
"test": "make test"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,9 +8,17 @@
|
||||||
var util = require('util'),
|
var util = require('util'),
|
||||||
inspect = util.inspect,
|
inspect = util.inspect,
|
||||||
format = util.format;
|
format = util.format;
|
||||||
var test = require('tap').test;
|
|
||||||
var bunyan = require('../lib/bunyan');
|
var bunyan = require('../lib/bunyan');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Catcher() {
|
function Catcher() {
|
||||||
this.records = [];
|
this.records = [];
|
||||||
|
|
|
@ -4,9 +4,18 @@
|
||||||
* Test some `<Logger>.child(...)` behaviour.
|
* Test some `<Logger>.child(...)` behaviour.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var bunyan = require('../lib/bunyan');
|
var bunyan = require('../lib/bunyan');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function CapturingStream(recs) {
|
function CapturingStream(recs) {
|
||||||
this.recs = recs || [];
|
this.recs = recs || [];
|
||||||
}
|
}
|
||||||
|
|
114
test/cli.test.js
114
test/cli.test.js
|
@ -6,10 +6,19 @@
|
||||||
|
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var exec = require('child_process').exec;
|
var exec = require('child_process').exec;
|
||||||
var format = require('util').format;
|
var _ = require('util').format;
|
||||||
var test = require('tap').test;
|
|
||||||
var debug = console.warn;
|
var debug = console.warn;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var BUNYAN = path.resolve(__dirname, '../bin/bunyan');
|
var BUNYAN = path.resolve(__dirname, '../bin/bunyan');
|
||||||
|
|
||||||
//child = exec('cat *.js bad_file | wc -l',
|
//child = exec('cat *.js bad_file | wc -l',
|
||||||
|
@ -24,7 +33,7 @@ var BUNYAN = path.resolve(__dirname, '../bin/bunyan');
|
||||||
test('--version', function (t) {
|
test('--version', function (t) {
|
||||||
var version = require('../package.json').version;
|
var version = require('../package.json').version;
|
||||||
exec(BUNYAN + ' --version', function (err, stdout, stderr) {
|
exec(BUNYAN + ' --version', function (err, stdout, stderr) {
|
||||||
t.error(err)
|
t.ifError(err)
|
||||||
t.equal(stdout, 'bunyan ' + version + '\n');
|
t.equal(stdout, 'bunyan ' + version + '\n');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -32,7 +41,7 @@ test('--version', function (t) {
|
||||||
|
|
||||||
test('--help', function (t) {
|
test('--help', function (t) {
|
||||||
exec(BUNYAN + ' --help', function (err, stdout, stderr) {
|
exec(BUNYAN + ' --help', function (err, stdout, stderr) {
|
||||||
t.error(err)
|
t.ifError(err)
|
||||||
t.ok(stdout.indexOf('General options:') !== -1);
|
t.ok(stdout.indexOf('General options:') !== -1);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -40,7 +49,7 @@ test('--help', function (t) {
|
||||||
|
|
||||||
test('-h', function (t) {
|
test('-h', function (t) {
|
||||||
exec(BUNYAN + ' -h', function (err, stdout, stderr) {
|
exec(BUNYAN + ' -h', function (err, stdout, stderr) {
|
||||||
t.error(err)
|
t.ifError(err)
|
||||||
t.ok(stdout.indexOf('General options:') !== -1);
|
t.ok(stdout.indexOf('General options:') !== -1);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -55,8 +64,9 @@ test('--bogus', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('simple.log', function (t) {
|
test('simple.log', function (t) {
|
||||||
exec(BUNYAN + ' corpus/simple.log', function (err, stdout, stderr) {
|
exec(_('%s %s/corpus/simple.log', BUNYAN, __dirname),
|
||||||
t.error(err)
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err)
|
||||||
t.equal(stdout,
|
t.equal(stdout,
|
||||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||||
+ 'My message\n');
|
+ 'My message\n');
|
||||||
|
@ -64,9 +74,9 @@ test('simple.log', function (t) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('cat simple.log', function (t) {
|
test('cat simple.log', function (t) {
|
||||||
exec(format('cat corpus/simple.log | %s', BUNYAN),
|
exec(_('cat %s/corpus/simple.log | %s', __dirname, BUNYAN),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.error(err)
|
t.ifError(err)
|
||||||
t.equal(stdout,
|
t.equal(stdout,
|
||||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||||
+ 'My message\n');
|
+ 'My message\n');
|
||||||
|
@ -75,8 +85,9 @@ test('cat simple.log', function (t) {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
test('simple.log with color', function (t) {
|
test('simple.log with color', function (t) {
|
||||||
exec(BUNYAN + ' --color corpus/simple.log', function (err, stdout, stderr) {
|
exec(_('%s --color %s/corpus/simple.log', BUNYAN, __dirname),
|
||||||
t.error(err)
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err)
|
||||||
t.equal(stdout,
|
t.equal(stdout,
|
||||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
||||||
+ 'on example.com: \u001b[36mMy message\u001b[39m\n');
|
+ 'on example.com: \u001b[36mMy message\u001b[39m\n');
|
||||||
|
@ -85,8 +96,9 @@ test('simple.log with color', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('extrafield.log', function (t) {
|
test('extrafield.log', function (t) {
|
||||||
exec(BUNYAN + ' corpus/extrafield.log', function (err, stdout, stderr) {
|
exec(_('%s %s/corpus/extrafield.log', BUNYAN, __dirname),
|
||||||
t.error(err)
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err)
|
||||||
t.equal(stdout,
|
t.equal(stdout,
|
||||||
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
'[2012-02-08T22:56:52.856Z] INFO: myservice/123 on example.com: '
|
||||||
+ 'My message (extra=field)\n');
|
+ 'My message (extra=field)\n');
|
||||||
|
@ -94,9 +106,9 @@ test('extrafield.log', function (t) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
test('extrafield.log with color', function (t) {
|
test('extrafield.log with color', function (t) {
|
||||||
exec(BUNYAN + ' --color corpus/extrafield.log',
|
exec(_('%s --color %s/corpus/extrafield.log', BUNYAN, __dirname),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.error(err)
|
t.ifError(err)
|
||||||
t.equal(stdout,
|
t.equal(stdout,
|
||||||
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
'[2012-02-08T22:56:52.856Z] \u001b[36m INFO\u001b[39m: myservice/123 '
|
||||||
+ 'on example.com: \u001b[36mMy message\u001b[39m'
|
+ 'on example.com: \u001b[36mMy message\u001b[39m'
|
||||||
|
@ -106,31 +118,35 @@ test('extrafield.log with color', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bogus.log', function (t) {
|
test('bogus.log', function (t) {
|
||||||
exec(BUNYAN + ' corpus/bogus.log', function (err, stdout, stderr) {
|
exec(_('%s %s/corpus/bogus.log', BUNYAN, __dirname),
|
||||||
t.error(err)
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err)
|
||||||
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bogus.log -j', function (t) {
|
test('bogus.log -j', function (t) {
|
||||||
exec(BUNYAN + ' -j corpus/bogus.log', function (err, stdout, stderr) {
|
exec(_('%s -j %s/corpus/bogus.log', BUNYAN, __dirname),
|
||||||
t.error(err)
|
function (err, stdout, stderr) {
|
||||||
t.equal(stdout, 'not a JSON line\n{\n "hi": "there"\n}\n');
|
t.ifError(err)
|
||||||
|
t.equal(stdout, 'not a JSON line\n{"hi": "there"}\n');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('all.log', function (t) {
|
test('all.log', function (t) {
|
||||||
exec(BUNYAN + ' corpus/all.log', function (err, stdout, stderr) {
|
exec(_('%s %s/corpus/all.log', BUNYAN, __dirname),
|
||||||
|
function (err, stdout, stderr) {
|
||||||
// Just make sure don't blow up on this.
|
// Just make sure don't blow up on this.
|
||||||
t.error(err)
|
t.ifError(err)
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('simple.log doesnotexist1.log doesnotexist2.log', function (t) {
|
test('simple.log doesnotexist1.log doesnotexist2.log', function (t) {
|
||||||
exec(BUNYAN + ' corpus/simple.log doesnotexist1.log doesnotexist2.log',
|
exec(_('%s %s/corpus/simple.log doesnotexist1.log doesnotexist2.log',
|
||||||
|
BUNYAN, __dirname),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.ok(err)
|
t.ok(err)
|
||||||
t.equal(err.code, 2)
|
t.equal(err.code, 2)
|
||||||
|
@ -151,9 +167,9 @@ test('simple.log doesnotexist1.log doesnotexist2.log', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('multiple logs', function (t) {
|
test('multiple logs', function (t) {
|
||||||
exec(BUNYAN + ' corpus/log1.log corpus/log2.log',
|
exec(_('%s %s/corpus/log1.log %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.error(err);
|
t.ifError(err);
|
||||||
t.equal(stdout, [
|
t.equal(stdout, [
|
||||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||||
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
||||||
|
@ -170,8 +186,9 @@ test('multiple logs', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('log1.log.gz', function (t) {
|
test('log1.log.gz', function (t) {
|
||||||
exec(BUNYAN + ' corpus/log1.log.gz', function (err, stdout, stderr) {
|
exec(_('%s %s/corpus/log1.log.gz', BUNYAN, __dirname),
|
||||||
t.error(err);
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err);
|
||||||
t.equal(stdout, [
|
t.equal(stdout, [
|
||||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||||
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
'[2012-05-08T17:02:49.339Z] INFO: agent1/73267 on headnode: message\n',
|
||||||
|
@ -183,9 +200,9 @@ test('log1.log.gz', function (t) {
|
||||||
});
|
});
|
||||||
|
|
||||||
test('mixed text and gzip logs', function (t) {
|
test('mixed text and gzip logs', function (t) {
|
||||||
exec(BUNYAN + ' corpus/log1.log.gz corpus/log2.log',
|
exec(_('%s %s/corpus/log1.log.gz %s/corpus/log2.log', BUNYAN, __dirname, __dirname),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.error(err);
|
t.ifError(err);
|
||||||
t.equal(stdout, [
|
t.equal(stdout, [
|
||||||
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
'[2012-05-08T16:57:55.586Z] INFO: agent1/73267 on headnode: message\n',
|
||||||
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
'[2012-05-08T16:58:55.586Z] INFO: agent2/73267 on headnode: message\n',
|
||||||
|
@ -215,11 +232,13 @@ test('--level 40', function (t) {
|
||||||
'not a JSON line\n',
|
'not a JSON line\n',
|
||||||
'{"hi": "there"}\n'
|
'{"hi": "there"}\n'
|
||||||
].join('');
|
].join('');
|
||||||
exec(BUNYAN + ' -l 40 corpus/all.log', function (err, stdout, stderr) {
|
exec(_('%s -l 40 %s/corpus/all.log', BUNYAN, __dirname),
|
||||||
t.error(err);
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err);
|
||||||
t.equal(stdout, expect);
|
t.equal(stdout, expect);
|
||||||
exec(BUNYAN + ' --level 40 corpus/all.log', function (err, stdout, stderr) {
|
exec(_('%s --level 40 %s/corpus/all.log', BUNYAN, __dirname),
|
||||||
t.error(err);
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err);
|
||||||
t.equal(stdout, expect);
|
t.equal(stdout, expect);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -237,13 +256,13 @@ test('--condition "level === 10 && pid === 123"', function (t) {
|
||||||
'not a JSON line\n',
|
'not a JSON line\n',
|
||||||
'{"hi": "there"}\n'
|
'{"hi": "there"}\n'
|
||||||
].join('');
|
].join('');
|
||||||
exec(BUNYAN + ' -c "level === 10 && pid === 123" corpus/all.log',
|
exec(_('%s -c "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.error(err);
|
t.ifError(err);
|
||||||
t.equal(stdout, expect);
|
t.equal(stdout, expect);
|
||||||
exec(BUNYAN + ' --condition "level === 10 && pid === 123" corpus/all.log',
|
exec(_('%s --condition "level === 10 && pid === 123" %s/corpus/all.log', BUNYAN, __dirname),
|
||||||
function (err, stdout, stderr) {
|
function (err, stdout, stderr) {
|
||||||
t.error(err);
|
t.ifError(err);
|
||||||
t.equal(stdout, expect);
|
t.equal(stdout, expect);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -263,10 +282,11 @@ test('multiple --conditions', function (t) {
|
||||||
'not a JSON line\n',
|
'not a JSON line\n',
|
||||||
'{"hi": "there"}\n'
|
'{"hi": "there"}\n'
|
||||||
].join('');
|
].join('');
|
||||||
exec(BUNYAN + ' corpus/all.log ' +
|
exec(_('%s %s/corpus/all.log ' +
|
||||||
'-c "if (level === 40) pid = 1; true" ' +
|
'-c "if (level === 40) pid = 1; true" ' +
|
||||||
'-c "pid === 1"', function (err, stdout, stderr) {
|
'-c "pid === 1"', BUNYAN, __dirname),
|
||||||
t.error(err);
|
function (err, stdout, stderr) {
|
||||||
|
t.ifError(err);
|
||||||
t.equal(stdout, expect);
|
t.equal(stdout, expect);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -310,17 +330,9 @@ test('robust req handling', function (t) {
|
||||||
' "version": false',
|
' "version": false',
|
||||||
' }'
|
' }'
|
||||||
].join('\n') + '\n';
|
].join('\n') + '\n';
|
||||||
exec(BUNYAN + ' corpus/withreq.log', function (err, stdout, stderr) {
|
exec(_('%s %s/corpus/withreq.log', BUNYAN, __dirname),
|
||||||
t.error(err);
|
function (err, stdout, stderr) {
|
||||||
t.equal(stdout, expect);
|
t.ifError(err);
|
||||||
t.end();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('non-object res field', function (t) {
|
|
||||||
var expect = '[2012-10-10T16:14:07.610Z] INFO: cnapi.get_existing_nics/24440 on 710c784f-6aa5-428c-9074-e046c3af884e: got existing: 02:08:20:d7:53:e0 (job_uuid=3499b13e-dbca-4331-b13a-f164c0da320a, nic=<unknown>, res="error: Unknown nic \\"020820d753e0\\"")\n';
|
|
||||||
exec(BUNYAN + ' corpus/non-object-res.log', function (err, stdout, stderr) {
|
|
||||||
t.error(err);
|
|
||||||
t.equal(stdout, expect);
|
t.equal(stdout, expect);
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
|
@ -4,19 +4,26 @@
|
||||||
* Test type checking on creation of the Logger.
|
* Test type checking on creation of the Logger.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var bunyan = require('../lib/bunyan'),
|
var bunyan = require('../lib/bunyan'),
|
||||||
Logger = bunyan;
|
Logger = bunyan;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
test('ensure Logger creation options', function (t) {
|
test('ensure Logger creation options', function (t) {
|
||||||
t.throws(function () { new Logger(); },
|
t.throws(function () { new Logger(); },
|
||||||
{name: 'TypeError', message: 'options (object) is required'},
|
'options (object) is required',
|
||||||
'no options should throw');
|
'no options should throw');
|
||||||
|
|
||||||
t.throws(function () { new Logger({}); },
|
t.throws(function () { new Logger({}); },
|
||||||
{name: 'TypeError', message: 'options.name (string) is required'},
|
'options.name (string) is required',
|
||||||
'no options.name should throw');
|
'no options.name should throw');
|
||||||
|
|
||||||
t.doesNotThrow(function () { new Logger({name: 'foo'}); },
|
t.doesNotThrow(function () { new Logger({name: 'foo'}); },
|
||||||
|
@ -29,23 +36,17 @@ test('ensure Logger creation options', function (t) {
|
||||||
// https://github.com/trentm/node-bunyan/issues/3
|
// https://github.com/trentm/node-bunyan/issues/3
|
||||||
options = {name: 'foo', streams: {}};
|
options = {name: 'foo', streams: {}};
|
||||||
t.throws(function () { new Logger(options); },
|
t.throws(function () { new Logger(options); },
|
||||||
{name: 'TypeError', message: 'invalid options.streams: must be an array'},
|
'invalid options.streams: must be an array',
|
||||||
'"streams" must be an array');
|
'"streams" must be an array');
|
||||||
|
|
||||||
options = {name: 'foo', serializers: 'a string'};
|
options = {name: 'foo', serializers: 'a string'};
|
||||||
t.throws(function () { new Logger(options); },
|
t.throws(function () { new Logger(options); },
|
||||||
{
|
'invalid options.serializers: must be an object',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.serializers: must be an object'
|
|
||||||
},
|
|
||||||
'"serializers" cannot be a string');
|
'"serializers" cannot be a string');
|
||||||
|
|
||||||
options = {name: 'foo', serializers: [1, 2, 3]};
|
options = {name: 'foo', serializers: [1, 2, 3]};
|
||||||
t.throws(function () { new Logger(options); },
|
t.throws(function () { new Logger(options); },
|
||||||
{
|
'invalid options.serializers: must be an object',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.serializers: must be an object'
|
|
||||||
},
|
|
||||||
'"serializers" cannot be an array');
|
'"serializers" cannot be an array');
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -54,11 +55,11 @@ test('ensure Logger creation options', function (t) {
|
||||||
|
|
||||||
test('ensure Logger creation options (createLogger)', function (t) {
|
test('ensure Logger creation options (createLogger)', function (t) {
|
||||||
t.throws(function () { bunyan.createLogger(); },
|
t.throws(function () { bunyan.createLogger(); },
|
||||||
{name: 'TypeError', message: 'options (object) is required'},
|
'options (object) is required',
|
||||||
'no options should throw');
|
'no options should throw');
|
||||||
|
|
||||||
t.throws(function () { bunyan.createLogger({}); },
|
t.throws(function () { bunyan.createLogger({}); },
|
||||||
{name: 'TypeError', message: 'options.name (string) is required'},
|
'options.name (string) is required',
|
||||||
'no options.name should throw');
|
'no options.name should throw');
|
||||||
|
|
||||||
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
|
t.doesNotThrow(function () { bunyan.createLogger({name: 'foo'}); },
|
||||||
|
@ -71,23 +72,17 @@ test('ensure Logger creation options (createLogger)', function (t) {
|
||||||
// https://github.com/trentm/node-bunyan/issues/3
|
// https://github.com/trentm/node-bunyan/issues/3
|
||||||
options = {name: 'foo', streams: {}};
|
options = {name: 'foo', streams: {}};
|
||||||
t.throws(function () { bunyan.createLogger(options); },
|
t.throws(function () { bunyan.createLogger(options); },
|
||||||
{name: 'TypeError', message: 'invalid options.streams: must be an array'},
|
'invalid options.streams: must be an array',
|
||||||
'"streams" must be an array');
|
'"streams" must be an array');
|
||||||
|
|
||||||
options = {name: 'foo', serializers: 'a string'};
|
options = {name: 'foo', serializers: 'a string'};
|
||||||
t.throws(function () { bunyan.createLogger(options); },
|
t.throws(function () { bunyan.createLogger(options); },
|
||||||
{
|
'invalid options.serializers: must be an object',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.serializers: must be an object'
|
|
||||||
},
|
|
||||||
'"serializers" cannot be a string');
|
'"serializers" cannot be a string');
|
||||||
|
|
||||||
options = {name: 'foo', serializers: [1, 2, 3]};
|
options = {name: 'foo', serializers: [1, 2, 3]};
|
||||||
t.throws(function () { bunyan.createLogger(options); },
|
t.throws(function () { bunyan.createLogger(options); },
|
||||||
{
|
'invalid options.serializers: must be an object',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.serializers: must be an object'
|
|
||||||
},
|
|
||||||
'"serializers" cannot be an array');
|
'"serializers" cannot be an array');
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
@ -104,10 +99,7 @@ test('ensure Logger child() options', function (t) {
|
||||||
'empty options should be fine too');
|
'empty options should be fine too');
|
||||||
|
|
||||||
t.throws(function () { log.child({name: 'foo'}); },
|
t.throws(function () { log.child({name: 'foo'}); },
|
||||||
{
|
'invalid options.name: child cannot set logger name',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.name: child cannot set logger name'
|
|
||||||
},
|
|
||||||
'child cannot change name');
|
'child cannot change name');
|
||||||
|
|
||||||
var options = {stream: process.stdout, streams: []};
|
var options = {stream: process.stdout, streams: []};
|
||||||
|
@ -117,23 +109,17 @@ test('ensure Logger child() options', function (t) {
|
||||||
// https://github.com/trentm/node-bunyan/issues/3
|
// https://github.com/trentm/node-bunyan/issues/3
|
||||||
options = {streams: {}};
|
options = {streams: {}};
|
||||||
t.throws(function () { log.child(options); },
|
t.throws(function () { log.child(options); },
|
||||||
{name: 'TypeError', message: 'invalid options.streams: must be an array'},
|
'invalid options.streams: must be an array',
|
||||||
'"streams" must be an array');
|
'"streams" must be an array');
|
||||||
|
|
||||||
options = {serializers: 'a string'};
|
options = {serializers: 'a string'};
|
||||||
t.throws(function () { log.child(options); },
|
t.throws(function () { log.child(options); },
|
||||||
{
|
'invalid options.serializers: must be an object',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.serializers: must be an object'
|
|
||||||
},
|
|
||||||
'"serializers" cannot be a string');
|
'"serializers" cannot be a string');
|
||||||
|
|
||||||
options = {serializers: [1, 2, 3]};
|
options = {serializers: [1, 2, 3]};
|
||||||
t.throws(function () { log.child(options); },
|
t.throws(function () { log.child(options); },
|
||||||
{
|
'invalid options.serializers: must be an object',
|
||||||
name: 'TypeError',
|
|
||||||
message: 'invalid options.serializers: must be an object'
|
|
||||||
},
|
|
||||||
'"serializers" cannot be an array');
|
'"serializers" cannot be an array');
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
|
@ -4,9 +4,17 @@
|
||||||
* Make sure cycles are safe.
|
* Make sure cycles are safe.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var Logger = require('../lib/bunyan.js');
|
var Logger = require('../lib/bunyan.js');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
var Stream = require('stream').Stream;
|
var Stream = require('stream').Stream;
|
||||||
var outstr = new Stream;
|
var outstr = new Stream;
|
||||||
outstr.writable = true;
|
outstr.writable = true;
|
||||||
|
@ -61,7 +69,13 @@ var log = new Logger({
|
||||||
test('cycles', function (t) {
|
test('cycles', function (t) {
|
||||||
outstr.on('end', function () {
|
outstr.on('end', function () {
|
||||||
output.forEach(function (o, i) {
|
output.forEach(function (o, i) {
|
||||||
t.has(o, expect[i], 'log item ' + i + ' matches');
|
// Drop variable parts for comparison.
|
||||||
|
delete o.hostname;
|
||||||
|
delete o.pid;
|
||||||
|
delete o.time;
|
||||||
|
// Hack object/dict comparison: JSONify.
|
||||||
|
t.equal(JSON.stringify(o), JSON.stringify(expect[i]),
|
||||||
|
'log item ' + i + ' matches');
|
||||||
});
|
});
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
@ -72,5 +86,5 @@ test('cycles', function (t) {
|
||||||
log.info('kaboom', obj.KABOOM);
|
log.info('kaboom', obj.KABOOM);
|
||||||
log.info(obj);
|
log.info(obj);
|
||||||
outstr.end();
|
outstr.end();
|
||||||
t.pass('did not throw');
|
t.ok('did not throw');
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,9 +7,16 @@
|
||||||
var spawn = require('child_process').spawn;
|
var spawn = require('child_process').spawn;
|
||||||
var format = require('util').format;
|
var format = require('util').format;
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var bunyan = require('../lib/bunyan');
|
var bunyan = require('../lib/bunyan');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
// Determine if we can run the dtrace tests.
|
// Determine if we can run the dtrace tests.
|
||||||
var dtracePlats = ['sunos', 'darwin', 'freebsd'];
|
var dtracePlats = ['sunos', 'darwin', 'freebsd'];
|
||||||
|
|
|
@ -5,13 +5,21 @@
|
||||||
* stream.
|
* stream.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
var bunyan = require('../lib/bunyan');
|
||||||
var Logger = require('../lib/bunyan');
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
test('error event on log write', function (t) {
|
test('error event on log write', function (t) {
|
||||||
LOG_PATH = '/this/path/is/bogus.log'
|
LOG_PATH = '/this/path/is/bogus.log'
|
||||||
var log = new Logger({name: 'error-event', streams: [{path: LOG_PATH}]});
|
var log = bunyan.createLogger(
|
||||||
t.plan(5);
|
{name: 'error-event', streams: [{path: LOG_PATH}]});
|
||||||
log.on('error', function (err, stream) {
|
log.on('error', function (err, stream) {
|
||||||
t.ok(err, 'got err in error event: ' + err);
|
t.ok(err, 'got err in error event: ' + err);
|
||||||
t.equal(err.code, 'ENOENT', 'error code is ENOENT');
|
t.equal(err.code, 'ENOENT', 'error code is ENOENT');
|
||||||
|
|
|
@ -4,10 +4,18 @@
|
||||||
* Test the `log.trace(...)`, `log.debug(...)`, ..., `log.fatal(...)` API.
|
* Test the `log.trace(...)`, `log.debug(...)`, ..., `log.fatal(...)` API.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
var bunyan = require('../lib/bunyan');
|
||||||
var Logger = require('../lib/bunyan');
|
|
||||||
|
|
||||||
var log1 = new Logger({
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
|
var log1 = bunyan.createLogger({
|
||||||
name: 'log1',
|
name: 'log1',
|
||||||
streams: [
|
streams: [
|
||||||
{
|
{
|
||||||
|
@ -17,7 +25,7 @@ var log1 = new Logger({
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
var log2 = new Logger({
|
var log2 = bunyan.createLogger({
|
||||||
name: 'log2',
|
name: 'log2',
|
||||||
streams: [
|
streams: [
|
||||||
{
|
{
|
||||||
|
@ -32,7 +40,7 @@ var log2 = new Logger({
|
||||||
})
|
})
|
||||||
|
|
||||||
test('log.LEVEL() -> boolean', function (t) {
|
test('log.LEVEL() -> boolean', function (t) {
|
||||||
t.equal(log1.trace(), false)
|
t.equal(log1.trace(), false, 'log1.trace() is false')
|
||||||
t.equal(log1.debug(), false)
|
t.equal(log1.debug(), false)
|
||||||
t.equal(log1.info(), true)
|
t.equal(log1.info(), true)
|
||||||
t.equal(log1.warn(), true)
|
t.equal(log1.warn(), true)
|
||||||
|
|
|
@ -4,9 +4,17 @@
|
||||||
* Test other parts of the exported API.
|
* Test other parts of the exported API.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var bunyan = require('../lib/bunyan');
|
var bunyan = require('../lib/bunyan');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
test('bunyan.<LEVEL>s', function (t) {
|
test('bunyan.<LEVEL>s', function (t) {
|
||||||
t.ok(bunyan.TRACE, 'TRACE');
|
t.ok(bunyan.TRACE, 'TRACE');
|
||||||
t.ok(bunyan.DEBUG, 'DEBUG');
|
t.ok(bunyan.DEBUG, 'DEBUG');
|
||||||
|
@ -32,4 +40,3 @@ test('bunyan.resolveLevel()', function (t) {
|
||||||
t.equal(bunyan.resolveLevel('FATAL'), bunyan.FATAL, 'FATAL');
|
t.equal(bunyan.resolveLevel('FATAL'), bunyan.FATAL, 'FATAL');
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var format = require('util').format;
|
var format = require('util').format;
|
||||||
var test = require('tap').test;
|
|
||||||
var Logger = require('../lib/bunyan');
|
var Logger = require('../lib/bunyan');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
function CapturingStream(recs) {
|
function CapturingStream(recs) {
|
||||||
|
|
|
@ -2,10 +2,18 @@
|
||||||
* Test the RingBuffer output stream.
|
* Test the RingBuffer output stream.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var Logger = require('../lib/bunyan');
|
var Logger = require('../lib/bunyan');
|
||||||
var ringbuffer = new Logger.RingBuffer({ 'limit': 5 });
|
var ringbuffer = new Logger.RingBuffer({ 'limit': 5 });
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
var log1 = new Logger({
|
var log1 = new Logger({
|
||||||
name: 'log1',
|
name: 'log1',
|
||||||
streams: [
|
streams: [
|
||||||
|
|
|
@ -4,12 +4,19 @@
|
||||||
* Test the standard serializers in Bunyan.
|
* Test the standard serializers in Bunyan.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var test = require('tap').test;
|
|
||||||
var http = require('http');
|
var http = require('http');
|
||||||
|
|
||||||
var bunyan = require('../lib/bunyan');
|
var bunyan = require('../lib/bunyan');
|
||||||
var verror = require('verror');
|
var verror = require('verror');
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
|
||||||
function CapturingStream(recs) {
|
function CapturingStream(recs) {
|
||||||
this.recs = recs;
|
this.recs = recs;
|
||||||
|
|
62
test/tap4nodeunit.js
Normal file
62
test/tap4nodeunit.js
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Mark Cavage. All rights reserved.
|
||||||
|
*
|
||||||
|
* Help nodeunit API feel like node-tap's.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* 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;
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//---- Exports
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
after: function after(teardown) {
|
||||||
|
module.parent.exports.tearDown = function _teardown(callback) {
|
||||||
|
try {
|
||||||
|
teardown.call(this, callback);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('after:\n' + e.stack);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
before: function before(setup) {
|
||||||
|
module.parent.exports.setUp = function _setup(callback) {
|
||||||
|
try {
|
||||||
|
setup.call(this, callback);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('before:\n' + e.stack);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
test: function test(name, tester) {
|
||||||
|
module.parent.exports[name] = function _(t) {
|
||||||
|
var _done = false;
|
||||||
|
t.end = function end() {
|
||||||
|
if (!_done) {
|
||||||
|
_done = true;
|
||||||
|
t.done();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
t.notOk = function notOk(ok, message) {
|
||||||
|
return (t.ok(!ok, message));
|
||||||
|
};
|
||||||
|
t.error = t.ifError;
|
||||||
|
|
||||||
|
tester.call(this, t);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in a new issue