|
| 1 | +'use strict' |
| 2 | + |
| 3 | +var test = require('tape') |
| 4 | +var { getHTTPDestination } = require('../../lib/instrumentation/context') |
| 5 | + |
| 6 | +test('#getHTTPDestination', function (t) { |
| 7 | + t.test('username and pass', (t) => { |
| 8 | + const url = 'http://user:pass@testing.local:1234/path?query' |
| 9 | + t.deepEqual(getHTTPDestination(url, 'external'), { |
| 10 | + service: { |
| 11 | + name: 'http://testing.local:1234', |
| 12 | + resource: 'testing.local:1234', |
| 13 | + type: 'external' |
| 14 | + }, |
| 15 | + address: 'testing.local', |
| 16 | + port: 1234 |
| 17 | + }) |
| 18 | + t.end() |
| 19 | + }) |
| 20 | + |
| 21 | + t.test('https with custom port', () => { |
| 22 | + const url = 'https://example.com:2222' |
| 23 | + t.deepEqual(getHTTPDestination(url, 'external'), { |
| 24 | + service: |
| 25 | + { |
| 26 | + name: 'https://example.com:2222', |
| 27 | + resource: 'example.com:2222', |
| 28 | + type: 'external' |
| 29 | + }, |
| 30 | + address: 'example.com', |
| 31 | + port: 2222 |
| 32 | + }) |
| 33 | + t.end() |
| 34 | + }) |
| 35 | + |
| 36 | + t.test('https default port', (t) => { |
| 37 | + const url = 'https://www.elastic.co/products/apm' |
| 38 | + t.deepEqual(getHTTPDestination(url, 'external'), { |
| 39 | + service: { |
| 40 | + name: 'https://www.elastic.co', |
| 41 | + resource: 'www.elastic.co:443', |
| 42 | + type: 'external' |
| 43 | + }, |
| 44 | + address: 'www.elastic.co', |
| 45 | + port: 443 |
| 46 | + }) |
| 47 | + t.end() |
| 48 | + }) |
| 49 | + |
| 50 | + t.test('http default port', (t) => { |
| 51 | + const url = 'http://www.elastic.co/products/apm' |
| 52 | + t.deepEqual(getHTTPDestination(url, 'external'), { |
| 53 | + service: { |
| 54 | + name: 'http://www.elastic.co', |
| 55 | + resource: 'www.elastic.co:80', |
| 56 | + type: 'external' |
| 57 | + }, |
| 58 | + address: 'www.elastic.co', |
| 59 | + port: 80 |
| 60 | + }) |
| 61 | + t.end() |
| 62 | + }) |
| 63 | + |
| 64 | + t.test('ipv6', (t) => { |
| 65 | + const url = 'http://[::1]' |
| 66 | + t.deepEqual(getHTTPDestination(url, 'external'), { |
| 67 | + service: { |
| 68 | + name: 'http://[::1]', |
| 69 | + resource: '[::1]:80', |
| 70 | + type: 'external' |
| 71 | + }, |
| 72 | + address: '::1', |
| 73 | + port: 80 |
| 74 | + }) |
| 75 | + t.end() |
| 76 | + }) |
| 77 | + |
| 78 | + t.test('ipv6 https custom port', (t) => { |
| 79 | + const url = 'https://[::1]:80/' |
| 80 | + t.deepEqual(getHTTPDestination(url, 'external'), { |
| 81 | + service: { |
| 82 | + name: 'https://[::1]:80', |
| 83 | + resource: '[::1]:80', |
| 84 | + type: 'external' |
| 85 | + }, |
| 86 | + address: '::1', |
| 87 | + port: 80 |
| 88 | + }) |
| 89 | + t.end() |
| 90 | + }) |
| 91 | +}) |
0 commit comments