test: add extra checks

pull/5010/head
Ben Noordhuis 2013-04-12 16:16:18 +02:00 committed by isaacs
parent 38149bb048
commit 31d0d5af8e
1 changed files with 34 additions and 17 deletions

View File

@ -22,6 +22,7 @@
var common = require('../common'); var common = require('../common');
var assert = require('assert'); var assert = require('assert');
var http = require('http'); var http = require('http');
var util = require('util');
first(); first();
@ -37,22 +38,38 @@ function third() {
} }
function test(path, expected, next) { function test(path, expected, next) {
var server = http.createServer(function(req, res) { function helper(arg, next) {
assert.equal(req.url, expected); var server = http.createServer(function(req, res) {
res.end('OK'); assert.equal(req.url, expected);
server.close(function() { res.end('OK');
if (next) next(); server.close(next);
}); });
}); server.on('clientError', function(err) {
server.on('clientError', function(err) { throw err;
throw err; });
}); server.listen(common.PORT, '127.0.0.1', function() {
var options = { http.get(arg);
host: '127.0.0.1', });
port: common.PORT, }
path: path
}; // Go the extra mile to ensure that the behavior of
server.listen(options.port, options.host, function() { // http.get("http://example.com/...") matches http.get({ path: ... }).
http.get(options); 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();
}
} }