Skip to content

Commit

Permalink
test: refactor test-net-dns-error
Browse files Browse the repository at this point in the history
- Use `common.mustCall()` and `common.mustNotCall()`.
- Use ternary operator.

PR-URL: #19640
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
lpinca authored and targos committed Apr 2, 2018
1 parent 677b613 commit a89ba21
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions test/parallel/test-net-dns-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,20 @@

'use strict';
const common = require('../common');
const assert = require('assert');

const assert = require('assert');
const net = require('net');

const host = '*'.repeat(256);
const errCode = common.isOpenBSD ? 'EAI_FAIL' : 'ENOTFOUND';

let errCode = 'ENOTFOUND';
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);
const socket = net.connect(42, host, common.mustNotCall());
socket.on('error', common.mustCall(function(err) {
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.strictEqual(err.code, errCode);
assert.strictEqual(ip, undefined);
assert.strictEqual(type, undefined);
});
}));

0 comments on commit a89ba21

Please sign in to comment.