mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 17:01:08 +00:00

Move tmpdir functionality to its own module (common/tmpdir). PR-URL: https://github.com/nodejs/node/pull/17856 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
51 lines
976 B
JavaScript
51 lines
976 B
JavaScript
'use strict';
|
|
|
|
require('../common');
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const path = require('path');
|
|
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
const agent = new http.Agent();
|
|
|
|
// default to localhost
|
|
assert.strictEqual(
|
|
agent.getName({
|
|
port: 80,
|
|
localAddress: '192.168.1.1'
|
|
}),
|
|
'localhost:80:192.168.1.1'
|
|
);
|
|
|
|
// empty
|
|
assert.strictEqual(
|
|
agent.getName({}),
|
|
'localhost::'
|
|
);
|
|
|
|
// pass all arguments
|
|
assert.strictEqual(
|
|
agent.getName({
|
|
host: '0.0.0.0',
|
|
port: 80,
|
|
localAddress: '192.168.1.1'
|
|
}),
|
|
'0.0.0.0:80:192.168.1.1'
|
|
);
|
|
|
|
// unix socket
|
|
const socketPath = path.join(tmpdir.path, 'foo', 'bar');
|
|
assert.strictEqual(
|
|
agent.getName({
|
|
socketPath
|
|
}),
|
|
`localhost:::${socketPath}`
|
|
);
|
|
|
|
for (const family of [0, null, undefined, 'bogus'])
|
|
assert.strictEqual(agent.getName({ family }), 'localhost::');
|
|
|
|
for (const family of [4, 6])
|
|
assert.strictEqual(agent.getName({ family }), `localhost:::${family}`);
|