github.com/cloudcredo/cloudrocker@v0.0.0-20160108110610-1320f8cc2dfd/sample-apps/node/node_modules/logfmt/test/stream_parser_test.js (about)

     1  var logfmt = require('../logfmt'),
     2      through = require('through'),
     3      stream = require('stream'),
     4      assert = require('assert');
     5  
     6  //avoid test bleeding
     7  var logfmt = new logfmt;
     8  
     9  suite('logfmt.streamParser', function() {
    10    test("parses all the lines", function(done){
    11      var s = new stream.Readable;
    12      s._read = function(){};
    13      s.push('hello=kitty\n');
    14      s.push('foo=bar\n');
    15      s.push('path=/\n');
    16      s.push(null);
    17  
    18      var matches = [{path: '/'}, {foo: 'bar'}, {hello: 'kitty'}];
    19      s.pipe(logfmt.streamParser()).pipe(through(function(data){
    20        assert.deepEqual(data, matches.pop())
    21      },function(){
    22        done()
    23      }))
    24    })
    25  
    26    // is this the desired behavior?
    27    test("handles empty data", function(done){
    28      var s = new stream.Readable;
    29      s._read = function(){};
    30      s.push('');
    31      s.push(null);
    32  
    33      s.pipe(logfmt.streamParser()).pipe(through(function(data){
    34        assert.deepEqual({}, data);
    35      },function(){
    36        done()
    37      }))
    38    })
    39  
    40    // is this the desired behavior?
    41    test("handles empty lines", function(done){
    42      var s = new stream.Readable;
    43      s._read = function(){};
    44      s.push("   \n");
    45      s.push(null);
    46  
    47      s.pipe(logfmt.streamParser()).pipe(through(function(data){
    48        assert.deepEqual({}, data);
    49      },function(){
    50        done()
    51      }))
    52    })
    53  })