Skip to content

Commit

Permalink
failing url rewriting test
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Jan 15, 2012
1 parent e3a0d68 commit ffa77ae
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/bounce_url.js
@@ -0,0 +1,50 @@
var test = require('tap').test;
var http = require('http');
var bouncy = require('../');

test('bounce url', function (t) {
t.plan(4);

var p0 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
var s0 = http.createServer(function (req, res) {
t.equal(req.url, '/rewritten');
res.setHeader('content-type', 'text/plain');
res.write('beep boop');
res.end();
});
s0.listen(p0, connect);

var p1 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
var s1 = bouncy(function (req, bounce) {
bounce({ port : p0, path : '/rewritten' });
});
s1.listen(p1, connect);

var connected = 0;
function connect () {
if (++connected !== 2) return;
var opts = {
method : 'GET',
host : 'localhost',
port : p1,
path : '/beep'
};
var req = http.request(opts, function (res) {
t.equal(res.statusCode, 200)
t.equal(res.headers['content-type'], 'text/plain');

var data = '';
res.on('data', function (buf) {
data += buf.toString();
});

res.on('end', function () {
t.equal(data, 'beep boop');
s0.close();
s1.close();
t.end();
});
});
req.end();
}
});

0 comments on commit ffa77ae

Please sign in to comment.