mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
test: added net.connect lookup type check
Check the options passed to Socket.prototype.connect() to validate the type of the lookup property. PR-URL: https://github.com/nodejs/node/pull/11873 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
34
test/parallel/test-net-options-lookup.js
Normal file
34
test/parallel/test-net-options-lookup.js
Normal file
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
const net = require('net');
|
||||
|
||||
const expectedError = /^TypeError: "lookup" option should be a function$/;
|
||||
|
||||
['foobar', 1, {}, []].forEach((input) => connectThrows(input));
|
||||
|
||||
function connectThrows(input) {
|
||||
const opts = {
|
||||
host: 'localhost',
|
||||
port: common.PORT,
|
||||
lookup: input
|
||||
};
|
||||
|
||||
assert.throws(function() {
|
||||
net.connect(opts);
|
||||
}, expectedError);
|
||||
}
|
||||
|
||||
[() => {}].forEach((input) => connectDoesNotThrow(input));
|
||||
|
||||
function connectDoesNotThrow(input) {
|
||||
const opts = {
|
||||
host: 'localhost',
|
||||
port: common.PORT,
|
||||
lookup: input
|
||||
};
|
||||
|
||||
assert.doesNotThrow(function() {
|
||||
net.connect(opts);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user