11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// This tests that the error thrown from net.createConnection
41cb0ef41Sopenharmony_ci// comes with host and port properties.
51cb0ef41Sopenharmony_ci// See https://github.com/nodejs/node-v0.x-archive/issues/7005
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst common = require('../common');
81cb0ef41Sopenharmony_ciconst assert = require('assert');
91cb0ef41Sopenharmony_ciconst net = require('net');
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst { addresses } = require('../common/internet');
121cb0ef41Sopenharmony_ciconst {
131cb0ef41Sopenharmony_ci  errorLookupMock,
141cb0ef41Sopenharmony_ci  mockedErrorCode
151cb0ef41Sopenharmony_ci} = require('../common/dns');
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci// Using port 0 as hostname used is already invalid.
181cb0ef41Sopenharmony_ciconst c = net.createConnection({
191cb0ef41Sopenharmony_ci  port: 0,
201cb0ef41Sopenharmony_ci  host: addresses.INVALID_HOST,
211cb0ef41Sopenharmony_ci  lookup: common.mustCall(errorLookupMock())
221cb0ef41Sopenharmony_ci});
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cic.on('connect', common.mustNotCall());
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cic.on('error', common.mustCall((error) => {
271cb0ef41Sopenharmony_ci  assert.ok(!('port' in error));
281cb0ef41Sopenharmony_ci  assert.ok(!('host' in error));
291cb0ef41Sopenharmony_ci  assert.throws(() => { throw error; }, {
301cb0ef41Sopenharmony_ci    errno: mockedErrorCode,
311cb0ef41Sopenharmony_ci    code: mockedErrorCode,
321cb0ef41Sopenharmony_ci    name: 'Error',
331cb0ef41Sopenharmony_ci    message: 'getaddrinfo ENOTFOUND something.invalid',
341cb0ef41Sopenharmony_ci    hostname: addresses.INVALID_HOST,
351cb0ef41Sopenharmony_ci    syscall: 'getaddrinfo'
361cb0ef41Sopenharmony_ci  });
371cb0ef41Sopenharmony_ci}));
38