• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3require('../common');
4const assert = require('assert');
5const http = require('http');
6const path = require('path');
7
8const tmpdir = require('../common/tmpdir');
9
10const agent = new http.Agent();
11
12// Default to localhost
13assert.strictEqual(
14  agent.getName({
15    port: 80,
16    localAddress: '192.168.1.1'
17  }),
18  'localhost:80:192.168.1.1'
19);
20
21// empty
22assert.strictEqual(
23  agent.getName({}),
24  'localhost::'
25);
26
27// pass all arguments
28assert.strictEqual(
29  agent.getName({
30    host: '0.0.0.0',
31    port: 80,
32    localAddress: '192.168.1.1'
33  }),
34  '0.0.0.0:80:192.168.1.1'
35);
36
37// unix socket
38const socketPath = path.join(tmpdir.path, 'foo', 'bar');
39assert.strictEqual(
40  agent.getName({
41    socketPath
42  }),
43  `localhost:::${socketPath}`
44);
45
46for (const family of [0, null, undefined, 'bogus'])
47  assert.strictEqual(agent.getName({ family }), 'localhost::');
48
49for (const family of [4, 6])
50  assert.strictEqual(agent.getName({ family }), `localhost:::${family}`);
51