forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add coverage for dgram send() errors
This commit adds code coverage for emitted and callback errors for dgram's Socket#send() method. PR-URL: nodejs#11248 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
const mockError = new Error('mock DNS error'); | ||
|
||
function getSocket(callback) { | ||
const socket = dgram.createSocket('udp4'); | ||
|
||
socket.on('message', common.mustNotCall('Should not receive any messages.')); | ||
socket.bind(common.mustCall(() => { | ||
socket._handle.lookup = function(address, callback) { | ||
process.nextTick(callback, mockError); | ||
}; | ||
|
||
callback(socket); | ||
})); | ||
return socket; | ||
} | ||
|
||
getSocket((socket) => { | ||
socket.on('error', common.mustCall((err) => { | ||
socket.close(); | ||
assert.strictEqual(err, mockError); | ||
})); | ||
|
||
socket.send('foo', socket.address().port, 'localhost'); | ||
}); | ||
|
||
getSocket((socket) => { | ||
const callback = common.mustCall((err) => { | ||
socket.close(); | ||
assert.strictEqual(err, mockError); | ||
}); | ||
|
||
socket.send('foo', socket.address().port, 'localhost', callback); | ||
}); |