Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 194002b

Browse filesBrowse files
Trotttargos
authored andcommitted
test: use block-scoping in test-net-server-address
Use block-scoping in test-net-server-address. This also allows us to easily rename some identifiers that were not camelCase. PR-URL: #30754 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent cc8dc67 commit 194002b
Copy full SHA for 194002b

File tree

Expand file treeCollapse file tree

1 file changed

+67
-55
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+67
-55
lines changed
Open diff view settings
Collapse file

‎test/sequential/test-net-server-address.js‎

Copy file name to clipboardExpand all lines: test/sequential/test-net-server-address.js
+67-55Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,77 +25,89 @@ const assert = require('assert');
2525
const net = require('net');
2626

2727
// Test on IPv4 Server
28-
const family_ipv4 = 'IPv4';
29-
const server_ipv4 = net.createServer();
30-
31-
server_ipv4.on('error', common.mustNotCall());
32-
33-
server_ipv4
34-
.listen(common.PORT + 1, common.localhostIPv4, common.mustCall(() => {
35-
const address_ipv4 = server_ipv4.address();
36-
assert.strictEqual(address_ipv4.address, common.localhostIPv4);
37-
assert.strictEqual(address_ipv4.port, common.PORT + 1);
38-
assert.strictEqual(address_ipv4.family, family_ipv4);
39-
server_ipv4.close();
40-
}));
28+
{
29+
const family = 'IPv4';
30+
const server = net.createServer();
31+
32+
server.on('error', common.mustNotCall());
33+
34+
server
35+
.listen(common.PORT + 1, common.localhostIPv4, common.mustCall(() => {
36+
const address4 = server.address();
37+
assert.strictEqual(address4.address, common.localhostIPv4);
38+
assert.strictEqual(address4.port, common.PORT + 1);
39+
assert.strictEqual(address4.family, family);
40+
server.close();
41+
}));
42+
}
4143

4244
if (!common.hasIPv6) {
4345
common.printSkipMessage('ipv6 part of test, no IPv6 support');
4446
return;
4547
}
4648

49+
const family6 = 'IPv6';
50+
const anycast6 = '::';
51+
4752
// Test on IPv6 Server
48-
const localhost_ipv6 = '::1';
49-
const family_ipv6 = 'IPv6';
50-
const server_ipv6 = net.createServer();
53+
{
54+
const localhost = '::1';
5155

52-
server_ipv6.on('error', common.mustNotCall());
56+
const server = net.createServer();
5357

54-
server_ipv6.listen(common.PORT + 2, localhost_ipv6, common.mustCall(() => {
55-
const address_ipv6 = server_ipv6.address();
56-
assert.strictEqual(address_ipv6.address, localhost_ipv6);
57-
assert.strictEqual(address_ipv6.port, common.PORT + 2);
58-
assert.strictEqual(address_ipv6.family, family_ipv6);
59-
server_ipv6.close();
60-
}));
58+
server.on('error', common.mustNotCall());
6159

62-
// Test without hostname or ip
63-
const anycast_ipv6 = '::';
64-
const server1 = net.createServer();
65-
66-
server1.on('error', common.mustNotCall());
60+
server.listen(common.PORT + 2, localhost, common.mustCall(() => {
61+
const address = server.address();
62+
assert.strictEqual(address.address, localhost);
63+
assert.strictEqual(address.port, common.PORT + 2);
64+
assert.strictEqual(address.family, family6);
65+
server.close();
66+
}));
67+
}
6768

68-
// Specify the port number
69-
server1.listen(common.PORT + 3, common.mustCall(() => {
70-
const address = server1.address();
71-
assert.strictEqual(address.address, anycast_ipv6);
72-
assert.strictEqual(address.port, common.PORT + 3);
73-
assert.strictEqual(address.family, family_ipv6);
74-
server1.close();
75-
}));
69+
// Test without hostname or ip
70+
{
71+
const server = net.createServer();
72+
73+
server.on('error', common.mustNotCall());
74+
75+
// Specify the port number
76+
server.listen(common.PORT + 3, common.mustCall(() => {
77+
const address = server.address();
78+
assert.strictEqual(address.address, anycast6);
79+
assert.strictEqual(address.port, common.PORT + 3);
80+
assert.strictEqual(address.family, family6);
81+
server.close();
82+
}));
83+
}
7684

7785
// Test without hostname or port
78-
const server2 = net.createServer();
86+
{
87+
const server = net.createServer();
7988

80-
server2.on('error', common.mustNotCall());
89+
server.on('error', common.mustNotCall());
8190

82-
// Don't specify the port number
83-
server2.listen(common.mustCall(() => {
84-
const address = server2.address();
85-
assert.strictEqual(address.address, anycast_ipv6);
86-
assert.strictEqual(address.family, family_ipv6);
87-
server2.close();
88-
}));
91+
// Don't specify the port number
92+
server.listen(common.mustCall(() => {
93+
const address = server.address();
94+
assert.strictEqual(address.address, anycast6);
95+
assert.strictEqual(address.family, family6);
96+
server.close();
97+
}));
98+
}
8999

90100
// Test without hostname, but with a false-y port
91-
const server3 = net.createServer();
101+
{
102+
const server = net.createServer();
92103

93-
server3.on('error', common.mustNotCall());
104+
server.on('error', common.mustNotCall());
94105

95-
// Specify a false-y port number
96-
server3.listen(0, common.mustCall(() => {
97-
const address = server3.address();
98-
assert.strictEqual(address.address, anycast_ipv6);
99-
assert.strictEqual(address.family, family_ipv6);
100-
server3.close();
101-
}));
106+
// Specify a false-y port number
107+
server.listen(0, common.mustCall(() => {
108+
const address = server.address();
109+
assert.strictEqual(address.address, anycast6);
110+
assert.strictEqual(address.family, family6);
111+
server.close();
112+
}));
113+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.