-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
7791031
commit eaca929
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
test/integration/server-discovery-and-monitoring/server_description.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { type ChildProcess, spawn } from 'node:child_process'; | ||
|
||
import { expect } from 'chai'; | ||
|
||
import { MongoClient } from '../../mongodb'; | ||
|
||
describe('class ServerDescription', function () { | ||
describe('when connecting to mongocryptd', { requires: { mongodb: '>=4.4' } }, function () { | ||
let client: MongoClient; | ||
const mongocryptdTestPort = '27022'; | ||
let childProcess: ChildProcess; | ||
|
||
beforeEach(async function () { | ||
childProcess = spawn('mongocryptd', ['--port', mongocryptdTestPort, '--ipv6'], { | ||
stdio: 'ignore', | ||
detached: true | ||
}); | ||
|
||
childProcess.on('error', error => console.warn(this.currentTest?.fullTitle(), error)); | ||
client = new MongoClient(`mongodb://localhost:${mongocryptdTestPort}`); | ||
}); | ||
|
||
afterEach(async function () { | ||
await client?.close(); | ||
childProcess.kill('SIGKILL'); | ||
}); | ||
|
||
it('iscryptd is set to true ', async function () { | ||
const descriptions = []; | ||
client.on('serverDescriptionChanged', description => descriptions.push(description)); | ||
const hello = await client.db().command({ hello: true }); | ||
expect(hello).to.have.property('iscryptd', true); | ||
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', true); | ||
}); | ||
}); | ||
|
||
describe('when connecting to anything other than mongocryptd', function () { | ||
let client: MongoClient; | ||
|
||
beforeEach(async function () { | ||
client = this.configuration.newClient(); | ||
}); | ||
|
||
afterEach(async function () { | ||
await client?.close(); | ||
}); | ||
|
||
it('iscryptd is set to false ', async function () { | ||
const descriptions = []; | ||
client.on('serverDescriptionChanged', description => descriptions.push(description)); | ||
const hello = await client.db().command({ hello: true }); | ||
expect(hello).to.not.have.property('iscryptd'); | ||
expect(descriptions.at(-1)).to.have.nested.property('newDescription.iscryptd', false); | ||
}); | ||
}); | ||
}); |