From 31d0d5af8e30362bb46a177afa4d74c2474c8e46 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Fri, 12 Apr 2013 16:16:18 +0200 Subject: [PATCH] test: add extra checks --- test/simple/test-http-client-escape-path.js | 51 ++++++++++++++------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/test/simple/test-http-client-escape-path.js b/test/simple/test-http-client-escape-path.js index d4203c5f69..0178c823ba 100644 --- a/test/simple/test-http-client-escape-path.js +++ b/test/simple/test-http-client-escape-path.js @@ -22,6 +22,7 @@ var common = require('../common'); var assert = require('assert'); var http = require('http'); +var util = require('util'); first(); @@ -37,22 +38,38 @@ function third() { } function test(path, expected, next) { - var server = http.createServer(function(req, res) { - assert.equal(req.url, expected); - res.end('OK'); - server.close(function() { - if (next) next(); + function helper(arg, next) { + var server = http.createServer(function(req, res) { + assert.equal(req.url, expected); + res.end('OK'); + server.close(next); }); - }); - server.on('clientError', function(err) { - throw err; - }); - var options = { - host: '127.0.0.1', - port: common.PORT, - path: path - }; - server.listen(options.port, options.host, function() { - http.get(options); - }); + server.on('clientError', function(err) { + throw err; + }); + server.listen(common.PORT, '127.0.0.1', function() { + http.get(arg); + }); + } + + // Go the extra mile to ensure that the behavior of + // http.get("http://example.com/...") matches http.get({ path: ... }). + test1(); + + function test1() { + console.log('as url: ' + util.inspect(path)); + helper('http://127.0.0.1:' + common.PORT + path, test2); + } + function test2() { + var options = { + host: '127.0.0.1', + port: common.PORT, + path: path + }; + console.log('as options: ' + util.inspect(options)); + helper(options, done); + } + function done() { + if (next) next(); + } }