test: add error code tests in dgram test
Improve error validation in test-dgram-send-bad-arguments. PR-URL: https://github.com/nodejs/node/pull/24215 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
8884a98ac0
commit
457cde3167
@ -20,7 +20,7 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
|
|
||||||
@ -28,9 +28,16 @@ const buf = Buffer.from('test');
|
|||||||
const host = '127.0.0.1';
|
const host = '127.0.0.1';
|
||||||
const sock = dgram.createSocket('udp4');
|
const sock = dgram.createSocket('udp4');
|
||||||
|
|
||||||
assert.throws(() => {
|
// First argument should be a buffer.
|
||||||
sock.send();
|
common.expectsError(
|
||||||
}, TypeError); // First argument should be a buffer.
|
() => { sock.send(); },
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "buffer" argument must be one of type ' +
|
||||||
|
'Buffer, Uint8Array, or string. Received type undefined'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// send(buf, offset, length, port, host)
|
// send(buf, offset, length, port, host)
|
||||||
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
|
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
|
||||||
@ -38,7 +45,23 @@ assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);
|
|||||||
assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError);
|
assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError);
|
||||||
|
|
||||||
// send(buf, port, host)
|
// send(buf, port, host)
|
||||||
assert.throws(() => { sock.send(23, 12345, host); }, TypeError);
|
common.expectsError(
|
||||||
|
() => { sock.send(23, 12345, host); },
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "buffer" argument must be one of type ' +
|
||||||
|
'Buffer, Uint8Array, or string. Received type number'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// send([buf1, ..], port, host)
|
// send([buf1, ..], port, host)
|
||||||
assert.throws(() => { sock.send([buf, 23], 12345, host); }, TypeError);
|
common.expectsError(
|
||||||
|
() => { sock.send([buf, 23], 12345, host); },
|
||||||
|
{
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "buffer list arguments" argument must be one of type ' +
|
||||||
|
'Buffer or string. Received type object'
|
||||||
|
}
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user