Skip to content

Commit 98cc676

Browse files
fix tests
1 parent 916f78b commit 98cc676

File tree

2 files changed

+42
-64
lines changed

2 files changed

+42
-64
lines changed

test/unit/cmap/handshake/client_metadata.test.ts

Lines changed: 40 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('client metadata module', () => {
142142
describe('makeClientMetadata()', () => {
143143
context('when no FAAS environment is detected', () => {
144144
it('does not append FAAS metadata', () => {
145-
const metadata = makeClientMetadata({ additionalDriverInfo: [{}] });
145+
const metadata = makeClientMetadata([], {});
146146
expect(metadata).not.to.have.property(
147147
'env',
148148
'faas metadata applied in a non-faas environment'
@@ -165,18 +165,14 @@ describe('client metadata module', () => {
165165

166166
context('when driverInfo.platform is provided', () => {
167167
it('throws an error if driverInfo.platform is too large', () => {
168-
expect(() =>
169-
makeClientMetadata({
170-
additionalDriverInfo: [{ platform: 'a'.repeat(512) }]
171-
})
172-
).to.throw(MongoInvalidArgumentError, /platform/);
168+
expect(() => makeClientMetadata([{ platform: 'a'.repeat(512) }], {})).to.throw(
169+
MongoInvalidArgumentError,
170+
/platform/
171+
);
173172
});
174173

175174
it('appends driverInfo.platform to the platform field', () => {
176-
const options = {
177-
additionalDriverInfo: [{ platform: 'myPlatform' }]
178-
};
179-
const metadata = makeClientMetadata(options);
175+
const metadata = makeClientMetadata([{ platform: 'myPlatform' }], {});
180176
expect(metadata).to.deep.equal({
181177
driver: {
182178
name: 'nodejs',
@@ -195,13 +191,14 @@ describe('client metadata module', () => {
195191

196192
context('when driverInfo.name is provided', () => {
197193
it('throws an error if driverInfo.name is too large', () => {
198-
expect(() =>
199-
makeClientMetadata({ additionalDriverInfo: [{ name: 'a'.repeat(512) }] })
200-
).to.throw(MongoInvalidArgumentError, /name/);
194+
expect(() => makeClientMetadata([{ name: 'a'.repeat(512) }], {})).to.throw(
195+
MongoInvalidArgumentError,
196+
/name/
197+
);
201198
});
202199

203200
it('appends driverInfo.name to the driver.name field', () => {
204-
const metadata = makeClientMetadata({ additionalDriverInfo: [{ name: 'myName' }] });
201+
const metadata = makeClientMetadata([{ name: 'myName' }], {});
205202
expect(metadata).to.deep.equal({
206203
driver: {
207204
name: 'nodejs|myName',
@@ -220,15 +217,14 @@ describe('client metadata module', () => {
220217

221218
context('when driverInfo.version is provided', () => {
222219
it('throws an error if driverInfo.version is too large', () => {
223-
expect(() =>
224-
makeClientMetadata({ additionalDriverInfo: [{ version: 'a'.repeat(512) }] })
225-
).to.throw(MongoInvalidArgumentError, /version/);
220+
expect(() => makeClientMetadata([{ version: 'a'.repeat(512) }], {})).to.throw(
221+
MongoInvalidArgumentError,
222+
/version/
223+
);
226224
});
227225

228226
it('appends driverInfo.version to the version field', () => {
229-
const metadata = makeClientMetadata({
230-
additionalDriverInfo: [{ version: 'myVersion' }]
231-
});
227+
const metadata = makeClientMetadata([{ version: 'myVersion' }], {});
232228
expect(metadata).to.deep.equal({
233229
driver: {
234230
name: 'nodejs',
@@ -246,7 +242,7 @@ describe('client metadata module', () => {
246242
});
247243

248244
context('when no custom driverInto is provided', () => {
249-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
245+
const metadata = makeClientMetadata([], {});
250246

251247
it('does not append the driver info to the metadata', () => {
252248
expect(metadata).to.deep.equal({
@@ -272,9 +268,8 @@ describe('client metadata module', () => {
272268
context('when app name is provided', () => {
273269
context('when the app name is over 128 bytes', () => {
274270
const longString = 'a'.repeat(300);
275-
const metadata = makeClientMetadata({
276-
appName: longString,
277-
additionalDriverInfo: []
271+
const metadata = makeClientMetadata([], {
272+
appName: longString
278273
});
279274

280275
it('truncates the application name to <=128 bytes', () => {
@@ -290,9 +285,8 @@ describe('client metadata module', () => {
290285
'TODO(NODE-5150): fix appName truncation when multi-byte unicode charaters straddle byte 128',
291286
() => {
292287
const longString = '€'.repeat(300);
293-
const metadata = makeClientMetadata({
294-
appName: longString,
295-
additionalDriverInfo: []
288+
const metadata = makeClientMetadata([], {
289+
appName: longString
296290
});
297291

298292
it('truncates the application name to 129 bytes', () => {
@@ -306,9 +300,8 @@ describe('client metadata module', () => {
306300
);
307301

308302
context('when the app name is under 128 bytes', () => {
309-
const metadata = makeClientMetadata({
310-
appName: 'myApplication',
311-
additionalDriverInfo: []
303+
const metadata = makeClientMetadata([], {
304+
appName: 'myApplication'
312305
});
313306

314307
it('sets the application name to the value', () => {
@@ -325,39 +318,37 @@ describe('client metadata module', () => {
325318

326319
it('sets platform to Deno', () => {
327320
globalThis.Deno = { version: { deno: '1.2.3' } };
328-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
321+
const metadata = makeClientMetadata([], {});
329322
expect(metadata.platform).to.equal('Deno v1.2.3, LE');
330323
});
331324

332325
it('sets platform to Deno with driverInfo.platform', () => {
333326
globalThis.Deno = { version: { deno: '1.2.3' } };
334-
const metadata = makeClientMetadata({
335-
additionalDriverInfo: [{ platform: 'myPlatform' }]
336-
});
327+
const metadata = makeClientMetadata([{ platform: 'myPlatform' }], {});
337328
expect(metadata.platform).to.equal('Deno v1.2.3, LE|myPlatform');
338329
});
339330

340331
it('ignores version if Deno.version.deno is not a string', () => {
341332
globalThis.Deno = { version: { deno: 1 } };
342-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
333+
const metadata = makeClientMetadata([], {});
343334
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
344335
});
345336

346337
it('ignores version if Deno.version does not have a deno property', () => {
347338
globalThis.Deno = { version: { somethingElse: '1.2.3' } };
348-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
339+
const metadata = makeClientMetadata([], {});
349340
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
350341
});
351342

352343
it('ignores version if Deno.version is null', () => {
353344
globalThis.Deno = { version: null };
354-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
345+
const metadata = makeClientMetadata([], {});
355346
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
356347
});
357348

358349
it('ignores version if Deno is nullish', () => {
359350
globalThis.Deno = null;
360-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
351+
const metadata = makeClientMetadata([], {});
361352
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
362353
});
363354
});
@@ -371,43 +362,37 @@ describe('client metadata module', () => {
371362
globalThis.Bun = class {
372363
static version = '1.2.3';
373364
};
374-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
365+
const metadata = makeClientMetadata([], {});
375366
expect(metadata.platform).to.equal('Bun v1.2.3, LE');
376367
});
377368

378369
it('sets platform to Bun with driverInfo.platform', () => {
379370
globalThis.Bun = class {
380371
static version = '1.2.3';
381372
};
382-
const metadata = makeClientMetadata({
383-
additionalDriverInfo: [{ platform: 'myPlatform' }]
384-
});
373+
const metadata = makeClientMetadata([{ platform: 'myPlatform' }], {});
385374
expect(metadata.platform).to.equal('Bun v1.2.3, LE|myPlatform');
386375
});
387376

388377
it('ignores version if Bun.version is not a string', () => {
389378
globalThis.Bun = class {
390379
static version = 1;
391380
};
392-
const metadata = makeClientMetadata({ additionalDriverInfo: [] });
381+
const metadata = makeClientMetadata([], {});
393382
expect(metadata.platform).to.equal('Bun v0.0.0-unknown, LE');
394383
});
395384

396385
it('ignores version if Bun.version is not a string and sets driverInfo.platform', () => {
397386
globalThis.Bun = class {
398387
static version = 1;
399388
};
400-
const metadata = makeClientMetadata({
401-
additionalDriverInfo: [{ platform: 'myPlatform' }]
402-
});
389+
const metadata = makeClientMetadata([{ platform: 'myPlatform' }], {});
403390
expect(metadata.platform).to.equal('Bun v0.0.0-unknown, LE|myPlatform');
404391
});
405392

406393
it('ignores version if Bun is nullish', () => {
407394
globalThis.Bun = null;
408-
const metadata = makeClientMetadata({
409-
additionalDriverInfo: [{ platform: 'myPlatform' }]
410-
});
395+
const metadata = makeClientMetadata([{ platform: 'myPlatform' }], {});
411396
expect(metadata.platform).to.equal('Bun v0.0.0-unknown, LE|myPlatform');
412397
});
413398
});
@@ -528,7 +513,7 @@ describe('client metadata module', () => {
528513
});
529514

530515
it(`returns ${inspect(outcome)} under env property`, () => {
531-
const { env } = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
516+
const { env } = makeClientMetadata([], {});
532517
expect(env).to.deep.equal(outcome);
533518
});
534519

@@ -552,9 +537,7 @@ describe('client metadata module', () => {
552537
});
553538

554539
it('does not attach it to the metadata', () => {
555-
expect(
556-
makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] })
557-
).not.to.have.nested.property('aws.memory_mb');
540+
expect(makeClientMetadata([], {})).not.to.have.nested.property('aws.memory_mb');
558541
});
559542
});
560543
});
@@ -569,7 +552,7 @@ describe('client metadata module', () => {
569552
});
570553

571554
it('only includes env.name', () => {
572-
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
555+
const metadata = makeClientMetadata([], {});
573556
expect(metadata).to.not.have.nested.property('env.region');
574557
expect(metadata).to.have.nested.property('env.name', 'aws.lambda');
575558
expect(metadata.env).to.have.all.keys('name');
@@ -587,7 +570,7 @@ describe('client metadata module', () => {
587570
});
588571

589572
it('only includes env.name', () => {
590-
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
573+
const metadata = makeClientMetadata([], {});
591574
expect(metadata).to.have.property('env');
592575
expect(metadata).to.have.nested.property('env.region', 'abc');
593576
expect(metadata.os).to.have.all.keys('type');
@@ -604,7 +587,7 @@ describe('client metadata module', () => {
604587
});
605588

606589
it('omits os information', () => {
607-
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
590+
const metadata = makeClientMetadata([], {});
608591
expect(metadata).to.not.have.property('os');
609592
});
610593
});
@@ -620,10 +603,7 @@ describe('client metadata module', () => {
620603
});
621604

622605
it('omits the faas env', () => {
623-
const metadata = makeClientMetadata({
624-
driverInfo: { name: 'a'.repeat(350) },
625-
additionalDriverInfo: []
626-
});
606+
const metadata = makeClientMetadata([{ name: 'a'.repeat(350) }], {});
627607
expect(metadata).to.not.have.property('env');
628608
});
629609
});

test/unit/sdam/topology.test.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ describe('Topology (unit)', function () {
5353

5454
it('should correctly pass appname', function () {
5555
const server: Topology = topologyWithPlaceholderClient([`localhost:27017`], {
56-
metadata: makeClientMetadata({
57-
appName: 'My application name',
58-
driverInfo: {},
59-
additionalDriverInfo: []
56+
metadata: makeClientMetadata([], {
57+
appName: 'My application name'
6058
})
6159
});
6260

0 commit comments

Comments
 (0)