• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const dns = require('dns');
3const assert = require('assert');
4
5assert(process.env.NODE_TEST_HOST);
6
7const {
8  setDeserializeMainFunction,
9} = require('v8').startupSnapshot;
10
11function onError(err) {
12  console.error('error:', err);
13}
14
15function onResolve(addresses) {
16  console.log(`addresses: ${JSON.stringify(addresses)}`);
17}
18
19function onReverse(hostnames) {
20  console.log(`hostnames: ${JSON.stringify(hostnames)}`);
21}
22
23function query() {
24  if (process.env.NODE_TEST_DNS) {
25    dns.setServers([process.env.NODE_TEST_DNS])
26  }
27
28  const host = process.env.NODE_TEST_HOST;
29  if (process.env.NODE_TEST_PROMISE === 'true') {
30    dns.promises.resolve4(host).then(onResolve, onError);
31  } else {
32    dns.resolve4(host, (err, addresses) => {
33      if (err) {
34        onError(err);
35      } else {
36        onResolve(addresses);
37      }
38    });
39  }
40
41  const ip = process.env.NODE_TEST_IP;
42  if (ip) {
43    if (process.env.NODE_TEST_PROMISE === 'true') {
44      dns.promises.reverse(ip).then(onReverse, onError);
45    } else {
46      dns.reverse(ip, (err, hostnames) => {
47        if (err) {
48          onError(err);
49        } else {
50          onReverse(hostnames);
51        }
52      });
53    }
54  }
55}
56
57query();
58
59setDeserializeMainFunction(query);
60