Skip to content

Commit

Permalink
test: add error code tests in dgram test
Browse files Browse the repository at this point in the history
Improve error validation in test-dgram-send-bad-arguments.

PR-URL: #24215
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
MarkArranz authored and MylesBorins committed Dec 26, 2018
1 parent e57a5c3 commit 8e9ff69
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions test/parallel/test-dgram-send-bad-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,48 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.

'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');

const buf = Buffer.from('test');
const host = '127.0.0.1';
const sock = dgram.createSocket('udp4');

assert.throws(() => {
sock.send();
}, TypeError); // First argument should be a buffer.
// First argument should be a buffer.
common.expectsError(
() => { 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)
assert.throws(() => { sock.send(buf, 1, 1, -1, host); }, RangeError);
assert.throws(() => { sock.send(buf, 1, 1, 0, host); }, RangeError);
assert.throws(() => { sock.send(buf, 1, 1, 65536, host); }, RangeError);

// 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)
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'
}
);

0 comments on commit 8e9ff69

Please sign in to comment.