1'use strict'; 2const common = require('../common'); 3const { addresses } = require('../common/internet'); 4const assert = require('assert'); 5const dns = require('dns'); 6const resolver = new dns.promises.Resolver(); 7const dnsPromises = dns.promises; 8const promiseResolver = new dns.promises.Resolver(); 9 10{ 11 [ 12 null, 13 undefined, 14 Number(addresses.DNS4_SERVER), 15 addresses.DNS4_SERVER, 16 { 17 address: addresses.DNS4_SERVER 18 }, 19 ].forEach((val) => { 20 const errObj = { 21 code: 'ERR_INVALID_ARG_TYPE', 22 name: 'TypeError', 23 message: 'The "servers" argument must be an instance of Array.' + 24 common.invalidArgTypeHelper(val) 25 }; 26 assert.throws( 27 () => { 28 dns.setServers(val); 29 }, errObj 30 ); 31 assert.throws( 32 () => { 33 resolver.setServers(val); 34 }, errObj 35 ); 36 assert.throws( 37 () => { 38 dnsPromises.setServers(val); 39 }, errObj 40 ); 41 assert.throws( 42 () => { 43 promiseResolver.setServers(val); 44 }, errObj 45 ); 46 }); 47} 48 49{ 50 [ 51 [null], 52 [undefined], 53 [Number(addresses.DNS4_SERVER)], 54 [ 55 { 56 address: addresses.DNS4_SERVER 57 }, 58 ], 59 ].forEach((val) => { 60 const errObj = { 61 code: 'ERR_INVALID_ARG_TYPE', 62 name: 'TypeError', 63 message: 'The "servers[0]" argument must be of type string.' + 64 common.invalidArgTypeHelper(val[0]) 65 }; 66 assert.throws( 67 () => { 68 dns.setServers(val); 69 }, errObj 70 ); 71 assert.throws( 72 () => { 73 resolver.setServers(val); 74 }, errObj 75 ); 76 assert.throws( 77 () => { 78 dnsPromises.setServers(val); 79 }, errObj 80 ); 81 assert.throws( 82 () => { 83 promiseResolver.setServers(val); 84 }, errObj 85 ); 86 }); 87} 88