11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst dgram = require('dgram'); 51cb0ef41Sopenharmony_ciconst dns = require('dns'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ci{ 81cb0ef41Sopenharmony_ci // Verify that the provided lookup function is called. 91cb0ef41Sopenharmony_ci const lookup = common.mustCall((host, family, callback) => { 101cb0ef41Sopenharmony_ci dns.lookup(host, family, callback); 111cb0ef41Sopenharmony_ci }); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci const socket = dgram.createSocket({ type: 'udp4', lookup }); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci socket.bind(common.mustCall(() => { 161cb0ef41Sopenharmony_ci socket.close(); 171cb0ef41Sopenharmony_ci })); 181cb0ef41Sopenharmony_ci} 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci{ 211cb0ef41Sopenharmony_ci // Verify that lookup defaults to dns.lookup(). 221cb0ef41Sopenharmony_ci const originalLookup = dns.lookup; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci dns.lookup = common.mustCall((host, family, callback) => { 251cb0ef41Sopenharmony_ci dns.lookup = originalLookup; 261cb0ef41Sopenharmony_ci originalLookup(host, family, callback); 271cb0ef41Sopenharmony_ci }); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci const socket = dgram.createSocket({ type: 'udp4' }); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci socket.bind(common.mustCall(() => { 321cb0ef41Sopenharmony_ci socket.close(); 331cb0ef41Sopenharmony_ci })); 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci{ 371cb0ef41Sopenharmony_ci // Verify that non-functions throw. 381cb0ef41Sopenharmony_ci [null, true, false, 0, 1, NaN, '', 'foo', {}, Symbol()].forEach((value) => { 391cb0ef41Sopenharmony_ci assert.throws(() => { 401cb0ef41Sopenharmony_ci dgram.createSocket({ type: 'udp4', lookup: value }); 411cb0ef41Sopenharmony_ci }, { 421cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 431cb0ef41Sopenharmony_ci name: 'TypeError', 441cb0ef41Sopenharmony_ci message: 'The "lookup" argument must be of type function.' + 451cb0ef41Sopenharmony_ci common.invalidArgTypeHelper(value) 461cb0ef41Sopenharmony_ci }); 471cb0ef41Sopenharmony_ci }); 481cb0ef41Sopenharmony_ci} 49