Permalink
Browse files

full-stack single bounce test

  • Loading branch information...
1 parent 8378c25 commit 473c0a4affc14f5e05bf47d37168d88b5f6d7850 @substack committed Oct 10, 2011
Showing with 49 additions and 0 deletions.
  1. +49 −0 test/bounce.js
View
@@ -0,0 +1,49 @@
+var test = require('tap').test;
+var http = require('http');
+var net = require('net');
+var bouncy = require('../');
+
+test('bounce', function (t) {
+ var p0 = Math.floor(Math.random() * (Math.pow(2,16) - 1e4) + 1e4);
+ var s0 = http.createServer(function (req, res) {
+ 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) {
+ var stream = net.createConnection(p0);
+ bounce(stream);
+ });
+ 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 473c0a4

Please sign in to comment.