GT2/GT2-iOS/node_modules/logfmt/test/stream_parser_test.js

54 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-02-12 17:26:06 +00:00
var logfmt = require('../logfmt'),
through = require('through'),
stream = require('stream'),
assert = require('assert');
//avoid test bleeding
var logfmt = new logfmt;
suite('logfmt.streamParser', function() {
test("parses all the lines", function(done){
var s = new stream.Readable;
s._read = function(){};
s.push('hello=kitty\n');
s.push('foo=bar\n');
s.push('path=/\n');
s.push(null);
var matches = [{path: '/'}, {foo: 'bar'}, {hello: 'kitty'}];
s.pipe(logfmt.streamParser()).pipe(through(function(data){
assert.deepEqual(data, matches.pop())
},function(){
done()
}))
})
// is this the desired behavior?
test("handles empty data", function(done){
var s = new stream.Readable;
s._read = function(){};
s.push('');
s.push(null);
s.pipe(logfmt.streamParser()).pipe(through(function(data){
assert.deepEqual({}, data);
},function(){
done()
}))
})
// is this the desired behavior?
test("handles empty lines", function(done){
var s = new stream.Readable;
s._read = function(){};
s.push(" \n");
s.push(null);
s.pipe(logfmt.streamParser()).pipe(through(function(data){
assert.deepEqual({}, data);
},function(){
done()
}))
})
})