|
9 | 9 | setAsyncContextStrategy, |
10 | 10 | } from '@sentry/core'; |
11 | 11 | import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest'; |
| 12 | +import { getPortAndAddress } from '../../src/integrations/tracing-channel/firebase/firestore'; |
12 | 13 | import { firebaseChannelIntegration } from '../../src/orchestrion'; |
13 | 14 | import { CHANNELS } from '../../src/orchestrion/channels'; |
14 | 15 |
|
@@ -290,3 +291,79 @@ describe('firebaseChannelIntegration', () => { |
290 | 291 | }); |
291 | 292 | }); |
292 | 293 | }); |
| 294 | + |
| 295 | +describe('getPortAndAddress', () => { |
| 296 | + describe('IPv6 addresses', () => { |
| 297 | + it('parses an IPv6 address without a port', () => { |
| 298 | + const { address, port } = getPortAndAddress({ host: '[2001:db8::1]' }); |
| 299 | + |
| 300 | + expect(address).toBe('2001:db8::1'); |
| 301 | + expect(port).toBeUndefined(); |
| 302 | + }); |
| 303 | + |
| 304 | + it('parses an IPv6 address with a port', () => { |
| 305 | + const { address, port } = getPortAndAddress({ host: '[2001:db8::1]:8080' }); |
| 306 | + |
| 307 | + expect(address).toBe('2001:db8::1'); |
| 308 | + expect(port).toBe(8080); |
| 309 | + }); |
| 310 | + |
| 311 | + it('parses IPv6 localhost without a port', () => { |
| 312 | + const { address, port } = getPortAndAddress({ host: '[::1]' }); |
| 313 | + |
| 314 | + expect(address).toBe('::1'); |
| 315 | + expect(port).toBeUndefined(); |
| 316 | + }); |
| 317 | + |
| 318 | + it('parses IPv6 localhost with a port', () => { |
| 319 | + const { address, port } = getPortAndAddress({ host: '[::1]:3000' }); |
| 320 | + |
| 321 | + expect(address).toBe('::1'); |
| 322 | + expect(port).toBe(3000); |
| 323 | + }); |
| 324 | + }); |
| 325 | + |
| 326 | + describe('IPv4 and hostname addresses', () => { |
| 327 | + it('parses an IPv4 address with a port', () => { |
| 328 | + const { address, port } = getPortAndAddress({ host: '192.168.1.1:8080' }); |
| 329 | + |
| 330 | + expect(address).toBe('192.168.1.1'); |
| 331 | + expect(port).toBe(8080); |
| 332 | + }); |
| 333 | + |
| 334 | + it('parses a hostname with a port', () => { |
| 335 | + const { address, port } = getPortAndAddress({ host: 'localhost:3000' }); |
| 336 | + |
| 337 | + expect(address).toBe('localhost'); |
| 338 | + expect(port).toBe(3000); |
| 339 | + }); |
| 340 | + |
| 341 | + it('parses a hostname without a port', () => { |
| 342 | + const { address, port } = getPortAndAddress({ host: 'example.com' }); |
| 343 | + |
| 344 | + expect(address).toBe('example.com'); |
| 345 | + expect(port).toBeUndefined(); |
| 346 | + }); |
| 347 | + |
| 348 | + it('parses a fully-qualified hostname with a port', () => { |
| 349 | + const { address, port } = getPortAndAddress({ host: 'example.com:4000' }); |
| 350 | + |
| 351 | + expect(address).toBe('example.com'); |
| 352 | + expect(port).toBe(4000); |
| 353 | + }); |
| 354 | + |
| 355 | + it('handles an empty host string', () => { |
| 356 | + const { address, port } = getPortAndAddress({ host: '' }); |
| 357 | + |
| 358 | + expect(address).toBe(''); |
| 359 | + expect(port).toBeUndefined(); |
| 360 | + }); |
| 361 | + |
| 362 | + it('returns no address or port when host is absent', () => { |
| 363 | + const { address, port } = getPortAndAddress({}); |
| 364 | + |
| 365 | + expect(address).toBeUndefined(); |
| 366 | + expect(port).toBeUndefined(); |
| 367 | + }); |
| 368 | + }); |
| 369 | +}); |
0 commit comments