Skip to content

Commit 2caa029

Browse files
nicohrubecclaude
andcommitted
test(server-utils): Port getPortAndAddress tests to orchestrion firebase
`getPortAndAddress` is a line-for-line port of the OTel firestore parser but its 9-case unit suite wasn't ported alongside it. Bring the IPv4/IPv6/host edge cases over, plus a missing-`host` case the guard clause handles. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent e2c7dcc commit 2caa029

1 file changed

Lines changed: 77 additions & 0 deletions

File tree

packages/server-utils/test/orchestrion/firebase.test.ts

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
setAsyncContextStrategy,
1010
} from '@sentry/core';
1111
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, type MockInstance, vi } from 'vitest';
12+
import { getPortAndAddress } from '../../src/integrations/tracing-channel/firebase/firestore';
1213
import { firebaseChannelIntegration } from '../../src/orchestrion';
1314
import { CHANNELS } from '../../src/orchestrion/channels';
1415

@@ -290,3 +291,79 @@ describe('firebaseChannelIntegration', () => {
290291
});
291292
});
292293
});
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

Comments
 (0)