Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dgram bad arguments tests #24215

Closed
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions test/parallel/test-dgram-send-bad-arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,25 @@
// 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.
assert.throws(() => { sock.send(); }, TypeError);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we don't need both this and common. expectsError(), I'd keep only common. expectsError(). Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update accordingly. Thank you.

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);
Expand All @@ -39,6 +47,24 @@ 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'
}
);