node/test/parallel/test-dns-default-order-verbatim.js
Luigi Pinca 123982d11d
dns: honor the order option
Fixes: https://github.com/nodejs/node/issues/55391
PR-URL: https://github.com/nodejs/node/pull/55392
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Tim Perry <pimterry@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Feng Yu <F3n67u@outlook.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
2024-10-17 13:18:28 +00:00

60 lines
1.7 KiB
JavaScript

// Flags: --expose-internals --dns-result-order=verbatim
'use strict';
const common = require('../common');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const cares = internalBinding('cares_wrap');
const { promisify } = require('util');
// Test that --dns-result-order=verbatim works as expected.
const originalGetaddrinfo = cares.getaddrinfo;
const calls = [];
cares.getaddrinfo = common.mustCallAtLeast((...args) => {
calls.push(args);
originalGetaddrinfo(...args);
}, 1);
const dns = require('dns');
const dnsPromises = dns.promises;
// We want to test the parameter of verbatim only so that we
// ignore possible errors here.
function allowFailed(fn) {
return fn.catch((_err) => {
//
});
}
(async () => {
let callsLength = 0;
const checkParameter = (expected) => {
assert.strictEqual(calls.length, callsLength + 1);
const order = calls[callsLength][4];
assert.strictEqual(order, expected);
callsLength += 1;
};
await allowFailed(promisify(dns.lookup)('example.org'));
checkParameter(cares.DNS_ORDER_VERBATIM);
await allowFailed(dnsPromises.lookup('example.org'));
checkParameter(cares.DNS_ORDER_VERBATIM);
await allowFailed(promisify(dns.lookup)('example.org', {}));
checkParameter(cares.DNS_ORDER_VERBATIM);
await allowFailed(dnsPromises.lookup('example.org', {}));
checkParameter(cares.DNS_ORDER_VERBATIM);
await allowFailed(
promisify(dns.lookup)('example.org', { order: 'ipv4first' })
);
checkParameter(cares.DNS_ORDER_IPV4_FIRST);
await allowFailed(
promisify(dns.lookup)('example.org', { order: 'ipv6first' })
);
checkParameter(cares.DNS_ORDER_IPV6_FIRST);
})().then(common.mustCall());