diff options
author | cjihrig <cjihrig@gmail.com> | 2017-02-10 10:31:29 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-02-13 17:25:40 -0500 |
commit | a2fac322d5782a5b1802039ed477f8d4f0db2bdb (patch) | |
tree | 33674eddc72e123e8dc89743d584da3d679f3447 /test | |
parent | 4762791fe2620de04fa8a61e9eca3611d950890c (diff) | |
download | android-node-v8-a2fac322d5782a5b1802039ed477f8d4f0db2bdb.tar.gz android-node-v8-a2fac322d5782a5b1802039ed477f8d4f0db2bdb.tar.bz2 android-node-v8-a2fac322d5782a5b1802039ed477f8d4f0db2bdb.zip |
test: add coverage for dgram _createSocketHandle()
This commit adds code coverage to _createSocketHandle(), which
the cluster module uses to create dgram sockets.
PR-URL: https://github.com/nodejs/node/pull/11291
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-dgram-create-socket-handle.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/parallel/test-dgram-create-socket-handle.js b/test/parallel/test-dgram-create-socket-handle.js new file mode 100644 index 0000000000..559d92be98 --- /dev/null +++ b/test/parallel/test-dgram-create-socket-handle.js @@ -0,0 +1,39 @@ +'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. +assert.throws(() => { + _createSocketHandle(common.localhostIPv4, 0, 'udp4', 42); +}, /^AssertionError: 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); +} |