test: fix parallel/test-dgram-error-message-address
[platform/upstream/nodejs.git] / test / parallel / test-dgram-error-message-address.js
1 var common = require('../common');
2 var assert = require('assert');
3 var dgram = require('dgram');
4
5 // IPv4 Test
6 var socket_ipv4 = dgram.createSocket('udp4');
7
8 socket_ipv4.on('listening', assert.fail);
9
10 socket_ipv4.on('error', common.mustCall(function(e) {
11   assert.equal(e.message, 'bind EADDRNOTAVAIL 1.1.1.1:' + common.PORT);
12   assert.equal(e.address, '1.1.1.1');
13   assert.equal(e.port, common.PORT);
14   assert.equal(e.code, 'EADDRNOTAVAIL');
15   socket_ipv4.close();
16 }));
17
18 socket_ipv4.bind(common.PORT, '1.1.1.1');
19
20 // IPv6 Test
21 var socket_ipv6 = dgram.createSocket('udp6');
22 var family_ipv6 = 'IPv6';
23
24 socket_ipv6.on('listening', assert.fail);
25
26 socket_ipv6.on('error', common.mustCall(function(e) {
27   // EAFNOSUPPORT means IPv6 is disabled on this system.
28   var code = (e.code === 'EADDRNOTAVAIL' ? e.code : 'EAFNOSUPPORT');
29   assert.equal(e.message, 'bind ' + code + ' 111::1:' + common.PORT);
30   assert.equal(e.address, '111::1');
31   assert.equal(e.port, common.PORT);
32   assert.equal(e.code, code);
33   socket_ipv6.close();
34 }));
35
36 socket_ipv6.bind(common.PORT, '111::1');