Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
test: add test for internalConnect() when address type is IPv6
  • Loading branch information
yanivfriedensohn committed Aug 21, 2018
commit ba908ba4df0a331f0a8730c3b313a9dfcc1f2ea6
4 changes: 4 additions & 0 deletions test/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,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;
Expand Down
31 changes: 25 additions & 6 deletions test/sequential/test-net-connect-local-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
};

const optionsIPv6 = {
host: common.localhostIPv6,
port: common.PORT + 2,
localPort: common.PORT + 3,
localAddress: common.localhostIPv6
};

client.on('error', common.mustCall(function onError(err) {
const onError = (err, options) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be a function declaration?

function onError(err, options) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a named function expression.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a style preference, function declaration are much more common in the test suite than named function expressions.

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