11cb0ef41Sopenharmony_ci// Flags: --expose-internals
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 { UV_ENOENT } = internalBinding('uv');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci// Stub `getnameinfo` to *always* error.
101cb0ef41Sopenharmony_cicares.getnameinfo = () => UV_ENOENT;
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// Because dns promises is attached lazily,
131cb0ef41Sopenharmony_ci// and turn accesses getnameinfo on init
141cb0ef41Sopenharmony_ci// but this lazy access is triggered by ES named
151cb0ef41Sopenharmony_ci// instead of lazily itself, we must require
161cb0ef41Sopenharmony_ci// dns after hooking cares
171cb0ef41Sopenharmony_ciconst dns = require('dns');
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciassert.throws(
201cb0ef41Sopenharmony_ci  () => dns.lookupService('127.0.0.1', 80, common.mustNotCall()),
211cb0ef41Sopenharmony_ci  {
221cb0ef41Sopenharmony_ci    code: 'ENOENT',
231cb0ef41Sopenharmony_ci    message: 'getnameinfo ENOENT 127.0.0.1',
241cb0ef41Sopenharmony_ci    syscall: 'getnameinfo'
251cb0ef41Sopenharmony_ci  }
261cb0ef41Sopenharmony_ci);
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciassert.rejects(
291cb0ef41Sopenharmony_ci  dns.promises.lookupService('127.0.0.1', 80),
301cb0ef41Sopenharmony_ci  {
311cb0ef41Sopenharmony_ci    code: 'ENOENT',
321cb0ef41Sopenharmony_ci    message: 'getnameinfo ENOENT 127.0.0.1',
331cb0ef41Sopenharmony_ci    syscall: 'getnameinfo'
341cb0ef41Sopenharmony_ci  }
351cb0ef41Sopenharmony_ci);
36