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

test: replace port in dgram send address types test #13007

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
59 changes: 31 additions & 28 deletions test/parallel/test-dgram-send-address-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,52 @@ const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');

const port = common.PORT;
const buf = Buffer.from('test');
const client = dgram.createSocket('udp4');

const onMessage = common.mustCall((err, bytes) => {
assert.ifError(err);
assert.strictEqual(bytes, buf.length);
}, 6);

// valid address: false
client.send(buf, port, false, onMessage);
const expectedError =
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;

// valid address: empty string
client.send(buf, port, '', onMessage);
const client = dgram.createSocket('udp4').bind(0, () => {

// valid address: null
client.send(buf, port, null, onMessage);
const port = client.address().port;

// valid address: 0
client.send(buf, port, 0, onMessage);
// valid address: false
client.send(buf, port, false, onMessage);

// valid address: undefined
client.send(buf, port, undefined, onMessage);
// valid address: empty string
client.send(buf, port, '', onMessage);

// valid address: not provided
client.send(buf, port, onMessage);
// valid address: null
client.send(buf, port, null, onMessage);

const expectedError =
/^TypeError: Invalid arguments: address must be a nonempty string or falsy$/;
// valid address: 0
client.send(buf, port, 0, onMessage);

// valid address: undefined
client.send(buf, port, undefined, onMessage);

// valid address: not provided
client.send(buf, port, onMessage);

// invalid address: object
assert.throws(() => {
client.send(buf, port, []);
}, expectedError);
// invalid address: object
assert.throws(() => {
client.send(buf, port, []);
}, expectedError);

// invalid address: nonzero number
assert.throws(() => {
client.send(buf, port, 1);
}, expectedError);
// invalid address: nonzero number
assert.throws(() => {
client.send(buf, port, 1);
}, expectedError);

// invalid address: true
assert.throws(() => {
client.send(buf, port, true);
}, expectedError);
// invalid address: true
assert.throws(() => {
client.send(buf, port, true);
}, expectedError);
});

client.unref();