From 72dc6ae7f8469cea96ab9f197e7597395edf1d76 Mon Sep 17 00:00:00 2001 From: Artur Vieira Date: Fri, 12 May 2017 21:54:01 +0000 Subject: [PATCH] test: replace port in dgram send address types test Replaced common.PORT in the following test. test-dgram-send-address-types.js Ref: nodejs#12376 --- .../parallel/test-dgram-send-address-types.js | 59 ++++++++++--------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/test/parallel/test-dgram-send-address-types.js b/test/parallel/test-dgram-send-address-types.js index d064898aa9fd86..e00068cbde9097 100644 --- a/test/parallel/test-dgram-send-address-types.js +++ b/test/parallel/test-dgram-send-address-types.js @@ -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();