Skip to content

Commit

Permalink
[test] add tests for streaming/querying.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed May 3, 2012
1 parent 7bfd5b8 commit e7ba14c
Show file tree
Hide file tree
Showing 8 changed files with 362 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -19,8 +19,8 @@
"loggly": "0.3.x >=0.3.7",
"pkginfo": "0.2.x",
"stack-trace": "0.0.x",
"redis": ">=0.7.1",
"request": ">=2.9.202"
"redis": "0.7.x",
"cradle": "0.6.x"
},
"devDependencies": {
"vows": "0.6.x"
Expand Down
17 changes: 12 additions & 5 deletions test/logger-test.js
Expand Up @@ -10,7 +10,8 @@ var path = require('path'),
vows = require('vows'),
assert = require('assert'),
winston = require('../lib/winston'),
helpers = require('./helpers');
helpers = require('./helpers'),
transport = require('./transports/transport');

vows.describe('winton/logger').addBatch({
"An instance of winston.Logger": {
Expand Down Expand Up @@ -197,7 +198,10 @@ vows.describe('winton/logger').addBatch({
}
}
}).addBatch({
"The winston logger": {
"The winston logger": transport(winston.transport.File, {
filename: path.join(__dirname, 'fixtures', 'logs', 'filelog.log')
}),
"The winston logger_": {
topic: new (winston.Logger)({
transports: [
new (winston.transports.File)({
Expand All @@ -207,11 +211,14 @@ vows.describe('winton/logger').addBatch({
}),
"the query() method": {
topic: function(logger) {
logger.log('info', 'hello world', {});
logger.query({}, this.callback);
var cb = this.callback;
logger.log('info', 'hello world', {}, function() {
logger.query({}, cb);
});
},
"should return matching results": function (err, results, logger) {
assert.equal(results.file.pop().message, 'hello world');
results = results.file;
assert.equal(results.pop().message, 'hello world');
}
},
"the stream() method": {
Expand Down
96 changes: 96 additions & 0 deletions test/transports/couchdb-stream-query.js
@@ -0,0 +1,96 @@
/*
* couchdb-test.js: Tests for instances of the Couchdb transport
*
* (C) 2011 Max Ogden
* MIT LICENSE
*
*/

var path = require('path'),
vows = require('vows'),
fs = require('fs'),
http = require('http'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers'),
request = require('request');

var transport = require('./transport');

request('http://localhost:5984/logs', function(err, res) {
if (!err && res.statusCode !== 404) test();
});

function test() {
var couchdbTransport = new winston.transports.Couchdb({
host: 'localhost',
port: 5984,
db: 'logs'
});

vows.describe('winston/transports/couchdb').addBatch({
"An instance of the Couchdb Transport": {
"when passed valid options": {
"should have the proper methods defined": function () {
helpers.assertCouchdb(couchdbTransport);
},
"the log() method": helpers.testNpmLevels(couchdbTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).addBatch({
/*
"The winston logger": {
topic: new winston.Logger({
transports: [
new winston.transports.Couchdb({
host: 'localhost',
port: 5984,
db: 'logs'
})
]
}),
"the query() method": {
topic: function(logger) {
var cb = this.callback;
logger.log('info', 'hello world', {}, function() {
logger.query({}, cb);
});
},
"should return matching results": function (err, results, logger) {
results = results.Couchdb || results.couchdb;
assert.equal(results.pop().message.indexOf('hello world'), 0);
}
},
"the stream() method": {
topic: function(logger) {
var cb = this.callback;
var j = 10;
var i = 10;
var results = [];
logger.log('info', 'hello world', {});
var stream = logger.stream({});
stream.on('log', function(log) {
results.push(log);
results.stream = stream;
if (!--j) cb(results);
});
while (i--) logger.log('info', 'hello world ' + i, {});
},
"should stream logs": function (results, logger) {
results.forEach(function(log) {
assert.ok(log.message.indexOf('hello world') === 0
|| log.message.indexOf('test message') === 0);
});
results.stream.destroy();
}
}
}
*/
}).export(module);
}
101 changes: 101 additions & 0 deletions test/transports/couchdb-stream-query.js_
@@ -0,0 +1,101 @@
/*
* couchdb-test.js: Tests for instances of the Couchdb transport
*
* (C) 2011 Max Ogden
* MIT LICENSE
*
*/

var path = require('path'),
vows = require('vows'),
fs = require('fs'),
http = require('http'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers'),
request = require('request');

var transport = require('./transport');

request('http://localhost:5984/logs', function(err, res) {
if (!err && res.statusCode !== 404) test();
});

function test() {
var couchdbTransport = new winston.transports.Couchdb({
host: 'localhost',
port: 5984,
db: 'logs'
});

vows.describe('winston/transports/couchdb').addBatch({
"An instance of the Couchdb Transport": {
"when passed valid options": {
"should have the proper methods defined": function () {
helpers.assertCouchdb(couchdbTransport);
},
"the log() method": helpers.testNpmLevels(couchdbTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
}
}
}).addBatch({
/*
"The winston logger": {
topic: new winston.Logger({
transports: [
new winston.transports.Couchdb({
host: 'localhost',
port: 5984,
db: 'logs'
})
]
}),
"the query() method": {
topic: function(logger) {
var cb = this.callback;
logger.log('info', 'hello world', {}, function() {
logger.query({}, cb);
});
},
"should return matching results": function (err, results, logger) {
results = results.Couchdb || results.couchdb;
assert.equal(results.pop().message.indexOf('hello world'), 0);
}
},
"the stream() method": {
topic: function(logger) {
var cb = this.callback;
var j = 10;
var i = 10;
var results = [];

logger.log('info', 'hello world', {});

var stream = logger.stream({});
stream.on('log', function(log) {
results.push(log);
results.stream = stream;
if (!--j) cb(results);
});

while (i--) logger.log('info', 'hello world ' + i, {});
},
"should stream logs": function (results, logger) {
results.forEach(function(log) {
assert.ok(log.message.indexOf('hello world') === 0
|| log.message.indexOf('test message') === 0);
});
results.stream.destroy();
}
}
}
*/
"The Couchdb transport": streamQueryTest(winston.transports.Couchdb, {
host: 'localhost',
port: 5984,
db: 'logs'
})
}).export(module);
}
26 changes: 20 additions & 6 deletions test/transports/couchdb-test.js
Expand Up @@ -14,7 +14,10 @@ var path = require('path'),
winston = require('../../lib/winston'),
helpers = require('../helpers');

var couchdbTransport = new (winston.transports.Couchdb)({
var transport = require('./transport');

if (0) {
var couchdbTransport = new (winston.transports.Couchdb)({
"host": "localhost",
"port": 4567,
"db": "logs"
Expand All @@ -32,10 +35,12 @@ vows.describe('winston/transports/couchdb').addBatch({
"should have the proper methods defined": function () {
helpers.assertCouchdb(couchdbTransport);
},
"the log() method": helpers.testNpmLevels(couchdbTransport, "should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
})
"the log() method": helpers.testNpmLevels(couchdbTransport,
"should respond with true", function (ign, err, logged) {
assert.isNull(err);
assert.isTrue(logged);
}
)
}
}
}).addBatch({
Expand All @@ -44,4 +49,13 @@ vows.describe('winston/transports/couchdb').addBatch({
server.close();
}
}
}).export(module);
}).export(module);
} else {
vows.describe('winston/transports/couchdb').addBatch({
"An instance of the Couchdb Transport": transport(winston.transports.Couchdb, {
host: 'localhost',
port: 5984,
db: 'logs'
})
}).export(module);
}
16 changes: 13 additions & 3 deletions test/transports/file-test.js
Expand Up @@ -13,8 +13,14 @@ var path = require('path'),
winston = require('../../lib/winston'),
helpers = require('../helpers');

var stream = fs.createWriteStream(path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log')),
fileTransport = new (winston.transports.File)({ filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfilename.log') }),
var transport = require('./transport');

var stream = fs.createWriteStream(
path.join(__dirname, '..', 'fixtures', 'logs', 'testfile.log')
),
fileTransport = new (winston.transports.File)({
filename: path.join(__dirname, '..', 'fixtures', 'logs', 'testfilename.log')
}),
streamTransport = new (winston.transports.File)({ stream: stream });

vows.describe('winston/transports/file').addBatch({
Expand Down Expand Up @@ -47,4 +53,8 @@ vows.describe('winston/transports/file').addBatch({
assert.isTrue(true);
}
}
}).export(module);
}).addBatch({
"An instance of the File Transport": transport(winston.transports.File, {
filename: path.join(__dirname, 'fixtures', 'logs', 'filelog.log')
})
}).export(module);
24 changes: 24 additions & 0 deletions test/transports/redis-test.js
@@ -0,0 +1,24 @@
/*
* couchdb-test.js: Tests for instances of the Couchdb transport
*
* (C) 2011 Max Ogden
* MIT LICENSE
*
*/

var path = require('path'),
vows = require('vows'),
fs = require('fs'),
http = require('http'),
assert = require('assert'),
winston = require('../../lib/winston'),
helpers = require('../helpers');

var transport = require('./transport');

vows.describe('winston/transports/redis').addBatch({
"An instance of the Couchdb Transport": transport(winston.transports.Redis, {
host: 'localhost',
port: 6379
})
}).export(module);

0 comments on commit e7ba14c

Please sign in to comment.