Skip to content
Permalink
Browse files

dgram: test to add and to drop specific membership

Test of addSourceSpecificMembership and dropSourceSpecificMembership
for correct arguments with sourceAddress, groupAddress.

PR-URL: #31047
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
zeroWheel authored and BridgeAR committed Dec 20, 2019
1 parent ca53f02 commit 44d03e81d49f1e9d0894bedf397a620e7ad5666d
Showing with 80 additions and 8 deletions.
  1. +4 −8 lib/dgram.js
  2. +76 −0 test/parallel/test-dgram-membership.js
@@ -856,13 +856,11 @@ Socket.prototype.addSourceSpecificMembership = function(sourceAddress,
healthCheck(this);

if (typeof sourceAddress !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'sourceAddress',
'string');
throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress);
}

if (typeof groupAddress !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'groupAddress',
'string');
throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress);
}

const err =
@@ -881,13 +879,11 @@ Socket.prototype.dropSourceSpecificMembership = function(sourceAddress,
healthCheck(this);

if (typeof sourceAddress !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'sourceAddress',
'string');
throw new ERR_INVALID_ARG_TYPE('sourceAddress', 'string', sourceAddress);
}

if (typeof groupAddress !== 'string') {
throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'groupAddress',
'string');
throw new ERR_INVALID_ARG_TYPE('groupAddress', 'string', groupAddress);
}

const err =
@@ -76,3 +76,79 @@ const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
/^Error: dropMembership EINVAL$/);
socket.close();
}

// addSourceSpecificMembership with invalid sourceAddress should throw
{
const socket = setup();
assert.throws(() => {
socket.addSourceSpecificMembership(0, multicastAddress);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "sourceAddress" argument must be of type string. ' +
'Received type number (0)'
});
socket.close();
}

// addSourceSpecificMembership with invalid sourceAddress should throw
{
const socket = setup();
assert.throws(() => {
socket.addSourceSpecificMembership(multicastAddress, 0);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "groupAddress" argument must be of type string. ' +
'Received type number (0)'
});
socket.close();
}

// addSourceSpecificMembership with invalid groupAddress should throw
{
const socket = setup();
assert.throws(() => {
socket.addSourceSpecificMembership(multicastAddress, '0');
}, {
code: 'EINVAL',
message: 'addSourceSpecificMembership EINVAL'
});
socket.close();
}

// dropSourceSpecificMembership with invalid sourceAddress should throw
{
const socket = setup();
assert.throws(() => {
socket.dropSourceSpecificMembership(0, multicastAddress);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "sourceAddress" argument must be of type string. ' +
'Received type number (0)'
});
socket.close();
}

// dropSourceSpecificMembership with invalid groupAddress should throw
{
const socket = setup();
assert.throws(() => {
socket.dropSourceSpecificMembership(multicastAddress, 0);
}, {
code: 'ERR_INVALID_ARG_TYPE',
message: 'The "groupAddress" argument must be of type string. ' +
'Received type number (0)'
});
socket.close();
}

// dropSourceSpecificMembership with invalid UDP should throw
{
const socket = setup();
assert.throws(() => {
socket.dropSourceSpecificMembership(multicastAddress, '0');
}, {
code: 'EINVAL',
message: 'dropSourceSpecificMembership EINVAL'
});
socket.close();
}

0 comments on commit 44d03e8

Please sign in to comment.
You can’t perform that action at this time.