(suite, context)
| 249 | |
| 250 | // Test runner helpers |
| 251 | function prepareDatabaseForSuite(suite, context) { |
| 252 | context.dbName = suite.database_name || 'spec_db'; |
| 253 | context.collectionName = suite.collection_name || 'spec_collection'; |
| 254 | |
| 255 | const db = context.sharedClient.db(context.dbName); |
| 256 | |
| 257 | if (context.skipPrepareDatabase) return Promise.resolve(); |
| 258 | |
| 259 | const setupPromise = db |
| 260 | .admin() |
| 261 | .command({ killAllSessions: [] }) |
| 262 | .catch(err => { |
| 263 | if ( |
| 264 | err.message.match(/no such (cmd|command)/) || |
| 265 | err.message.match(/Failed to kill on some hosts/) || |
| 266 | err.code === 11601 |
| 267 | ) { |
| 268 | return; |
| 269 | } |
| 270 | |
| 271 | throw err; |
| 272 | }); |
| 273 | |
| 274 | if (context.collectionName == null || context.dbName === 'admin') { |
| 275 | return setupPromise; |
| 276 | } |
| 277 | |
| 278 | const coll = db.collection(context.collectionName); |
| 279 | return setupPromise |
| 280 | .then(() => { |
| 281 | const options = { writeConcern: { w: 'majority' } }; |
| 282 | if (suite.encrypted_fields) { |
| 283 | options.encryptedFields = suite.encrypted_fields; |
| 284 | } |
| 285 | return coll.drop(options); |
| 286 | }) |
| 287 | .then(() => { |
| 288 | if (suite.key_vault_data) { |
| 289 | const dataKeysCollection = context.sharedClient.db('keyvault').collection('datakeys'); |
| 290 | return dataKeysCollection.drop({ writeConcern: { w: 'majority' } }).then(() => { |
| 291 | if (suite.key_vault_data.length) { |
| 292 | return dataKeysCollection.insertMany(suite.key_vault_data, { |
| 293 | writeConcern: { w: 'majority' } |
| 294 | }); |
| 295 | } |
| 296 | }); |
| 297 | } |
| 298 | }) |
| 299 | .then(() => { |
| 300 | const options = { writeConcern: { w: 'majority' } }; |
| 301 | if (suite.json_schema) { |
| 302 | options.validator = { $jsonSchema: suite.json_schema }; |
| 303 | } |
| 304 | if (suite.encrypted_fields) { |
| 305 | options.encryptedFields = suite.encrypted_fields; |
| 306 | } |
| 307 | |
| 308 | return db.createCollection(context.collectionName, options); |
no test coverage detected