test: add test for internalConnect() when address type is IPv6

PR-URL: https://github.com/nodejs/node/pull/22444
Reviewed-By: Refael Ackermann <refack@gmail.com>
This commit is contained in:
Yaniv Friedensohn 2018-08-21 21:45:34 +03:00 committed by Anna Henningsen
parent 56cf058878
commit e03f9c55f2
No known key found for this signature in database
GPG Key ID: 9C63F3A6CD2AD8F9
2 changed files with 29 additions and 6 deletions

View File

@ -180,6 +180,10 @@ Object.defineProperty(exports, 'localhostIPv4', {
}
});
Object.defineProperty(exports, 'localhostIPv6', {
get: () => '::1'
});
// opensslCli defined lazily to reduce overhead of spawnSync
Object.defineProperty(exports, 'opensslCli', { get: function() {
if (opensslCli !== null) return opensslCli;

View File

@ -6,20 +6,39 @@ const net = require('net');
// EADDRINUSE is expected to occur on FreeBSD
// Ref: https://github.com/nodejs/node/issues/13055
const expectedErrorCodes = ['ECONNREFUSED', 'EADDRINUSE'];
const client = net.connect({
const optionsIPv4 = {
port: common.PORT,
localPort: common.PORT + 1,
localAddress: common.localhostIPv4
});
};
client.on('error', common.mustCall(function onError(err) {
const optionsIPv6 = {
host: common.localhostIPv6,
port: common.PORT + 2,
localPort: common.PORT + 3,
localAddress: common.localhostIPv6
};
function onError(err, options) {
assert.ok(expectedErrorCodes.includes(err.code));
assert.strictEqual(err.syscall, 'connect');
assert.strictEqual(err.localPort, common.PORT + 1);
assert.strictEqual(err.localAddress, common.localhostIPv4);
assert.strictEqual(err.localPort, options.localPort);
assert.strictEqual(err.localAddress, options.localAddress);
assert.strictEqual(
err.message,
`connect ${err.code} ${err.address}:${err.port} ` +
`- Local (${err.localAddress}:${err.localPort})`
);
}));
}
const clientIPv4 = net.connect(optionsIPv4);
clientIPv4.on('error', common.mustCall((err) => onError(err, optionsIPv4)));
if (!common.hasIPv6) {
common.printSkipMessage('ipv6 part of test, no IPv6 support');
return;
}
const clientIPv6 = net.connect(optionsIPv6);
clientIPv6.on('error', common.mustCall((err) => onError(err, optionsIPv6)));