11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst http = require('http');
61cb0ef41Sopenharmony_ciconst path = require('path');
71cb0ef41Sopenharmony_ci
81cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir');
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciconst agent = new http.Agent();
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ci// Default to localhost
131cb0ef41Sopenharmony_ciassert.strictEqual(
141cb0ef41Sopenharmony_ci  agent.getName({
151cb0ef41Sopenharmony_ci    port: 80,
161cb0ef41Sopenharmony_ci    localAddress: '192.168.1.1'
171cb0ef41Sopenharmony_ci  }),
181cb0ef41Sopenharmony_ci  'localhost:80:192.168.1.1'
191cb0ef41Sopenharmony_ci);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_ci// empty argument
221cb0ef41Sopenharmony_ciassert.strictEqual(
231cb0ef41Sopenharmony_ci  agent.getName(),
241cb0ef41Sopenharmony_ci  'localhost::'
251cb0ef41Sopenharmony_ci);
261cb0ef41Sopenharmony_ci
271cb0ef41Sopenharmony_ci// empty options
281cb0ef41Sopenharmony_ciassert.strictEqual(
291cb0ef41Sopenharmony_ci  agent.getName({}),
301cb0ef41Sopenharmony_ci  'localhost::'
311cb0ef41Sopenharmony_ci);
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci// pass all arguments
341cb0ef41Sopenharmony_ciassert.strictEqual(
351cb0ef41Sopenharmony_ci  agent.getName({
361cb0ef41Sopenharmony_ci    host: '0.0.0.0',
371cb0ef41Sopenharmony_ci    port: 80,
381cb0ef41Sopenharmony_ci    localAddress: '192.168.1.1'
391cb0ef41Sopenharmony_ci  }),
401cb0ef41Sopenharmony_ci  '0.0.0.0:80:192.168.1.1'
411cb0ef41Sopenharmony_ci);
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci// unix socket
441cb0ef41Sopenharmony_ciconst socketPath = path.join(tmpdir.path, 'foo', 'bar');
451cb0ef41Sopenharmony_ciassert.strictEqual(
461cb0ef41Sopenharmony_ci  agent.getName({
471cb0ef41Sopenharmony_ci    socketPath
481cb0ef41Sopenharmony_ci  }),
491cb0ef41Sopenharmony_ci  `localhost:::${socketPath}`
501cb0ef41Sopenharmony_ci);
511cb0ef41Sopenharmony_ci
521cb0ef41Sopenharmony_cifor (const family of [0, null, undefined, 'bogus'])
531cb0ef41Sopenharmony_ci  assert.strictEqual(agent.getName({ family }), 'localhost::');
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cifor (const family of [4, 6])
561cb0ef41Sopenharmony_ci  assert.strictEqual(agent.getName({ family }), `localhost:::${family}`);
57