|
| 1 | +import { type ChildProcess, spawn } from 'node:child_process'; |
| 2 | + |
| 3 | +import { expect } from 'chai'; |
| 4 | + |
| 5 | +import { MongoClient } from '../../mongodb'; |
| 6 | + |
| 7 | +describe('class ServerDescription', function () { |
| 8 | + describe('when connecting to mongocryptd', { requires: { mongodb: '>=4.4' } }, function () { |
| 9 | + let client: MongoClient; |
| 10 | + const mongocryptdTestPort = '27022'; |
| 11 | + let childProcess: ChildProcess; |
| 12 | + |
| 13 | + beforeEach(async function () { |
| 14 | + childProcess = spawn('mongocryptd', ['--port', mongocryptdTestPort, '--ipv6'], { |
| 15 | + stdio: 'ignore', |
| 16 | + detached: true |
| 17 | + }); |
| 18 | + |
| 19 | + childProcess.on('error', error => console.warn(this.currentTest?.fullTitle(), error)); |
| 20 | + client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}`); |
| 21 | + }); |
| 22 | + |
| 23 | + afterEach(async function () { |
| 24 | + await client?.close(); |
| 25 | + childProcess.kill('SIGKILL'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('iscryptd is set to true ', async function () { |
| 29 | + const descriptions = []; |
| 30 | + client.on('serverDescriptionChanged', description => descriptions.push(description)); |
| 31 | + const hello = await client.db().command({ hello: true }); |
| 32 | + expect(hello).to.have.property('iscryptd', true); |
| 33 | + expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', true); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('when connecting to anything other than mongocryptd', function () { |
| 38 | + let client: MongoClient; |
| 39 | + |
| 40 | + beforeEach(async function () { |
| 41 | + client = this.configuration.newClient(); |
| 42 | + }); |
| 43 | + |
| 44 | + afterEach(async function () { |
| 45 | + await client?.close(); |
| 46 | + }); |
| 47 | + |
| 48 | + it('iscryptd is set to false ', async function () { |
| 49 | + const descriptions = []; |
| 50 | + client.on('serverDescriptionChanged', description => descriptions.push(description)); |
| 51 | + const hello = await client.db().command({ hello: true }); |
| 52 | + expect(hello).to.not.have.property('iscryptd'); |
| 53 | + expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', false); |
| 54 | + }); |
| 55 | + }); |
| 56 | +}); |
0 commit comments