|
| 1 | +'use strict' |
| 2 | + |
| 3 | +const assert = require('node:assert/strict') |
| 4 | + |
| 5 | +const { describe, it } = require('mocha') |
| 6 | + |
| 7 | +require('../../setup/core') |
| 8 | + |
| 9 | +const { parseUrl } = require('../../../src/exporters/common/url') |
| 10 | + |
| 11 | +describe('exporters/common/url parseUrl', () => { |
| 12 | + describe('unix domain sockets', () => { |
| 13 | + it('keeps the socket path for a string URL', () => { |
| 14 | + const url = parseUrl('unix:///var/run/datadog/apm.socket') |
| 15 | + |
| 16 | + assert.strictEqual(url.protocol, 'unix:') |
| 17 | + assert.strictEqual(url.pathname, '/var/run/datadog/apm.socket') |
| 18 | + }) |
| 19 | + |
| 20 | + it('keeps the socket path for a URL object', () => { |
| 21 | + const url = parseUrl(new URL('unix:///var/run/datadog/apm.socket')) |
| 22 | + |
| 23 | + assert.strictEqual(url.protocol, 'unix:') |
| 24 | + assert.strictEqual(url.pathname, '/var/run/datadog/apm.socket') |
| 25 | + }) |
| 26 | + }) |
| 27 | + |
| 28 | + // The `.` authority of a `unix://./pipe/<name>` URL is parsed out of the path, |
| 29 | + // so it must be folded back into `//./pipe/<name>`. Both branches matter: the |
| 30 | + // string form is what tests/CLIs pass, the object form is what config hands |
| 31 | + // every exporter. |
| 32 | + describe('windows named pipes', () => { |
| 33 | + it('folds the authority back for a string URL', () => { |
| 34 | + const url = parseUrl('unix://./pipe/datadog') |
| 35 | + |
| 36 | + assert.strictEqual(url.protocol, 'unix:') |
| 37 | + assert.strictEqual(url.pathname, '//./pipe/datadog') |
| 38 | + }) |
| 39 | + |
| 40 | + it('folds the authority back for a URL object', () => { |
| 41 | + const url = parseUrl(new URL('unix://./pipe/datadog')) |
| 42 | + |
| 43 | + assert.strictEqual(url.protocol, 'unix:') |
| 44 | + assert.strictEqual(url.pathname, '//./pipe/datadog') |
| 45 | + }) |
| 46 | + |
| 47 | + it('keeps the backslash form untouched', () => { |
| 48 | + const url = parseUrl(new URL('unix:\\\\.\\pipe\\datadog')) |
| 49 | + |
| 50 | + assert.strictEqual(url.protocol, 'unix:') |
| 51 | + assert.strictEqual(url.pathname, '\\\\.\\pipe\\datadog') |
| 52 | + }) |
| 53 | + }) |
| 54 | + |
| 55 | + describe('http(s) urls', () => { |
| 56 | + it('maps protocol, hostname and port for a string URL', () => { |
| 57 | + const url = parseUrl('https://127.0.0.1:8126/path') |
| 58 | + |
| 59 | + assert.strictEqual(url.protocol, 'https:') |
| 60 | + assert.strictEqual(url.hostname, '127.0.0.1') |
| 61 | + assert.strictEqual(String(url.port), '8126') |
| 62 | + }) |
| 63 | + |
| 64 | + it('maps protocol, hostname and port for a URL object', () => { |
| 65 | + const url = parseUrl(new URL('http://localhost:8126')) |
| 66 | + |
| 67 | + assert.strictEqual(url.protocol, 'http:') |
| 68 | + assert.strictEqual(url.hostname, 'localhost') |
| 69 | + assert.strictEqual(String(url.port), '8126') |
| 70 | + }) |
| 71 | + }) |
| 72 | +}) |
0 commit comments