node/test/parallel/test-dgram-create-socket-handle.js
Mithun Sasidharan d8c896cac5
test: use common.expectsError in tests
PR-URL: https://github.com/nodejs/node/pull/17484
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
2017-12-08 16:21:47 -05:00

43 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const UDP = process.binding('udp_wrap').UDP;
const _createSocketHandle = dgram._createSocketHandle;
// Throws if an "existing fd" is passed in.
common.expectsError(() => {
_createSocketHandle(common.localhostIPv4, 0, 'udp4', 42);
}, {
code: 'ERR_ASSERTION',
message: /^false == true$/
});
{
// Create a handle that is not bound.
const handle = _createSocketHandle(null, null, 'udp4');
assert(handle instanceof UDP);
assert.strictEqual(typeof handle.fd, 'number');
assert(handle.fd < 0);
}
{
// Create a bound handle.
const handle = _createSocketHandle(common.localhostIPv4, 0, 'udp4');
assert(handle instanceof UDP);
assert.strictEqual(typeof handle.fd, 'number');
if (!common.isWindows)
assert(handle.fd > 0);
}
{
// Return an error if binding fails.
const err = _createSocketHandle('localhost', 0, 'udp4');
assert.strictEqual(typeof err, 'number');
assert(err < 0);
}