|
2 | 2 | const os = require('os');
|
3 | 3 | const fs = require('fs');
|
4 | 4 | const { expect } = require('chai');
|
| 5 | +const { getSymbolFrom } = require('../tools/utils'); |
5 | 6 | const { parseOptions } = require('../../src/connection_string');
|
6 | 7 | const { ReadConcern } = require('../../src/read_concern');
|
7 | 8 | const { WriteConcern } = require('../../src/write_concern');
|
@@ -450,4 +451,87 @@ describe('MongoOptions', function () {
|
450 | 451 | );
|
451 | 452 | });
|
452 | 453 | });
|
| 454 | + |
| 455 | + describe('default options', () => { |
| 456 | + const doNotCheckEq = Symbol('do not check equality'); |
| 457 | + const KNOWN_DEFAULTS = [ |
| 458 | + ['connecttimeoutms', 30000], |
| 459 | + ['directconnection', false], |
| 460 | + ['forceserverobjectid', false], |
| 461 | + ['heartbeatfrequencyms', 10000], |
| 462 | + ['keepalive', true], |
| 463 | + ['keepaliveinitialdelay', 120000], |
| 464 | + ['localthresholdms', 15], |
| 465 | + ['logger', doNotCheckEq], |
| 466 | + ['maxidletimems', 0], |
| 467 | + ['maxpoolsize', 100], |
| 468 | + ['minpoolsize', 0], |
| 469 | + ['minheartbeatfrequencyms', 500], |
| 470 | + ['monitorcommands', false], // NODE-3513 |
| 471 | + ['nodelay', true], |
| 472 | + ['raw', false], |
| 473 | + ['retryreads', true], |
| 474 | + ['retrywrites', true], |
| 475 | + ['serverselectiontimeoutms', 30000], |
| 476 | + ['sockettimeoutms', 0], |
| 477 | + ['waitqueuetimeoutms', 0], |
| 478 | + ['zlibcompressionlevel', 0], |
| 479 | + |
| 480 | + // map to objects that are not worth checking deep equality |
| 481 | + ['compressors', doNotCheckEq], |
| 482 | + ['readpreference', doNotCheckEq], |
| 483 | + ['pkfactory', doNotCheckEq] |
| 484 | + ]; |
| 485 | + |
| 486 | + const findMatchingKey = (o, searchKey) => { |
| 487 | + return Object.keys(o).filter(key => { |
| 488 | + return key.toLowerCase() === searchKey; |
| 489 | + })[0]; |
| 490 | + }; |
| 491 | + |
| 492 | + it(`should define known defaults in client.options`, () => { |
| 493 | + const client = new MongoClient('mongodb://localhost'); |
| 494 | + const clientOptions = client.options; |
| 495 | + |
| 496 | + for (const [optionName, value] of KNOWN_DEFAULTS) { |
| 497 | + const camelCaseName = findMatchingKey(clientOptions, optionName); |
| 498 | + expect(camelCaseName, `did not find a camelcase match for ${optionName}`).to.be.a('string'); |
| 499 | + |
| 500 | + expect(clientOptions).to.have.property(camelCaseName); |
| 501 | + |
| 502 | + if (value !== doNotCheckEq) { |
| 503 | + expect(clientOptions).to.have.property(camelCaseName).that.deep.equals(value); |
| 504 | + } |
| 505 | + } |
| 506 | + }); |
| 507 | + |
| 508 | + it('set monitorCommands to false (NODE-3513)', function () { |
| 509 | + const client = new MongoClient('mongodb://localhost'); |
| 510 | + const clientOptions = client.options; |
| 511 | + |
| 512 | + expect(clientOptions).to.have.property('monitorCommands', false); |
| 513 | + expect(client.s.options).to.have.property('monitorCommands', false); |
| 514 | + expect(client).to.have.property('monitorCommands', false); |
| 515 | + const optionsSym = getSymbolFrom(client, 'options'); |
| 516 | + expect(client[optionsSym]).to.have.property('monitorCommands', false); |
| 517 | + }); |
| 518 | + |
| 519 | + it('respects monitorCommands option passed in', function () { |
| 520 | + const clientViaOpt = new MongoClient('mongodb://localhost', { monitorCommands: true }); |
| 521 | + const clientViaUri = new MongoClient('mongodb://localhost?monitorCommands=true'); |
| 522 | + |
| 523 | + const testTable = [ |
| 524 | + [clientViaOpt, clientViaOpt.options], |
| 525 | + [clientViaUri, clientViaUri.options] |
| 526 | + ]; |
| 527 | + |
| 528 | + for (const [client, clientOptions] of testTable) { |
| 529 | + expect(clientOptions).to.have.property('monitorCommands', true); |
| 530 | + expect(client.s.options).to.have.property('monitorCommands', true); |
| 531 | + expect(client).to.have.property('monitorCommands', true); |
| 532 | + const optionsSym = getSymbolFrom(client, 'options'); |
| 533 | + expect(client[optionsSym]).to.have.property('monitorCommands', true); |
| 534 | + } |
| 535 | + }); |
| 536 | + }); |
453 | 537 | });
|
0 commit comments