Skip to content

Commit 61adb8e

Browse files
committed
chore: move to assertion errors
1 parent bbf57f7 commit 61adb8e

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

test/tools/unified-spec-runner/entity_event_registry.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { AssertionError } from 'chai';
2+
13
import {
24
COMMAND_FAILED,
35
COMMAND_STARTED,
@@ -61,7 +63,7 @@ export class EntityEventRegistry {
6163
if (this.clientEntity.storeEventsAsEntities) {
6264
for (const { id, events } of this.clientEntity.storeEventsAsEntities) {
6365
if (this.entitiesMap.has(id) || this.clientEntity.id === id) {
64-
throw new Error(`Duplicate id ${id} found while storing events as entities`);
66+
throw new AssertionError(`Duplicate id ${id} found while storing events as entities`);
6567
}
6668
this.entitiesMap.set(id, []);
6769
for (const eventName of events) {

test/tools/unified-spec-runner/operations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type RunOperationFn = (
4444
) => Promise<Document | boolean | number | null | void | string>;
4545
export const operations = new Map<string, RunOperationFn>();
4646

47-
export class MalformedOperationError extends Error {}
47+
export class MalformedOperationError extends AssertionError {}
4848

4949
operations.set('createEntities', async ({ entities, operation, testConfig }) => {
5050
if (!operation.arguments?.entities) {

test/tools/unified-spec-runner/runner.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2-
import { expect } from 'chai';
2+
import { AssertionError, expect } from 'chai';
33
import { gte as semverGte, satisfies as semverSatisfies } from 'semver';
44

55
import type { MongoClient } from '../../mongodb';
6-
import { MONGODB_ERROR_CODES, ns, ReadPreference, TopologyType } from '../../mongodb';
6+
import {
7+
MONGODB_ERROR_CODES,
8+
MongoServerError,
9+
ns,
10+
ReadPreference,
11+
TopologyType
12+
} from '../../mongodb';
713
import { ejson } from '../utils';
814
import { AstrolabeResultsWriter } from './astrolabe_results_writer';
915
import { EntitiesMap, type UnifiedMongoClient } from './entities';
@@ -317,7 +323,9 @@ export function runUnifiedSuite(
317323
const error = await runUnifiedTest(this, unifiedSuite, test, skipFilter).catch(
318324
error => error
319325
);
320-
expect(error).to.exist;
326+
expect(error).to.satisfy(value => {
327+
return value instanceof AssertionError || value instanceof MongoServerError;
328+
});
321329
} else {
322330
await runUnifiedTest(this, unifiedSuite, test, skipFilter);
323331
}

test/tools/unified-spec-runner/unified-utils.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EJSON } from 'bson';
2-
import { expect } from 'chai';
2+
import { AssertionError, expect } from 'chai';
33
import ConnectionString from 'mongodb-connection-string-url';
44
import { gte as semverGte, lte as semverLte } from 'semver';
55
import { isDeepStrictEqual } from 'util';
@@ -351,7 +351,9 @@ export function mergeKMSProviders(
351351
: test['sessionToken']);
352352

353353
if (!awsProviders['accessKeyId'] || !awsProviders['secretAccessKey']) {
354-
throw new Error('AWS KMS providers must constain "accessKeyId" and "secretAccessKey"');
354+
throw new AssertionError(
355+
'AWS KMS providers must constain "accessKeyId" and "secretAccessKey"'
356+
);
355357
}
356358

357359
return awsProviders;
@@ -385,7 +387,7 @@ export function mergeKMSProviders(
385387
!azureProviders['clientId'] ||
386388
!azureProviders['clientSecret']
387389
) {
388-
throw new Error(
390+
throw new AssertionError(
389391
'Azure KMS providers must contain "tenantId", "clientId", and "clientSecret"'
390392
);
391393
}
@@ -409,7 +411,7 @@ export function mergeKMSProviders(
409411
: test['endPoint']);
410412

411413
if (!gcpProviders['email'] || !gcpProviders['privateKey']) {
412-
throw new Error('GCP KMS providers must contain "email" and "privateKey"');
414+
throw new AssertionError('GCP KMS providers must contain "email" and "privateKey"');
413415
}
414416

415417
return gcpProviders;
@@ -514,7 +516,7 @@ export function mergeKMSProviders(
514516
}
515517

516518
if (Object.keys(providers).length === 0) {
517-
throw new Error('Found empty KMS providers in test');
519+
throw new AssertionError('Found empty KMS providers in test');
518520
}
519521

520522
return providers;

0 commit comments

Comments
 (0)