11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci// Flags: --expose-internals
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst net = require('net');
61cb0ef41Sopenharmony_ciconst { normalizedArgsSymbol } = require('internal/net');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_cifunction validateNormalizedArgs(input, output) {
91cb0ef41Sopenharmony_ci  const args = net._normalizeArgs(input);
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci  assert.deepStrictEqual(args, output);
121cb0ef41Sopenharmony_ci  assert.strictEqual(args[normalizedArgsSymbol], true);
131cb0ef41Sopenharmony_ci}
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_ci// Test creation of normalized arguments.
161cb0ef41Sopenharmony_ciconst res = [{}, null];
171cb0ef41Sopenharmony_cires[normalizedArgsSymbol] = true;
181cb0ef41Sopenharmony_civalidateNormalizedArgs([], res);
191cb0ef41Sopenharmony_cires[0].port = 1234;
201cb0ef41Sopenharmony_civalidateNormalizedArgs([{ port: 1234 }], res);
211cb0ef41Sopenharmony_cires[1] = assert.fail;
221cb0ef41Sopenharmony_civalidateNormalizedArgs([{ port: 1234 }, assert.fail], res);
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci// Connecting to the server should fail with a standard array.
251cb0ef41Sopenharmony_ci{
261cb0ef41Sopenharmony_ci  const server = net.createServer(common.mustNotCall('should not connect'));
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  server.listen(common.mustCall(() => {
291cb0ef41Sopenharmony_ci    const port = server.address().port;
301cb0ef41Sopenharmony_ci    const socket = new net.Socket();
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci    assert.throws(() => {
331cb0ef41Sopenharmony_ci      socket.connect([{ port }, assert.fail]);
341cb0ef41Sopenharmony_ci    }, {
351cb0ef41Sopenharmony_ci      code: 'ERR_MISSING_ARGS'
361cb0ef41Sopenharmony_ci    });
371cb0ef41Sopenharmony_ci    server.close();
381cb0ef41Sopenharmony_ci  }));
391cb0ef41Sopenharmony_ci}
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ci// Connecting to the server should succeed with a normalized array.
421cb0ef41Sopenharmony_ci{
431cb0ef41Sopenharmony_ci  const server = net.createServer(common.mustCall((connection) => {
441cb0ef41Sopenharmony_ci    connection.end();
451cb0ef41Sopenharmony_ci    server.close();
461cb0ef41Sopenharmony_ci  }));
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ci  server.listen(common.mustCall(() => {
491cb0ef41Sopenharmony_ci    const port = server.address().port;
501cb0ef41Sopenharmony_ci    const socket = new net.Socket();
511cb0ef41Sopenharmony_ci    const args = net._normalizeArgs([{ port }, common.mustCall()]);
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci    socket.connect(args);
541cb0ef41Sopenharmony_ci  }));
551cb0ef41Sopenharmony_ci}
56