| 348 | } |
| 349 | |
| 350 | async function createUsers(configuration: TestConfiguration) { |
| 351 | const utilClient = configuration.newClient(); |
| 352 | const db = utilClient.db('admin'); |
| 353 | |
| 354 | const createUserCommands = users.map(user => ({ |
| 355 | createUser: user.username, |
| 356 | pwd: user.password, |
| 357 | roles: ['root'], |
| 358 | mechanisms: user.mechanisms |
| 359 | })); |
| 360 | |
| 361 | const failures = await Promise.allSettled( |
| 362 | createUserCommands.map(cmd => db.command(cmd)) |
| 363 | ).then(resolutions => resolutions.filter(resolution => resolution.status === 'rejected')); |
| 364 | |
| 365 | await utilClient.close(); |
| 366 | |
| 367 | if (failures.length) { |
| 368 | throw new Error( |
| 369 | 'Error(s) creating users: ' + failures.map(failure => failure.reason).join(' | ') |
| 370 | ); |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | before(async function () { |
| 375 | await cleanUpUsers(this.configuration); |