Skip to content

Commit f4e9945

Browse files
committed
Merge pull request #3 from yawnt/tests
Tests
2 parents d40e4be + 2fac7b9 commit f4e9945

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

Diff for: lib/caronte/streams/forward.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function ForwardStream(options) {
2424
var self = this;
2525

2626
self.options = options;
27-
self.res = res;
27+
// To uncomment the line below, please see
28+
// https://github.com/yawnt/caronte/commit/9ab8749a9bec33b49c495975e8364336ad7be1a3#commitcomment-3947117
29+
//self.res = res;
2830

2931
Writable.call(this);
3032

Diff for: test/lib-caronte-passes-web-test.js

+17
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,21 @@ describe('lib/caronte/passes/web.js', function() {
2525
expect(done).to.eql(5000);
2626
});
2727
});
28+
29+
describe('#XHeaders', function () {
30+
var stubRequest = {
31+
connection: {
32+
remoteAddress: '192.168.1.2',
33+
remotePort: '8080'
34+
},
35+
headers: {}
36+
}
37+
38+
it('set the correct x-forwarded-* headers', function () {
39+
caronte.XHeaders(stubRequest, {}, { xfwd: true });
40+
expect(stubRequest.headers['x-forwarded-for']).to.be('192.168.1.2');
41+
expect(stubRequest.headers['x-forwarded-port']).to.be('8080');
42+
expect(stubRequest.headers['x-forwarded-proto']).to.be('http');
43+
});
44+
});
2845
});

Diff for: test/lib-caronte-streams-forward-test.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var ForwardStream = require('../lib/caronte/streams/forward'),
2+
expect = require('expect.js'),
3+
Writable = require('stream').Writable,
4+
http = require('http');
5+
6+
7+
describe('lib/caronte/passes/web.js', function () {
8+
describe('forward stream constructor', function () {
9+
it('should be an instance of Writable stream and get the correct options and methods', function () {
10+
var stubOptions = {
11+
key: 'value'
12+
};
13+
var forwardProxy = new ForwardStream(stubOptions);
14+
15+
expect(forwardProxy).to.be.a(Writable);
16+
expect(forwardProxy.options).to.eql({ key: 'value' });
17+
expect(forwardProxy.onPipe).to.be.a('function');
18+
expect(forwardProxy.onFinish).to.be.a('function');
19+
expect(forwardProxy._events).to.have.property('pipe');
20+
expect(forwardProxy._events).to.have.property('finish');
21+
});
22+
});
23+
24+
describe('should pipe the request and finish it', function () {
25+
it('should make the request on pipe and finish it');
26+
var stubOptions = {
27+
target: {
28+
hostname : 'www.google.com',
29+
port : '80',
30+
path : '/'
31+
}
32+
};
33+
34+
var forwardProxy = new ForwardStream({});
35+
36+
});
37+
});

0 commit comments

Comments
 (0)