@@ -25,77 +25,89 @@ const assert = require('assert'); |
25 | 25 | const net = require('net'); |
26 | 26 |
|
27 | 27 | // 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 | +} |
41 | 43 |
|
42 | 44 | if (!common.hasIPv6) { |
43 | 45 | common.printSkipMessage('ipv6 part of test, no IPv6 support'); |
44 | 46 | return; |
45 | 47 | } |
46 | 48 |
|
| 49 | +const family6 = 'IPv6'; |
| 50 | +const anycast6 = '::'; |
| 51 | + |
47 | 52 | // 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'; |
51 | 55 |
|
52 | | -server_ipv6.on('error', common.mustNotCall()); |
| 56 | + const server = net.createServer(); |
53 | 57 |
|
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()); |
61 | 59 |
|
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 | +} |
67 | 68 |
|
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 | +} |
76 | 84 |
|
77 | 85 | // Test without hostname or port |
78 | | -const server2 = net.createServer(); |
| 86 | +{ |
| 87 | + const server = net.createServer(); |
79 | 88 |
|
80 | | -server2.on('error', common.mustNotCall()); |
| 89 | + server.on('error', common.mustNotCall()); |
81 | 90 |
|
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 | +} |
89 | 99 |
|
90 | 100 | // Test without hostname, but with a false-y port |
91 | | -const server3 = net.createServer(); |
| 101 | +{ |
| 102 | + const server = net.createServer(); |
92 | 103 |
|
93 | | -server3.on('error', common.mustNotCall()); |
| 104 | + server.on('error', common.mustNotCall()); |
94 | 105 |
|
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 | +} |