test: refactor test-net-dns-error
- Use `common.mustCall()` and `common.mustNotCall()`. - Use ternary operator. PR-URL: https://github.com/nodejs/node/pull/19640 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
a34f1e3245
commit
37db277bb4
@ -21,27 +21,20 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
const net = require('net');
|
const net = require('net');
|
||||||
|
|
||||||
const host = '*'.repeat(256);
|
const host = '*'.repeat(256);
|
||||||
|
const errCode = common.isOpenBSD ? 'EAI_FAIL' : 'ENOTFOUND';
|
||||||
|
|
||||||
let errCode = 'ENOTFOUND';
|
const socket = net.connect(42, host, common.mustNotCall());
|
||||||
if (common.isOpenBSD)
|
|
||||||
errCode = 'EAI_FAIL';
|
|
||||||
|
|
||||||
function do_not_call() {
|
|
||||||
throw new Error('This function should not have been called.');
|
|
||||||
}
|
|
||||||
|
|
||||||
const socket = net.connect(42, host, do_not_call);
|
|
||||||
socket.on('error', common.mustCall(function(err) {
|
socket.on('error', common.mustCall(function(err) {
|
||||||
assert.strictEqual(err.code, errCode);
|
assert.strictEqual(err.code, errCode);
|
||||||
}));
|
}));
|
||||||
socket.on('lookup', function(err, ip, type) {
|
socket.on('lookup', common.mustCall(function(err, ip, type) {
|
||||||
assert(err instanceof Error);
|
assert(err instanceof Error);
|
||||||
assert.strictEqual(err.code, errCode);
|
assert.strictEqual(err.code, errCode);
|
||||||
assert.strictEqual(ip, undefined);
|
assert.strictEqual(ip, undefined);
|
||||||
assert.strictEqual(type, undefined);
|
assert.strictEqual(type, undefined);
|
||||||
});
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user