/
test-dgram-membership.js
154 lines (140 loc) Β· 3.81 KB
/
test-dgram-membership.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
'use strict';
const common = require('../common');
const assert = require('assert');
const dgram = require('dgram');
const multicastAddress = '224.0.0.114';
const setup = dgram.createSocket.bind(dgram, { type: 'udp4', reuseAddr: true });
// addMembership() on closed socket should throw
{
const socket = setup();
socket.close(common.mustCall(() => {
common.expectsError(() => {
socket.addMembership(multicastAddress);
}, {
code: 'ERR_SOCKET_DGRAM_NOT_RUNNING',
type: Error,
message: /^Not running$/
});
}));
}
// dropMembership() on closed socket should throw
{
const socket = setup();
socket.close(common.mustCall(() => {
common.expectsError(() => {
socket.dropMembership(multicastAddress);
}, {
code: 'ERR_SOCKET_DGRAM_NOT_RUNNING',
type: Error,
message: /^Not running$/
});
}));
}
// addMembership() with no argument should throw
{
const socket = setup();
common.expectsError(() => {
socket.addMembership();
}, {
code: 'ERR_MISSING_ARGS',
type: TypeError,
message: /^The "multicastAddress" argument must be specified$/
});
socket.close();
}
// dropMembership() with no argument should throw
{
const socket = setup();
common.expectsError(() => {
socket.dropMembership();
}, {
code: 'ERR_MISSING_ARGS',
type: TypeError,
message: /^The "multicastAddress" argument must be specified$/
});
socket.close();
}
// addMembership() with invalid multicast address should throw
{
const socket = setup();
assert.throws(() => { socket.addMembership('256.256.256.256'); },
/^Error: addMembership EINVAL$/);
socket.close();
}
// dropMembership() with invalid multicast address should throw
{
const socket = setup();
assert.throws(() => { socket.dropMembership('256.256.256.256'); },
/^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();
}