Skip to content

Commit

Permalink
[test] Updates for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Aug 28, 2011
1 parent 1389b70 commit db10c4a
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ TestRunner.prototype.assertProxied = function (host, proxyPort, port, createProx

var test = {
topic: function () {
var that = this, options = {
var that = this,
options;

options = {
method: 'GET',
uri: self.protocol + ':https://localhost:' + proxyPort,
headers: {
Expand Down Expand Up @@ -172,9 +175,9 @@ TestRunner.prototype.webSocketTestWithTable = function (options) {
options.onListen(socket);
}

self.startProxyServerWithTable(
options.ports.proxy,
{router: options.router},
self.startProxyServerWithTable(
options.ports.proxy,
{ router: options.router },
function (err, proxy) {
if (options.onServer) { options.onServer(proxy) }

Expand Down Expand Up @@ -213,7 +216,10 @@ TestRunner.prototype.startProxyServer = function (port, targetPort, host, callba
//
TestRunner.prototype.startLatentProxyServer = function (port, targetPort, host, latency, callback) {
// Initialize the nodeProxy and start proxying the request
var that = this, proxyServer = httpProxy.createServer(function (req, res, proxy) {
var that = this,
proxyServer;

proxyServer = httpProxy.createServer(function (req, res, proxy) {
var buffer = proxy.buffer(req);

setTimeout(function () {
Expand All @@ -235,7 +241,9 @@ TestRunner.prototype.startLatentProxyServer = function (port, targetPort, host,
// Creates the reverse proxy server with a ProxyTable
//
TestRunner.prototype.startProxyServerWithTable = function (port, options, callback) {
var that = this, proxyServer = httpProxy.createServer(merge({}, options, this.options));
var that = this,
proxyServer = httpProxy.createServer(merge({}, options, this.options));

proxyServer.listen(port, function () {
that.testServers.push(proxyServer);
callback();
Expand All @@ -248,10 +256,12 @@ TestRunner.prototype.startProxyServerWithTable = function (port, options, callba
// Creates a latent reverse proxy server using a ProxyTable
//
TestRunner.prototype.startProxyServerWithTableAndLatency = function (port, latency, options, callback) {
//
// Initialize the nodeProxy and start proxying the request
var proxyServer,
that = this,
proxy = new httpProxy.HttpProxy(merge({}, options, that.options));
//
var that = this,
proxy = new httpProxy.HttpProxy(merge({}, options, that.options)),
proxyServer;

var handler = function (req, res) {
var buffer = proxy.buffer(req);
Expand All @@ -263,8 +273,8 @@ TestRunner.prototype.startProxyServerWithTableAndLatency = function (port, laten
};

proxyServer = that.options.https
? https.createServer(that.options.https, handler, that.options)
: http.createServer(handler, that.options);
? https.createServer(that.options.https, handler, that.options)
: http.createServer(handler, that.options);

proxyServer.listen(port, function () {
that.testServers.push(proxyServer);
Expand All @@ -278,7 +288,9 @@ TestRunner.prototype.startProxyServerWithTableAndLatency = function (port, laten
// Creates proxy server forwarding to the specified options
//
TestRunner.prototype.startProxyServerWithForwarding = function (port, targetPort, host, options, callback) {
var that = this, proxyServer = httpProxy.createServer(targetPort, host, merge({}, options, this.options));
var that = this,
proxyServer = httpProxy.createServer(targetPort, host, merge({}, options, this.options));

proxyServer.listen(port, function () {
that.testServers.push(proxyServer);
callback(null, proxyServer);
Expand All @@ -289,7 +301,11 @@ TestRunner.prototype.startProxyServerWithForwarding = function (port, targetPort
// Creates the 'hellonode' server
//
TestRunner.prototype.startTargetServer = function (port, output, callback) {
var that = this, targetServer, handler = function (req, res) {
var that = this,
targetServer,
handler;

handler = function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write(output);
res.end();
Expand Down

0 comments on commit db10c4a

Please sign in to comment.