|
| 1 | +import { describe, it, strict } from 'poku'; |
| 2 | +import tracing from '../../lib/tracing.js'; |
| 3 | + |
| 4 | +const { dc, hasTracingChannel } = tracing; |
| 5 | + |
| 6 | +await describe('Tracing module', async () => { |
| 7 | + await it('should load diagnostics_channel', () => { |
| 8 | + // dc should be defined on Node.js versions that support diagnostics_channel |
| 9 | + strict.ok( |
| 10 | + dc !== undefined, |
| 11 | + 'diagnostics_channel should be available' |
| 12 | + ); |
| 13 | + }); |
| 14 | + |
| 15 | + await it('should detect TracingChannel support', () => { |
| 16 | + if (typeof dc?.tracingChannel === 'function') { |
| 17 | + strict.ok(hasTracingChannel, 'hasTracingChannel should be true when tracingChannel exists'); |
| 18 | + strict.ok(tracing.queryChannel !== undefined, 'queryChannel should be defined'); |
| 19 | + strict.ok(tracing.executeChannel !== undefined, 'executeChannel should be defined'); |
| 20 | + strict.ok(tracing.connectChannel !== undefined, 'connectChannel should be defined'); |
| 21 | + strict.ok(tracing.poolConnectChannel !== undefined, 'poolConnectChannel should be defined'); |
| 22 | + } else { |
| 23 | + strict.ok(!hasTracingChannel, 'hasTracingChannel should be false when tracingChannel is unavailable'); |
| 24 | + strict.strictEqual(tracing.queryChannel, undefined, 'queryChannel should be undefined'); |
| 25 | + strict.strictEqual(tracing.executeChannel, undefined, 'executeChannel should be undefined'); |
| 26 | + strict.strictEqual(tracing.connectChannel, undefined, 'connectChannel should be undefined'); |
| 27 | + strict.strictEqual(tracing.poolConnectChannel, undefined, 'poolConnectChannel should be undefined'); |
| 28 | + } |
| 29 | + }); |
| 30 | + |
| 31 | + await it('should return server context for host/port', () => { |
| 32 | + const ctx = tracing.getServerContext({ host: '127.0.0.1', port: 3307 }); |
| 33 | + strict.strictEqual(ctx.serverAddress, '127.0.0.1'); |
| 34 | + strict.strictEqual(ctx.serverPort, 3307); |
| 35 | + }); |
| 36 | + |
| 37 | + await it('should return server context for socketPath', () => { |
| 38 | + const ctx = tracing.getServerContext({ socketPath: '/tmp/mysql.sock' }); |
| 39 | + strict.strictEqual(ctx.serverAddress, '/tmp/mysql.sock'); |
| 40 | + strict.strictEqual(ctx.serverPort, undefined); |
| 41 | + }); |
| 42 | + |
| 43 | + await it('should default to localhost:3306', () => { |
| 44 | + const ctx = tracing.getServerContext({}); |
| 45 | + strict.strictEqual(ctx.serverAddress, 'localhost'); |
| 46 | + strict.strictEqual(ctx.serverPort, 3306); |
| 47 | + }); |
| 48 | +}); |
0 commit comments