• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4const assert = require('assert');
5const { internalBinding } = require('internal/test/binding');
6const cares = internalBinding('cares_wrap');
7const { UV_ENOENT } = internalBinding('uv');
8
9// Stub `getnameinfo` to *always* error.
10cares.getnameinfo = () => UV_ENOENT;
11
12// Because dns promises is attached lazily,
13// and turn accesses getnameinfo on init
14// but this lazy access is triggered by ES named
15// instead of lazily itself, we must require
16// dns after hooking cares
17const dns = require('dns');
18
19assert.throws(
20  () => dns.lookupService('127.0.0.1', 80, common.mustNotCall()),
21  {
22    code: 'ENOENT',
23    message: 'getnameinfo ENOENT 127.0.0.1',
24    syscall: 'getnameinfo'
25  }
26);
27
28assert.rejects(
29  dns.promises.lookupService('127.0.0.1', 80),
30  {
31    code: 'ENOENT',
32    message: 'getnameinfo ENOENT 127.0.0.1',
33    syscall: 'getnameinfo'
34  }
35);
36