Skip to content
Closed
Changes from 1 commit
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
Next Next commit
dgram: add more tests for Socket.prototype.send
- Add coverage around valid, undocumented types for `address` parameter.
- Add coverage around known invalid, but uncovered, types for `address`
  parameter.
  • Loading branch information
boneskull committed Feb 14, 2017
commit c7bfc6d5952249718e41f978302a946b802a8e99
56 changes: 56 additions & 0 deletions test/parallel/test-dgram-send-address-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');

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

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

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

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

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

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

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

// the socket must be bound before these following assertions;
// otherwise the exceptions won't be thrown synchronously.

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

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

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

// invalid address: function
assert.throws(() => {
client.send(buf, port, () => {
});
}, TypeError);
}))
.unref();