forked from winstonjs/winston
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test] add tests for streaming/querying.
- Loading branch information
Showing
8 changed files
with
362 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
Oops, something went wrong.