Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[test] add querying and streaming tests.

  • Loading branch information...
commit 06435c481ca39f0bb31daa71d1331845cfb53326 1 parent 7afd56e
@chjj chjj authored
Showing with 86 additions and 12 deletions.
  1. +86 −12 test/winston-nssocket-test.js
View
98 test/winston-nssocket-test.js
@@ -1,24 +1,98 @@
+/**
+ * winston-nssocket tests
+ */
+
var assert = require('assert'),
vows = require('vows'),
winston = require('winston'),
nssocket = require('nssocket'),
macros = require('./helpers/macros'),
- ns = require('../');
+ ns = require('../'),
+ winstond = require('winstond');
+
+//
+// winstond nssocket server
+//
+
+var server = winstond.nssocket.createServer({
+ services: ['collect', 'query', 'stream'],
+ port: 1234
+});
+
+server.add(winstond.transports.File, {
+ filename: __dirname + '/test.log'
+});
+
+server.listen();
+
+//
+// winston logger
+//
+
+var logger = new winston.Logger({
+ transports: [
+ new ns.Nssocket({ host: 'localhost', port: 1234 })
+ ]
+});
+
+//
+// tests
+//
vows.describe('winston-nssocket').addBatch({
'When using `winston-nssocket`': {
- topic: function () {
- var logger = new winston.Logger({
- transports: [
- new ns.NsSocket({ host: '127.0.0.1', port: 1234 })
- ]
- });
-
- nssocket.createServer(this.callback.bind(this, null, logger)).listen(1234);
+ 'topic': logger,
+ 'the log() method': {
+ 'topic': function() {
+ logger.log('info', 'hello world', {}, this.callback);
+ },
+ 'should respond with true': function (err, logged) {
+ assert.isNull(err);
+ assert.isNotNull(logged);
+ }
+ },
+ 'the query() method': {
+ 'topic': function (logger) {
+ var cb = this.callback;
+ logger.log('info', 'hello world', {});
+ setTimeout(function () {
+ logger.query({}, cb);
+ }, 1000);
+ },
+ 'should return matching results': function (err, results) {
+ results = results.nssocket.file;
+ var log = results.pop();
+ assert.ok(log.message.indexOf('hello world') === 0
+ || log.message.indexOf('test message') === 0);
+ }
},
- 'it should send logs to `nssocket` server': {
- 'with no meta': macros.log('info', 'hello world!'),
- 'with meta': macros.log('error', 'hello world!', { chill: 'winston!' })
+ 'the stream() method': {
+ 'topic': function () {
+ logger.log('info', 'hello world', {});
+
+ var cb = this.callback,
+ j = 10,
+ i = 10,
+ results = [],
+ stream = logger.stream({});
+
+ stream.on('log', function (log) {
+ results.push(log);
+ results.stream = stream;
+ if (!--j) cb(null, results);
+ });
+
+ stream.on('error', function () {});
+
+ while (i--) logger.log('info', 'hello world ' + i, {});
+ },
+ 'should stream logs': function (err, results) {
+ results.forEach(function (log) {
+ assert.ok(log.message.indexOf('hello world') === 0
+ || log.message.indexOf('test message') === 0);
+ });
+ results.stream.destroy();
+ }
}
}
}).export(module);
Please sign in to comment.
Something went wrong with that request. Please try again.