Skip to content

Commit

Permalink
Update the TLS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
slvrtrn committed Nov 11, 2024
1 parent 452ec60 commit 303c04f
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions packages/client-node/__tests__/tls/tls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Stream.Readable>
Expand Down Expand Up @@ -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<typeof Http.request>
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,
Expand All @@ -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)
Expand Down

0 comments on commit 303c04f

Please sign in to comment.