summaryrefslogtreecommitdiff
path: root/test/parallel/test-dns-lookupService.js
blob: dc04893c28f9fd292f6ab8f11211feb8a0baa6a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Flags: --expose-internals
'use strict';
const common = require('../common');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
const cares = internalBinding('cares_wrap');
const { UV_ENOENT } = internalBinding('uv');

// Stub `getnameinfo` to *always* error.
cares.getnameinfo = () => UV_ENOENT;

// Because dns promises is attached lazily,
// and turn accesses getnameinfo on init
// but this lazy access is triggered by ES named
// instead of lazily itself, we must require
// dns after hooking cares
const dns = require('dns');

assert.throws(
  () => dns.lookupService('127.0.0.1', 80, common.mustNotCall()),
  {
    code: 'ENOENT',
    message: 'getnameinfo ENOENT 127.0.0.1',
    syscall: 'getnameinfo'
  }
);

assert.rejects(
  dns.promises.lookupService('127.0.0.1', 80),
  {
    code: 'ENOENT',
    message: 'getnameinfo ENOENT 127.0.0.1',
    syscall: 'getnameinfo'
  }
);