-
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.
feat: support driver info for drivers wrapping the node driver
This allows drivers that wrap the node driver (e.g. Mongoose) report information about themselves in the client metadata generated by the driver.
- Loading branch information
Showing
4 changed files
with
77 additions
and
1 deletion.
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
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
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
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,50 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const mock = require('mongodb-mock-server'); | ||
|
||
describe('Client (unit)', function() { | ||
let server; | ||
|
||
afterEach(() => mock.cleanup()); | ||
beforeEach(() => { | ||
return mock.createServer().then(_server => (server = _server)); | ||
}); | ||
|
||
it('should let wrapping libraries amend the client metadata', function() { | ||
let handshake; | ||
server.setMessageHandler(request => { | ||
const doc = request.document; | ||
if (doc.ismaster) { | ||
handshake = doc; | ||
request.reply(Object.assign({}, mock.DEFAULT_ISMASTER)); | ||
} else if (doc.endSessions) { | ||
request.reply({ ok: 1 }); | ||
} | ||
}); | ||
|
||
const client = this.configuration.newClient(`mongodb://${server.uri()}/`, { | ||
useUnifiedTopology: true, | ||
driverInfo: { | ||
name: 'mongoose', | ||
version: '5.7.10', | ||
platform: 'llama edition' | ||
} | ||
}); | ||
|
||
return client.connect().then(() => { | ||
this.defer(() => client.close()); | ||
|
||
expect(handshake) | ||
.nested.property('client.driver') | ||
.to.deep.equal({ | ||
name: 'nodejs|mongoose', | ||
version: '3.3.4|5.7.10' | ||
}); | ||
|
||
expect(handshake) | ||
.nested.property('client.platform') | ||
.to.match(/llama edition/); | ||
}); | ||
}); | ||
}); |