1'use strict'; 2const common = require('../common'); 3const assert = require('assert'); 4const dgram = require('dgram'); 5const dns = require('dns'); 6 7{ 8 // Verify that the provided lookup function is called. 9 const lookup = common.mustCall((host, family, callback) => { 10 dns.lookup(host, family, callback); 11 }); 12 13 const socket = dgram.createSocket({ type: 'udp4', lookup }); 14 15 socket.bind(common.mustCall(() => { 16 socket.close(); 17 })); 18} 19 20{ 21 // Verify that lookup defaults to dns.lookup(). 22 const originalLookup = dns.lookup; 23 24 dns.lookup = common.mustCall((host, family, callback) => { 25 dns.lookup = originalLookup; 26 originalLookup(host, family, callback); 27 }); 28 29 const socket = dgram.createSocket({ type: 'udp4' }); 30 31 socket.bind(common.mustCall(() => { 32 socket.close(); 33 })); 34} 35 36{ 37 // Verify that non-functions throw. 38 [null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((value) => { 39 assert.throws(() => { 40 dgram.createSocket({ type: 'udp4', lookup: value }); 41 }, { 42 code: 'ERR_INVALID_ARG_TYPE', 43 name: 'TypeError', 44 message: 'The "lookup" argument must be of type function.' + 45 common.invalidArgTypeHelper(value) 46 }); 47 }); 48} 49