Skip to content

Commit 6c0fc50

Browse files
Requested changes, team review
1 parent f2314a9 commit 6c0fc50

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

src/connection_string.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
ServerApiVersion
2424
} from './mongo_client';
2525
import {
26-
type MongoDBLogWritable,
2726
MongoLoggableComponent,
2827
MongoLogger,
2928
type MongoLoggerEnvOptions,
@@ -1251,7 +1250,10 @@ export const OPTIONS = {
12511250
if (
12521251
!(
12531252
(typeof value === 'string' && ['stderr', 'stdout'].includes(value)) ||
1254-
(typeof value === 'object' && typeof (value as MongoDBLogWritable)?.write === 'function')
1253+
(value &&
1254+
typeof value === 'object' &&
1255+
'write' in value &&
1256+
typeof value.write === 'function')
12551257
)
12561258
) {
12571259
throw new MongoAPIError(

test/unit/mongo_client.test.js

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,10 +1045,13 @@ describe('MongoOptions', function () {
10451045
});
10461046

10471047
context('when invalid environment option is provided', function () {
1048+
afterEach(function () {
1049+
process.env['MONGODB_LOG_ALL'] = 'undefined';
1050+
});
1051+
10481052
it('should still throw error at construction', function () {
10491053
process.env['MONGODB_LOG_ALL'] = 'imFakeToo';
10501054
expect(badClientCreator).to.throw(MongoAPIError);
1051-
process.env['MONGODB_LOG_ALL'] = 'undefined';
10521055
});
10531056
});
10541057
});
@@ -1099,14 +1102,14 @@ describe('MongoOptions', function () {
10991102
describe('mongodbLogMaxDocumentLength', function () {
11001103
context('when mongodbLogMaxDocumentLength is in options', function () {
11011104
context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided', function () {
1102-
it('it stores value for maxDocumentLength correctly', function () {
1105+
it('should store value for maxDocumentLength correctly', function () {
11031106
const client = new MongoClient('mongodb://a/', {
11041107
[loggerFeatureFlag]: true,
11051108
mongodbLogMaxDocumentLength: 290
11061109
});
11071110
expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(290);
11081111
});
1109-
it('it throws error for negative input', function () {
1112+
it('should throw error for negative input', function () {
11101113
expect(
11111114
() =>
11121115
new MongoClient('mongodb://a/', {
@@ -1117,23 +1120,61 @@ describe('MongoOptions', function () {
11171120
});
11181121
});
11191122
context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is provided', function () {
1120-
it('it stores value for maxDocumentLength correctly (client option value takes precedence)', function () {
1123+
beforeEach(function () {
11211124
process.env['MONGODB_LOG_MAX_DOCUMENT_LENGTH'] = '155';
1125+
});
1126+
1127+
afterEach(function () {
1128+
process.env['MONGODB_LOG_MAX_DOCUMENT_LENGTH'] = undefined;
1129+
});
1130+
1131+
it('should store value for maxDocumentLength correctly (client option value takes precedence)', function () {
11221132
const client = new MongoClient('mongodb://a/', {
11231133
[loggerFeatureFlag]: true,
11241134
mongodbLogMaxDocumentLength: 290
11251135
});
11261136
expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(290);
1127-
process.env['MONGODB_LOG_MAX_DOCUMENT_LENGTH'] = undefined;
1137+
});
1138+
it('should throw error for negative input', function () {
1139+
expect(
1140+
() =>
1141+
new MongoClient('mongodb://a/', {
1142+
[loggerFeatureFlag]: true,
1143+
mongodbLogMaxDocumentLength: -290
1144+
})
1145+
).to.throw(MongoParseError);
11281146
});
11291147
});
11301148
});
11311149
context('when mongodbLogMaxDocumentLength is not in options', function () {
1132-
it('it stores value for default maxDocumentLength correctly', function () {
1133-
const client = new MongoClient('mongodb://a/', {
1134-
[loggerFeatureFlag]: true
1150+
context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is not provided', function () {
1151+
it('should store value for default maxDocumentLength correctly', function () {
1152+
const client = new MongoClient('mongodb://a/', {
1153+
[loggerFeatureFlag]: true
1154+
});
1155+
expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000);
1156+
});
1157+
});
1158+
context('when env option for MONGODB_LOG_MAX_DOCUMENT_LENGTH is provided', function () {
1159+
afterEach(function () {
1160+
process.env['MONGODB_LOG_MAX_DOCUMENT_LENGTH'] = undefined;
1161+
});
1162+
1163+
it('should store value for maxDocumentLength correctly', function () {
1164+
process.env['MONGODB_LOG_MAX_DOCUMENT_LENGTH'] = '155';
1165+
const client = new MongoClient('mongodb://a/', {
1166+
[loggerFeatureFlag]: true
1167+
});
1168+
expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(155);
1169+
});
1170+
1171+
it('should not throw error for negative MONGODB_MAX_DOCUMENT_LENGTH and set to default', function () {
1172+
process.env['MONGODB_LOG_MAX_DOCUMENT_LENGTH'] = '-14';
1173+
const client = new MongoClient('mongodb://a/', {
1174+
[loggerFeatureFlag]: true
1175+
});
1176+
expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000);
11351177
});
1136-
expect(client.options.mongoLoggerOptions.maxDocumentLength).to.equal(1000);
11371178
});
11381179
});
11391180
});

0 commit comments

Comments
 (0)