forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-encryption-tests.js
More file actions
60 lines (49 loc) · 1.66 KB
/
setup-encryption-tests.js
File metadata and controls
60 lines (49 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
const { downloadMongoDb } = require('@mongodb-js/mongodb-downloader');
const { instances, start } = require('mongodb-runner');
const { rm, readdir, writeFile } = require('fs/promises');
const { tmpdir } = require('os');
const { join, resolve } = require('path');
async function main() {
const runnerDir = join(resolve(__dirname), '../data');
const serverVersion = '8.0';
const configuration = await run();
await writeFile('fle-cluster-config.json', JSON.stringify(configuration, null, 2));
async function downloadCryptShared() {
const crypt_shared_dir = await downloadMongoDb({
directory: join(runnerDir, 'crypt'),
version: serverVersion,
downloadOptions: {
enterprise: true,
crypt_shared: true
}
});
for (const dirEntry of await readdir(crypt_shared_dir)) {
if (/crypt/.test(dirEntry)) {
return join(crypt_shared_dir, dirEntry);
}
}
}
async function run() {
await rm(runnerDir, { recursive: true }).catch(() => {});
const cryptShared = await downloadCryptShared();
const binDir = await downloadMongoDb({
directory: runnerDir,
version: serverVersion,
downloadOptions: {
enterprise: true
}
});
await start({ id: 'encryption-test-cluster', binDir, topology:
'sharded', runnerDir, tmpDir: tmpdir() });
for await (const instance of instances({ runnerDir })) {
if (instance.id === 'encryption-test-cluster') {
return {
cryptShared, uri: instance.connectionString
};
}
}
throw new Error('Unable to locate newly configured instance of mongod - should never happen.');
}
}
main();