Skip to content

Commit

Permalink
dgram: test to add and to drop specific membership
Browse files Browse the repository at this point in the history
Test of addSourceSpecificMembership and dropSourceSpecificMembership
for correct arguments with sourceAddress, groupAddress.
  • Loading branch information
universePrisoner committed Dec 20, 2019
1 parent 118b28a commit 3abcdf4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/dgram.js
Expand Up @@ -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 =
Expand All @@ -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 =
Expand Down
72 changes: 72 additions & 0 deletions test/parallel/test-dgram-membership.js
Expand Up @@ -76,3 +76,75 @@ 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$/
});
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$/
});
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$/
});
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$/
});
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 3abcdf4

Please sign in to comment.