Browse Source

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 <info@bnoordhuis.nl>
v4.0.0-rc
Brendan Ashworth 10 years ago
committed by Rod Vagg
parent
commit
2965442308
  1. 1
      lib/_http_agent.js
  2. 32
      test/parallel/test-http-agent-getname.js
  3. 2
      test/parallel/test-http-agent-keepalive.js

1
lib/_http_agent.js

@ -107,7 +107,6 @@ Agent.prototype.getName = function(options) {
name += ':';
if (options.localAddress)
name += options.localAddress;
name += ':';
return name;
};

32
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'
);

2
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');

Loading…
Cancel
Save