From cedc5c4bd2059585e1222ec4f03f09e8bcc808fc Mon Sep 17 00:00:00 2001 From: yawnt Date: Fri, 9 Aug 2013 19:13:44 +0200 Subject: [PATCH] [tests] add more tests --- lib/caronte/streams/forward.js | 12 +++++++----- package.json | 2 +- test/lib-caronte-common-test.js | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 test/lib-caronte-common-test.js diff --git a/lib/caronte/streams/forward.js b/lib/caronte/streams/forward.js index 7ab802864..b7e8ccd03 100644 --- a/lib/caronte/streams/forward.js +++ b/lib/caronte/streams/forward.js @@ -21,12 +21,16 @@ module.exports = ForwardStream; */ function ForwardStream() { + var self = this; + Writable.call(this); - this.once('pipe', this.onPipe); - this.once('finish', this.onFinish); + this.once('pipe', function() { self.onPipe() }); + this.once('finish', function() { self.onFinish() }); } +require('util').inherits(ForwardStream, Writable); + /** * Fires up the request to the external target * @@ -74,6 +78,4 @@ ForwardStream.prototype.onFinish = function() { ForwardStream.prototype._write = function(chunk, encoding, clb) { this.forwardReq.write(chunk, encoding, clb); -}; - -require('util').inherits(ForwardStream, Writable); \ No newline at end of file +}; \ No newline at end of file diff --git a/package.json b/package.json index 8cef91a7f..e2b3f25d1 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ }, "scripts" : { "blanket" : { "pattern": "caronte/lib" }, - "test" : "mocha -R spec test/*-test.js && npm run-script test-cov", + "test" : "mocha -R landing test/*-test.js", "test-cov" : "mocha --require blanket -R html-cov > cov/coverage.html" }, diff --git a/test/lib-caronte-common-test.js b/test/lib-caronte-common-test.js new file mode 100644 index 000000000..b489c9ff7 --- /dev/null +++ b/test/lib-caronte-common-test.js @@ -0,0 +1,33 @@ +var common = require('../lib/caronte/common'), + expect = require('expect.js'); + +describe('lib/caronte/common.js', function() { + describe('#setupOutgoing', function() { + it('should setup the right headers', function() { + var outgoing = {}; + common.setupOutgoing(outgoing, + { + host : 'hey', + hostname : 'how', + socketPath: 'are', + port : 'you', + agent : '?' + }, + { + method : 'i', + path : 'am', + headers : 'proxy' + }); + + expect(outgoing.host).to.eql('hey'); + expect(outgoing.hostname).to.eql('how'); + expect(outgoing.socketPath).to.eql('are'); + expect(outgoing.port).to.eql('you'); + expect(outgoing.agent).to.eql('?'); + + expect(outgoing.method).to.eql('i'); + expect(outgoing.path).to.eql('am'); + expect(outgoing.headers).to.eql('proxy') + }); + }); +}); \ No newline at end of file