Skip to content

Commit a88b730

Browse files
committed
test: update unified runner ops to assert arg existence
1 parent 07e97e6 commit a88b730

File tree

1 file changed

+34
-37
lines changed

1 file changed

+34
-37
lines changed

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

+34-37
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ operations.set('aggregate', async ({ entities, operation }) => {
4242
if (!(dbOrCollection instanceof Db || dbOrCollection instanceof Collection)) {
4343
throw new Error(`Operation object '${operation.object}' must be a db or collection`);
4444
}
45-
const { pipeline, ...opts } = operation.arguments ?? {};
45+
const { pipeline, ...opts } = operation.arguments!;
4646
const cursor = dbOrCollection.aggregate(pipeline, opts);
4747
return cursor.toArray();
4848
});
@@ -181,7 +181,7 @@ operations.set('assertNumberConnectionsCheckedOut', async ({ entities, operation
181181

182182
operations.set('bulkWrite', async ({ entities, operation }) => {
183183
const collection = entities.getEntity('collection', operation.object);
184-
const { requests, ...opts } = operation.arguments ?? {};
184+
const { requests, ...opts } = operation.arguments!;
185185
return collection.bulkWrite(requests, opts);
186186
});
187187

@@ -209,7 +209,7 @@ operations.set('createChangeStream', async ({ entities, operation }) => {
209209
throw new Error(`Entity ${operation.object} must be watchable`);
210210
}
211211

212-
const { pipeline, ...args } = operation.arguments ?? {};
212+
const { pipeline, ...args } = operation.arguments!;
213213
const changeStream = watchable.watch(pipeline, args);
214214

215215
return new Promise((resolve, reject) => {
@@ -223,13 +223,13 @@ operations.set('createChangeStream', async ({ entities, operation }) => {
223223

224224
operations.set('createCollection', async ({ entities, operation }) => {
225225
const db = entities.getEntity('db', operation.object);
226-
const { collection, ...opts } = operation.arguments ?? {};
226+
const { collection, ...opts } = operation.arguments!;
227227
return await db.createCollection(collection, opts);
228228
});
229229

230230
operations.set('createFindCursor', async ({ entities, operation }) => {
231231
const collection = entities.getEntity('collection', operation.object);
232-
const { filter, ...opts } = operation.arguments ?? {};
232+
const { filter, ...opts } = operation.arguments!;
233233
const cursor = collection.find(filter, opts);
234234
// The spec dictates that we create the cursor and force the find command
235235
// to execute, but don't move the cursor forward. hasNext() accomplishes
@@ -240,25 +240,25 @@ operations.set('createFindCursor', async ({ entities, operation }) => {
240240

241241
operations.set('createIndex', async ({ entities, operation }) => {
242242
const collection = entities.getEntity('collection', operation.object);
243-
const { keys, ...opts } = operation.arguments ?? {};
243+
const { keys, ...opts } = operation.arguments!;
244244
await collection.createIndex(keys, opts);
245245
});
246246

247247
operations.set('dropIndex', async ({ entities, operation }) => {
248248
const collection = entities.getEntity('collection', operation.object);
249-
const { name, ...opts } = operation.arguments ?? {};
249+
const { name, ...opts } = operation.arguments!;
250250
await collection.dropIndex(name, opts);
251251
});
252252

253253
operations.set('deleteOne', async ({ entities, operation }) => {
254254
const collection = entities.getEntity('collection', operation.object);
255-
const { filter, ...options } = operation.arguments ?? {};
255+
const { filter, ...options } = operation.arguments!;
256256
return collection.deleteOne(filter, options);
257257
});
258258

259259
operations.set('dropCollection', async ({ entities, operation }) => {
260260
const db = entities.getEntity('db', operation.object);
261-
const { collection, ...opts } = operation.arguments ?? {};
261+
const { collection, ...opts } = operation.arguments!;
262262

263263
// TODO(NODE-4243): dropCollection should suppress namespace not found errors
264264
try {
@@ -277,25 +277,25 @@ operations.set('endSession', async ({ entities, operation }) => {
277277

278278
operations.set('find', async ({ entities, operation }) => {
279279
const collection = entities.getEntity('collection', operation.object);
280-
const { filter, ...opts } = operation.arguments ?? {};
280+
const { filter, ...opts } = operation.arguments!;
281281
return collection.find(filter, opts).toArray();
282282
});
283283

284284
operations.set('findOneAndReplace', async ({ entities, operation }) => {
285285
const collection = entities.getEntity('collection', operation.object);
286-
const { filter, replacement, ...opts } = operation.arguments ?? {};
286+
const { filter, replacement, ...opts } = operation.arguments!;
287287
return (await collection.findOneAndReplace(filter, replacement, translateOptions(opts))).value;
288288
});
289289

290290
operations.set('findOneAndUpdate', async ({ entities, operation }) => {
291291
const collection = entities.getEntity('collection', operation.object);
292-
const { filter, update, ...opts } = operation.arguments ?? {};
292+
const { filter, update, ...opts } = operation.arguments!;
293293
return (await collection.findOneAndUpdate(filter, update, translateOptions(opts))).value;
294294
});
295295

296296
operations.set('findOneAndDelete', async ({ entities, operation }) => {
297297
const collection = entities.getEntity('collection', operation.object);
298-
const { filter, ...opts } = operation.arguments ?? {};
298+
const { filter, ...opts } = operation.arguments!;
299299
return (await collection.findOneAndDelete(filter, opts)).value;
300300
});
301301

@@ -306,13 +306,13 @@ operations.set('failPoint', async ({ entities, operation }) => {
306306

307307
operations.set('insertOne', async ({ entities, operation }) => {
308308
const collection = entities.getEntity('collection', operation.object);
309-
const { document, ...opts } = operation.arguments ?? {};
309+
const { document, ...opts } = operation.arguments!;
310310
return collection.insertOne(document, opts);
311311
});
312312

313313
operations.set('insertMany', async ({ entities, operation }) => {
314314
const collection = entities.getEntity('collection', operation.object);
315-
const { documents, ...opts } = operation.arguments ?? {};
315+
const { documents, ...opts } = operation.arguments!;
316316
return collection.insertMany(documents, opts);
317317
});
318318

@@ -341,26 +341,23 @@ operations.set('iterateUntilDocumentOrError', async ({ entities, operation }) =>
341341

342342
operations.set('listCollections', async ({ entities, operation }) => {
343343
const db = entities.getEntity('db', operation.object);
344-
const { filter, ...opts } = operation.arguments ?? {};
344+
const { filter, ...opts } = operation.arguments!;
345345
return db.listCollections(filter, opts).toArray();
346346
});
347347

348348
operations.set('listDatabases', async ({ entities, operation }) => {
349349
const client = entities.getEntity('client', operation.object);
350-
return client
351-
.db()
352-
.admin()
353-
.listDatabases(operation.arguments ?? {});
350+
return client.db().admin().listDatabases(operation.arguments!);
354351
});
355352

356353
operations.set('listIndexes', async ({ entities, operation }) => {
357354
const collection = entities.getEntity('collection', operation.object);
358-
return collection.listIndexes(operation.arguments ?? {}).toArray();
355+
return collection.listIndexes(operation.arguments!).toArray();
359356
});
360357

361358
operations.set('replaceOne', async ({ entities, operation }) => {
362359
const collection = entities.getEntity('collection', operation.object);
363-
const { filter, replacement, ...opts } = operation.arguments ?? {};
360+
const { filter, replacement, ...opts } = operation.arguments!;
364361
return collection.replaceOne(filter, replacement, opts);
365362
});
366363

@@ -430,61 +427,61 @@ operations.set('withTransaction', async ({ entities, operation, client }) => {
430427

431428
operations.set('countDocuments', async ({ entities, operation }) => {
432429
const collection = entities.getEntity('collection', operation.object);
433-
const { filter, ...opts } = operation.arguments ?? {};
430+
const { filter, ...opts } = operation.arguments!;
434431
return collection.countDocuments(filter, opts);
435432
});
436433

437434
operations.set('deleteMany', async ({ entities, operation }) => {
438435
const collection = entities.getEntity('collection', operation.object);
439-
const { filter, ...opts } = operation.arguments ?? {};
436+
const { filter, ...opts } = operation.arguments!;
440437
return collection.deleteMany(filter, opts);
441438
});
442439

443440
operations.set('distinct', async ({ entities, operation }) => {
444441
const collection = entities.getEntity('collection', operation.object);
445-
const { fieldName, filter, ...opts } = operation.arguments ?? {};
442+
const { fieldName, filter, ...opts } = operation.arguments!;
446443
return collection.distinct(fieldName, filter, opts);
447444
});
448445

449446
operations.set('estimatedDocumentCount', async ({ entities, operation }) => {
450447
const collection = entities.getEntity('collection', operation.object);
451-
return collection.estimatedDocumentCount(operation.arguments ?? {});
448+
return collection.estimatedDocumentCount(operation.arguments!);
452449
});
453450

454451
operations.set('runCommand', async ({ entities, operation }: OperationFunctionParams) => {
455452
const db = entities.getEntity('db', operation.object);
456-
const { command, ...opts } = operation.arguments ?? {};
453+
const { command, ...opts } = operation.arguments!;
457454
return db.command(command, opts);
458455
});
459456

460457
operations.set('updateMany', async ({ entities, operation }) => {
461458
const collection = entities.getEntity('collection', operation.object);
462-
const { filter, update, ...options } = operation.arguments ?? {};
459+
const { filter, update, ...options } = operation.arguments!;
463460
return collection.updateMany(filter, update, options);
464461
});
465462

466463
operations.set('updateOne', async ({ entities, operation }) => {
467464
const collection = entities.getEntity('collection', operation.object);
468-
const { filter, update, ...options } = operation.arguments ?? {};
465+
const { filter, update, ...options } = operation.arguments!;
469466
return collection.updateOne(filter, update, options);
470467
});
471468

472469
operations.set('rename', async ({ entities, operation }) => {
473470
const collection = entities.getEntity('collection', operation.object);
474-
const { to, ...options } = operation.arguments ?? {};
471+
const { to, ...options } = operation.arguments!;
475472
return collection.rename(to, options);
476473
});
477474

478475
operations.set('createDataKey', async ({ entities, operation }) => {
479476
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
480-
const { kmsProvider, opts } = operation.arguments ?? {};
477+
const { kmsProvider, opts } = operation.arguments!;
481478

482479
return clientEncryption.createDataKey(kmsProvider, opts);
483480
});
484481

485482
operations.set('rewrapManyDataKey', async ({ entities, operation }) => {
486483
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
487-
const { filter, opts } = operation.arguments ?? {};
484+
const { filter, opts } = operation.arguments!;
488485

489486
const rewrapManyDataKeyResult = await clientEncryption.rewrapManyDataKey(filter, opts);
490487

@@ -506,14 +503,14 @@ operations.set('rewrapManyDataKey', async ({ entities, operation }) => {
506503

507504
operations.set('deleteKey', async ({ entities, operation }) => {
508505
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
509-
const { id } = operation.arguments ?? {};
506+
const { id } = operation.arguments!;
510507

511508
return clientEncryption.deleteKey(id);
512509
});
513510

514511
operations.set('getKey', async ({ entities, operation }) => {
515512
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
516-
const { id } = operation.arguments ?? {};
513+
const { id } = operation.arguments!;
517514

518515
return clientEncryption.getKey(id);
519516
});
@@ -526,21 +523,21 @@ operations.set('getKeys', async ({ entities, operation }) => {
526523

527524
operations.set('addKeyAltName', async ({ entities, operation }) => {
528525
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
529-
const { id, keyAltName } = operation.arguments ?? {};
526+
const { id, keyAltName } = operation.arguments!;
530527

531528
return clientEncryption.addKeyAltName(id, keyAltName);
532529
});
533530

534531
operations.set('removeKeyAltName', async ({ entities, operation }) => {
535532
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
536-
const { id, keyAltName } = operation.arguments ?? {};
533+
const { id, keyAltName } = operation.arguments!;
537534

538535
return clientEncryption.removeKeyAltName(id, keyAltName);
539536
});
540537

541538
operations.set('getKeyByAltName', async ({ entities, operation }) => {
542539
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
543-
const { keyAltName } = operation.arguments ?? {};
540+
const { keyAltName } = operation.arguments!;
544541

545542
return clientEncryption.getKeyByAltName(keyAltName);
546543
});

0 commit comments

Comments
 (0)