Skip to content

Commit ecb63b5

Browse files
committed
test: fix unit tests
1 parent d84af5c commit ecb63b5

File tree

1 file changed

+60
-37
lines changed

1 file changed

+60
-37
lines changed

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

Lines changed: 60 additions & 37 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({ driverInfo: {} });
145+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
146146
expect(metadata).not.to.have.property(
147147
'env',
148148
'faas metadata applied in a non-faas environment'
@@ -165,15 +165,18 @@ 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(() => makeClientMetadata({ driverInfo: { platform: 'a'.repeat(512) } })).to.throw(
169-
MongoInvalidArgumentError,
170-
/platform/
171-
);
168+
expect(() =>
169+
makeClientMetadata({
170+
driverInfo: { platform: 'a'.repeat(512) },
171+
additionalDriverInfo: []
172+
})
173+
).to.throw(MongoInvalidArgumentError, /platform/);
172174
});
173175

174176
it('appends driverInfo.platform to the platform field', () => {
175177
const options = {
176-
driverInfo: { platform: 'myPlatform' }
178+
driverInfo: { platform: 'myPlatform' },
179+
additionalDriverInfo: []
177180
};
178181
const metadata = makeClientMetadata(options);
179182
expect(metadata).to.deep.equal({
@@ -194,15 +197,15 @@ describe('client metadata module', () => {
194197

195198
context('when driverInfo.name is provided', () => {
196199
it('throws an error if driverInfo.name is too large', () => {
197-
expect(() => makeClientMetadata({ driverInfo: { name: 'a'.repeat(512) } })).to.throw(
198-
MongoInvalidArgumentError,
199-
/name/
200-
);
200+
expect(() =>
201+
makeClientMetadata({ driverInfo: { name: 'a'.repeat(512) }, additionalDriverInfo: [] })
202+
).to.throw(MongoInvalidArgumentError, /name/);
201203
});
202204

203205
it('appends driverInfo.name to the driver.name field', () => {
204206
const options = {
205-
driverInfo: { name: 'myName' }
207+
driverInfo: { name: 'myName' },
208+
additionalDriverInfo: []
206209
};
207210
const metadata = makeClientMetadata(options);
208211
expect(metadata).to.deep.equal({
@@ -223,15 +226,15 @@ describe('client metadata module', () => {
223226

224227
context('when driverInfo.version is provided', () => {
225228
it('throws an error if driverInfo.version is too large', () => {
226-
expect(() => makeClientMetadata({ driverInfo: { version: 'a'.repeat(512) } })).to.throw(
227-
MongoInvalidArgumentError,
228-
/version/
229-
);
229+
expect(() =>
230+
makeClientMetadata({ driverInfo: { version: 'a'.repeat(512) }, additionalDriverInfo: [] })
231+
).to.throw(MongoInvalidArgumentError, /version/);
230232
});
231233

232234
it('appends driverInfo.version to the version field', () => {
233235
const options = {
234-
driverInfo: { version: 'myVersion' }
236+
driverInfo: { version: 'myVersion' },
237+
additionalDriverInfo: []
235238
};
236239
const metadata = makeClientMetadata(options);
237240
expect(metadata).to.deep.equal({
@@ -251,7 +254,7 @@ describe('client metadata module', () => {
251254
});
252255

253256
context('when no custom driverInto is provided', () => {
254-
const metadata = makeClientMetadata({ driverInfo: {} });
257+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
255258

256259
it('does not append the driver info to the metadata', () => {
257260
expect(metadata).to.deep.equal({
@@ -279,7 +282,8 @@ describe('client metadata module', () => {
279282
const longString = 'a'.repeat(300);
280283
const options = {
281284
appName: longString,
282-
driverInfo: {}
285+
driverInfo: {},
286+
additionalDriverInfo: []
283287
};
284288
const metadata = makeClientMetadata(options);
285289

@@ -298,7 +302,8 @@ describe('client metadata module', () => {
298302
const longString = '€'.repeat(300);
299303
const options = {
300304
appName: longString,
301-
driverInfo: {}
305+
driverInfo: {},
306+
additionalDriverInfo: []
302307
};
303308
const metadata = makeClientMetadata(options);
304309

@@ -315,7 +320,8 @@ describe('client metadata module', () => {
315320
context('when the app name is under 128 bytes', () => {
316321
const options = {
317322
appName: 'myApplication',
318-
driverInfo: {}
323+
driverInfo: {},
324+
additionalDriverInfo: []
319325
};
320326
const metadata = makeClientMetadata(options);
321327

@@ -333,37 +339,40 @@ describe('client metadata module', () => {
333339

334340
it('sets platform to Deno', () => {
335341
globalThis.Deno = { version: { deno: '1.2.3' } };
336-
const metadata = makeClientMetadata({ driverInfo: {} });
342+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
337343
expect(metadata.platform).to.equal('Deno v1.2.3, LE');
338344
});
339345

340346
it('sets platform to Deno with driverInfo.platform', () => {
341347
globalThis.Deno = { version: { deno: '1.2.3' } };
342-
const metadata = makeClientMetadata({ driverInfo: { platform: 'myPlatform' } });
348+
const metadata = makeClientMetadata({
349+
driverInfo: { platform: 'myPlatform' },
350+
additionalDriverInfo: []
351+
});
343352
expect(metadata.platform).to.equal('Deno v1.2.3, LE|myPlatform');
344353
});
345354

346355
it('ignores version if Deno.version.deno is not a string', () => {
347356
globalThis.Deno = { version: { deno: 1 } };
348-
const metadata = makeClientMetadata({ driverInfo: {} });
357+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
349358
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
350359
});
351360

352361
it('ignores version if Deno.version does not have a deno property', () => {
353362
globalThis.Deno = { version: { somethingElse: '1.2.3' } };
354-
const metadata = makeClientMetadata({ driverInfo: {} });
363+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
355364
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
356365
});
357366

358367
it('ignores version if Deno.version is null', () => {
359368
globalThis.Deno = { version: null };
360-
const metadata = makeClientMetadata({ driverInfo: {} });
369+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
361370
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
362371
});
363372

364373
it('ignores version if Deno is nullish', () => {
365374
globalThis.Deno = null;
366-
const metadata = makeClientMetadata({ driverInfo: {} });
375+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
367376
expect(metadata.platform).to.equal('Deno v0.0.0-unknown, LE');
368377
});
369378
});
@@ -377,37 +386,46 @@ describe('client metadata module', () => {
377386
globalThis.Bun = class {
378387
static version = '1.2.3';
379388
};
380-
const metadata = makeClientMetadata({ driverInfo: {} });
389+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
381390
expect(metadata.platform).to.equal('Bun v1.2.3, LE');
382391
});
383392

384393
it('sets platform to Bun with driverInfo.platform', () => {
385394
globalThis.Bun = class {
386395
static version = '1.2.3';
387396
};
388-
const metadata = makeClientMetadata({ driverInfo: { platform: 'myPlatform' } });
397+
const metadata = makeClientMetadata({
398+
driverInfo: { platform: 'myPlatform' },
399+
additionalDriverInfo: []
400+
});
389401
expect(metadata.platform).to.equal('Bun v1.2.3, LE|myPlatform');
390402
});
391403

392404
it('ignores version if Bun.version is not a string', () => {
393405
globalThis.Bun = class {
394406
static version = 1;
395407
};
396-
const metadata = makeClientMetadata({ driverInfo: {} });
408+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
397409
expect(metadata.platform).to.equal('Bun v0.0.0-unknown, LE');
398410
});
399411

400412
it('ignores version if Bun.version is not a string and sets driverInfo.platform', () => {
401413
globalThis.Bun = class {
402414
static version = 1;
403415
};
404-
const metadata = makeClientMetadata({ driverInfo: { platform: 'myPlatform' } });
416+
const metadata = makeClientMetadata({
417+
driverInfo: { platform: 'myPlatform' },
418+
additionalDriverInfo: []
419+
});
405420
expect(metadata.platform).to.equal('Bun v0.0.0-unknown, LE|myPlatform');
406421
});
407422

408423
it('ignores version if Bun is nullish', () => {
409424
globalThis.Bun = null;
410-
const metadata = makeClientMetadata({ driverInfo: { platform: 'myPlatform' } });
425+
const metadata = makeClientMetadata({
426+
driverInfo: { platform: 'myPlatform' },
427+
additionalDriverInfo: []
428+
});
411429
expect(metadata.platform).to.equal('Bun v0.0.0-unknown, LE|myPlatform');
412430
});
413431
});
@@ -528,7 +546,7 @@ describe('client metadata module', () => {
528546
});
529547

530548
it(`returns ${inspect(outcome)} under env property`, () => {
531-
const { env } = makeClientMetadata({ driverInfo: {} });
549+
const { env } = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
532550
expect(env).to.deep.equal(outcome);
533551
});
534552

@@ -552,7 +570,9 @@ describe('client metadata module', () => {
552570
});
553571

554572
it('does not attach it to the metadata', () => {
555-
expect(makeClientMetadata({ driverInfo: {} })).not.to.have.nested.property('aws.memory_mb');
573+
expect(
574+
makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] })
575+
).not.to.have.nested.property('aws.memory_mb');
556576
});
557577
});
558578
});
@@ -567,7 +587,7 @@ describe('client metadata module', () => {
567587
});
568588

569589
it('only includes env.name', () => {
570-
const metadata = makeClientMetadata({ driverInfo: {} });
590+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
571591
expect(metadata).to.not.have.nested.property('env.region');
572592
expect(metadata).to.have.nested.property('env.name', 'aws.lambda');
573593
expect(metadata.env).to.have.all.keys('name');
@@ -585,7 +605,7 @@ describe('client metadata module', () => {
585605
});
586606

587607
it('only includes env.name', () => {
588-
const metadata = makeClientMetadata({ driverInfo: {} });
608+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
589609
expect(metadata).to.have.property('env');
590610
expect(metadata).to.have.nested.property('env.region', 'abc');
591611
expect(metadata.os).to.have.all.keys('type');
@@ -602,7 +622,7 @@ describe('client metadata module', () => {
602622
});
603623

604624
it('omits os information', () => {
605-
const metadata = makeClientMetadata({ driverInfo: {} });
625+
const metadata = makeClientMetadata({ driverInfo: {}, additionalDriverInfo: [] });
606626
expect(metadata).to.not.have.property('os');
607627
});
608628
});
@@ -618,7 +638,10 @@ describe('client metadata module', () => {
618638
});
619639

620640
it('omits the faas env', () => {
621-
const metadata = makeClientMetadata({ driverInfo: { name: 'a'.repeat(350) } });
641+
const metadata = makeClientMetadata({
642+
driverInfo: { name: 'a'.repeat(350) },
643+
additionalDriverInfo: []
644+
});
622645
expect(metadata).to.not.have.property('env');
623646
});
624647
});

0 commit comments

Comments
 (0)