Skip to content

Commit 194002b

Browse 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

1 file changed

Lines changed: 67 additions & 55 deletions

File tree

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

Lines changed: 67 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -25,77 +25,89 @@ const assert = require('assert');
2525
constnet=require('net');
2626

2727
// Test on IPv4 Server
28-
constfamily_ipv4='IPv4';
29-
constserver_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-
constaddress_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+
constfamily='IPv4';
30+
constserver=net.createServer();
31+
32+
server.on('error',common.mustNotCall());
33+
34+
server
35+
.listen(common.PORT+1,common.localhostIPv4,common.mustCall(()=>{
36+
constaddress4=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+
constfamily6='IPv6';
50+
constanycast6='::';
51+
4752
// Test on IPv6 Server
48-
constlocalhost_ipv6='::1';
49-
constfamily_ipv6='IPv6';
50-
constserver_ipv6=net.createServer();
53+
{
54+
constlocalhost='::1';
5155

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

54-
server_ipv6.listen(common.PORT+2,localhost_ipv6,common.mustCall(()=>{
55-
constaddress_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-
constanycast_ipv6='::';
64-
constserver1=net.createServer();
65-
66-
server1.on('error',common.mustNotCall());
60+
server.listen(common.PORT+2,localhost,common.mustCall(()=>{
61+
constaddress=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-
constaddress=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+
constserver=net.createServer();
72+
73+
server.on('error',common.mustNotCall());
74+
75+
// Specify the port number
76+
server.listen(common.PORT+3,common.mustCall(()=>{
77+
constaddress=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-
constserver2=net.createServer();
86+
{
87+
constserver=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-
constaddress=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+
constaddress=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-
constserver3=net.createServer();
101+
{
102+
constserver=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-
constaddress=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+
constaddress=server.address();
109+
assert.strictEqual(address.address,anycast6);
110+
assert.strictEqual(address.family,family6);
111+
server.close();
112+
}));
113+
}

0 commit comments

Comments
 (0)