11cb0ef41Sopenharmony_ci// Flags: --expose-internals --dns-result-order=verbatim
21cb0ef41Sopenharmony_ci'use strict';
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst { internalBinding } = require('internal/test/binding');
61cb0ef41Sopenharmony_ciconst cares = internalBinding('cares_wrap');
71cb0ef41Sopenharmony_ciconst { promisify } = require('util');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// Test that --dns-result-order=verbatim works as expected.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst originalGetaddrinfo = cares.getaddrinfo;
121cb0ef41Sopenharmony_ciconst calls = [];
131cb0ef41Sopenharmony_cicares.getaddrinfo = common.mustCallAtLeast((...args) => {
141cb0ef41Sopenharmony_ci  calls.push(args);
151cb0ef41Sopenharmony_ci  originalGetaddrinfo(...args);
161cb0ef41Sopenharmony_ci}, 1);
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciconst dns = require('dns');
191cb0ef41Sopenharmony_ciconst dnsPromises = dns.promises;
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cilet verbatim;
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci// We want to test the parameter of verbatim only so that we
241cb0ef41Sopenharmony_ci// ignore possible errors here.
251cb0ef41Sopenharmony_cifunction allowFailed(fn) {
261cb0ef41Sopenharmony_ci  return fn.catch((_err) => {
271cb0ef41Sopenharmony_ci    //
281cb0ef41Sopenharmony_ci  });
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci(async () => {
321cb0ef41Sopenharmony_ci  let callsLength = 0;
331cb0ef41Sopenharmony_ci  const checkParameter = (expected) => {
341cb0ef41Sopenharmony_ci    assert.strictEqual(calls.length, callsLength + 1);
351cb0ef41Sopenharmony_ci    verbatim = calls[callsLength][4];
361cb0ef41Sopenharmony_ci    assert.strictEqual(verbatim, expected);
371cb0ef41Sopenharmony_ci    callsLength += 1;
381cb0ef41Sopenharmony_ci  };
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci  await allowFailed(promisify(dns.lookup)('example.org'));
411cb0ef41Sopenharmony_ci  checkParameter(true);
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci  await allowFailed(dnsPromises.lookup('example.org'));
441cb0ef41Sopenharmony_ci  checkParameter(true);
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ci  await allowFailed(promisify(dns.lookup)('example.org', {}));
471cb0ef41Sopenharmony_ci  checkParameter(true);
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci  await allowFailed(dnsPromises.lookup('example.org', {}));
501cb0ef41Sopenharmony_ci  checkParameter(true);
511cb0ef41Sopenharmony_ci})().then(common.mustCall());
52