Skip to content

Commit

Permalink
First approach to tests with hock.
Browse files Browse the repository at this point in the history
  • Loading branch information
pose committed Nov 11, 2014
1 parent 4134288 commit 514bd45
Showing 2 changed files with 87 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
"colors": "0.6.x",
"cycle": "1.0.x",
"eyes": "0.1.x",
"hock": "^1.0.0",
"isstream": "0.1.x",
"pkginfo": "0.3.x",
"stack-trace": "0.0.x"
86 changes: 86 additions & 0 deletions test/transports/http-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* http-test.js: Tests for instances of the HTTP transport
*
* MIT LICENSE
*/

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

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

// TODO way of doing describe.only in vows?
// TODO How to debug a test?
// TODO Coverage tool

var host = '127.0.0.1';
var port = 1337;


vows.describe('winston/transports/http').addBatch({
"A valid instance of the HTTP Transport": {
topic: new (winston.transports.Http)({
host: host,
port: port,
path: 'log'
}),
"log method": {
// "when called with (undefined)": {
// topic: function (httpTransport) {
// var self = this;
// var scope = hock('http://foo')
// .post('log', {
// "method":"collect",
// "params":{
// "level":"info",
// "message":"hello",
// "meta":{}
// }
// })
// .reply(200);

// httpTr
// }
// },
"when logging in 'info' the string 'hello'": {
topic: function (httpTransport) {
var self = this;

var mock = hock.createHock();

mock
.post('log', {
"method":"collect",
"params":{
"level":"info",
"message":"hello",
"meta":{}
}
})
.reply(200);

var server = http.createServer(mock.handler);

server.listen(port, function (err) {
assert.ifError(err);
httpTransport.log('info', 'hello', function (err) {
assert.ifError(err);
self.callback(null, mock);
});
});
},
"should log to the specified URL": function (err, scope) {
assert.ifError(err);
scope.done();
hock.cleanAll();
}
}
}
}
}).export(module);

0 comments on commit 514bd45

Please sign in to comment.