Skip to content

Commit 7ff32bf

Browse files
cjihrigitaloacasas
authored andcommitted
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: #11248 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]>
1 parent 67d4dc0 commit 7ff32bf

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const dgram = require('dgram');
5+
const mockError = new Error('mock DNS error');
6+
7+
function getSocket(callback) {
8+
const socket = dgram.createSocket('udp4');
9+
10+
socket.on('message', common.mustNotCall('Should not receive any messages.'));
11+
socket.bind(common.mustCall(() => {
12+
socket._handle.lookup = function(address, callback) {
13+
process.nextTick(callback, mockError);
14+
};
15+
16+
callback(socket);
17+
}));
18+
return socket;
19+
}
20+
21+
getSocket((socket) => {
22+
socket.on('error', common.mustCall((err) => {
23+
socket.close();
24+
assert.strictEqual(err, mockError);
25+
}));
26+
27+
socket.send('foo', socket.address().port, 'localhost');
28+
});
29+
30+
getSocket((socket) => {
31+
const callback = common.mustCall((err) => {
32+
socket.close();
33+
assert.strictEqual(err, mockError);
34+
});
35+
36+
socket.send('foo', socket.address().port, 'localhost', callback);
37+
});

0 commit comments

Comments
 (0)