From 303c04f0eee16a060547ebef33d620d25ff5ba1a Mon Sep 17 00:00:00 2001 From: Serge Klochkov Date: Tue, 12 Nov 2024 00:00:01 +0100 Subject: [PATCH] Update the TLS tests --- .../client-node/__tests__/tls/tls.test.ts | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/packages/client-node/__tests__/tls/tls.test.ts b/packages/client-node/__tests__/tls/tls.test.ts index 2bd0be73..1e8c296e 100644 --- a/packages/client-node/__tests__/tls/tls.test.ts +++ b/packages/client-node/__tests__/tls/tls.test.ts @@ -5,6 +5,8 @@ import Http from 'http' import https from 'node:https' import type Stream from 'stream' import { createClient } from '../../src' +import Https from 'https' +import http from 'http' describe('[Node.js] TLS connection', () => { let client: ClickHouseClient @@ -138,13 +140,9 @@ describe('[Node.js] TLS connection', () => { expect(await resultSet.text()).toEqual('0\n1\n2\n') }) - describe('Custom HTTPS agent', () => { - let httpRequestStub: jasmine.Spy - beforeEach(() => { - httpRequestStub = spyOn(Http, 'request').and.callThrough() - }) - + fdescribe('Custom HTTPS agent', () => { it('should work with a custom HTTPS agent', async () => { + const httpsRequestStub = spyOn(Https, 'request').and.callThrough() const agent = new https.Agent({ maxFreeSockets: 5, ca: ca_cert, @@ -163,6 +161,26 @@ describe('[Node.js] TLS connection', () => { format: 'JSONEachRow', }) expect(await rs.json()).toEqual([{ result: 144 }]) + expect(httpsRequestStub).toHaveBeenCalledTimes(1) + const callArgs = httpsRequestStub.calls.mostRecent().args + expect(callArgs[1].agent).toBe(agent) + }) + + // does not really belong to the TLS test; keep it here for consistency + it('should work with a custom HTTP agent', async () => { + const httpRequestStub = spyOn(Http, 'request').and.callThrough() + const agent = new http.Agent({ + maxFreeSockets: 5, + }) + const client = createClient({ + url: 'http://localhost:8123', + http_agent: agent, + }) + const rs = await client.query({ + query: 'SELECT 144 AS result', + format: 'JSONEachRow', + }) + expect(await rs.json()).toEqual([{ result: 144 }]) expect(httpRequestStub).toHaveBeenCalledTimes(1) const callArgs = httpRequestStub.calls.mostRecent().args expect(callArgs[1].agent).toBe(agent)