Skip to content

Commit c961279

Browse files
committed
[test] proxystream test
1 parent 8fc3389 commit c961279

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var caronte = require('../'),
55
http = require('http');
66

77

8-
describe('lib/caronte/passes/web.js', function () {
8+
describe('lib/caronte/streams/forward.js', function () {
99
describe('forward stream constructor', function () {
1010
it('should be an instance of Writable stream and get the correct options and methods', function () {
1111
var stubOptions = {

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

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var caronte = require('../'),
2+
ProxyStream = require('../lib/caronte/streams/proxy');
3+
expect = require('expect.js'),
4+
Duplex = require('stream').Duplex,
5+
http = require('http');
6+
7+
8+
describe('lib/caronte/streams/proxy.js', function () {
9+
describe('proxy stream constructor', function () {
10+
it('should be an instance of Duplex stream and get the correct options and methods', function () {
11+
var stubOptions = {
12+
key: 'value'
13+
};
14+
var proxyStream = new ProxyStream(stubOptions);
15+
16+
expect(proxyStream).to.be.a(Duplex);
17+
expect(proxyStream.options).to.eql({ key: 'value' });
18+
expect(proxyStream.onPipe).to.be.a('function');
19+
expect(proxyStream.onFinish).to.be.a('function');
20+
expect(proxyStream._events).to.have.property('pipe');
21+
expect(proxyStream._events).to.have.property('finish');
22+
});
23+
});
24+
25+
describe('should pipe the request and finish it', function () {
26+
it('should make the request on pipe and finish it', function(done) {
27+
var result;
28+
29+
var p = caronte.createProxyServer({
30+
target: 'http://127.0.0.1:8080'
31+
}).listen('8081');
32+
33+
var s = http.createServer(function(req, res) {
34+
expect(req.headers['x-forwarded-for']).to.eql('127.0.0.1');
35+
s.close();
36+
p.close();
37+
done();
38+
});
39+
40+
s.listen('8080');
41+
42+
http.request({
43+
hostname: '127.0.0.1',
44+
port: '8081',
45+
method: 'POST',
46+
headers: {
47+
'x-forwarded-for': '127.0.0.1'
48+
}
49+
}, function() {}).end();
50+
});
51+
});
52+
});

0 commit comments

Comments
 (0)