1'use strict'; 2require('../common'); 3const assert = require('assert'); 4 5const dns = require('dns'); 6const resolver = new dns.Resolver(); 7const promiseResolver = new dns.promises.Resolver(); 8 9// Verifies that setLocalAddress succeeds with IPv4 and IPv6 addresses 10{ 11 resolver.setLocalAddress('127.0.0.1'); 12 resolver.setLocalAddress('::1'); 13 resolver.setLocalAddress('127.0.0.1', '::1'); 14 promiseResolver.setLocalAddress('127.0.0.1', '::1'); 15} 16 17// Verify that setLocalAddress throws if called with an invalid address 18{ 19 assert.throws(() => { 20 resolver.setLocalAddress('127.0.0.1', '127.0.0.1'); 21 }, Error); 22 assert.throws(() => { 23 resolver.setLocalAddress('::1', '::1'); 24 }, Error); 25 assert.throws(() => { 26 resolver.setLocalAddress('bad'); 27 }, Error); 28 assert.throws(() => { 29 resolver.setLocalAddress(123); 30 }, { code: 'ERR_INVALID_ARG_TYPE' }); 31 assert.throws(() => { 32 resolver.setLocalAddress('127.0.0.1', 42); 33 }, { code: 'ERR_INVALID_ARG_TYPE' }); 34 assert.throws(() => { 35 resolver.setLocalAddress(); 36 }, Error); 37 assert.throws(() => { 38 promiseResolver.setLocalAddress(); 39 }, Error); 40} 41