From 2965442308ea72e76f2b982d0c1ee74304676d5a Mon Sep 17 00:00:00 2001 From: Brendan Ashworth Date: Mon, 4 May 2015 19:24:59 -0700 Subject: [PATCH] http: fix agent.getName() and add tests This commit fixes agent.getName(), which returned an extra colon according to the docs, and adds tests (it was previously not unit tested). PR-URL: https://github.com/nodejs/io.js/pull/1617 Reviewed-By: Ben Noordhuis --- lib/_http_agent.js | 1 - test/parallel/test-http-agent-getname.js | 32 ++++++++++++++++++++++ test/parallel/test-http-agent-keepalive.js | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-http-agent-getname.js diff --git a/lib/_http_agent.js b/lib/_http_agent.js index 9208044a94..1db331c3d1 100644 --- a/lib/_http_agent.js +++ b/lib/_http_agent.js @@ -107,7 +107,6 @@ Agent.prototype.getName = function(options) { name += ':'; if (options.localAddress) name += options.localAddress; - name += ':'; return name; }; diff --git a/test/parallel/test-http-agent-getname.js b/test/parallel/test-http-agent-getname.js new file mode 100644 index 0000000000..d8d30a8ddb --- /dev/null +++ b/test/parallel/test-http-agent-getname.js @@ -0,0 +1,32 @@ +'use strict'; + +var assert = require('assert'); +var http = require('http'); +var common = require('../common'); + +var agent = new http.Agent(); + +// default to localhost +assert.equal( + agent.getName({ + port: 80, + localAddress: '192.168.1.1' + }), + 'localhost:80:192.168.1.1' +); + +// empty +assert.equal( + agent.getName({}), + 'localhost::' +); + +// pass all arguments +assert.equal( + agent.getName({ + host: '0.0.0.0', + port: 80, + localAddress: '192.168.1.1' + }), + '0.0.0.0:80:192.168.1.1' +); diff --git a/test/parallel/test-http-agent-keepalive.js b/test/parallel/test-http-agent-keepalive.js index f82af380bc..ef9553c831 100644 --- a/test/parallel/test-http-agent-keepalive.js +++ b/test/parallel/test-http-agent-keepalive.js @@ -35,7 +35,7 @@ function get(path, callback) { }, callback); } -var name = 'localhost:' + common.PORT + '::'; +var name = 'localhost:' + common.PORT + ':'; function checkDataAndSockets(body) { assert.equal(body.toString(), 'hello world');