Skip to content

Commit

Permalink
[test] testing the onResponse proxy method
Browse files Browse the repository at this point in the history
  • Loading branch information
cronopio committed Aug 28, 2013
1 parent abf1d90 commit 27df8d7
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions test/lib-caronte-streams-proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,20 @@ describe('lib/caronte/streams/proxy.js', function () {
});
});

describe('should pipe the request and finish it', function () {
describe('caronte createProxyServer() method', function () {
it('should make the request on pipe and finish it', function(done) {
var result;

var p = caronte.createProxyServer({
var proxy = caronte.createProxyServer({
target: 'http://127.0.0.1:8080'
}).listen('8081');

var s = http.createServer(function(req, res) {
var source = http.createServer(function(req, res) {
expect(req.headers['x-forwarded-for']).to.eql('127.0.0.1');
s.close();
p.close();
source.close();
proxy.close();
done();
});

s.listen('8080');
source.listen('8080');

http.request({
hostname: '127.0.0.1',
Expand All @@ -49,4 +47,38 @@ describe('lib/caronte/streams/proxy.js', function () {
}, function() {}).end();
});
});

describe('caronte createProxyServer() method with response', function () {
it('should make the request, handle response and finish it', function(done) {
var proxy = caronte.createProxyServer({
target: 'http://127.0.0.1:8080'
}).listen('8081');

var source = http.createServer(function(req, res) {
expect(req.method).to.eql('GET');
res.writeHead(200, {'Content-Type': 'text/plain'})
res.end('Hello from ' + source.address().port);
});

source.listen('8080');

http.request({
hostname: '127.0.0.1',
port: '8081',
method: 'GET',
}, function(res) {
expect(res.statusCode).to.eql(200);

res.on('data', function (data) {
expect(data.toString()).to.eql('Hello from 8080');
});

res.on('end', function () {
source.close();
proxy.close();
done();
});
}).end();
});
});
});

0 comments on commit 27df8d7

Please sign in to comment.