Skip to content

Commit f78fb17

Browse files
asdf
1 parent 5fbee5a commit f78fb17

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

scripts/setup-encryption-tests.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
const { downloadMongoDb } = require('@mongodb-js/mongodb-downloader');
3+
const { instances, start } = require('mongodb-runner');
4+
const { rm, readdir, writeFile } = require('fs/promises');
5+
const { tmpdir } = require('os');
6+
const { join, resolve } = require('path');
7+
8+
async function getCryptShared() {
9+
const crypt_shared_dir = await downloadMongoDb('./data/crypt', '8.0', {
10+
enterprise: true,
11+
crypt_shared: true
12+
});
13+
14+
for (const direntry of await readdir(crypt_shared_dir)) {
15+
if (/crypt/.test(direntry)) {
16+
return join(crypt_shared_dir, direntry);
17+
}
18+
}
19+
}
20+
21+
const runnerDir = join(resolve(__dirname), '../data');
22+
const id = 'my-cluster';
23+
24+
async function run() {
25+
await rm(runnerDir, { recursive: true }).catch(e => {});
26+
27+
const cryptShared = await getCryptShared();
28+
const binDir = await downloadMongoDb('./data', '8.0', {
29+
enterprise: true
30+
});
31+
32+
const tmpDir = tmpdir();
33+
34+
await start({ id, binDir, topology: 'replset', runnerDir, tmpDir });
35+
36+
for await (const instance of instances({ runnerDir })) {
37+
if (instance.id === id) return {
38+
cryptShared, uri: instance.connectionString
39+
};
40+
}
41+
42+
throw new Error('unable to find new instance.');
43+
}
44+
45+
async function stop() {
46+
await require('mongodb-runner').stop({
47+
runnerDir,
48+
id
49+
});
50+
}
51+
52+
async function main() {
53+
const { uri, cryptShared } = await run();
54+
await writeFile('mo-expansion.yml',
55+
`
56+
CRYPT_SHARED_LIB_PATH: "${cryptShared}"
57+
MONGODB_URI: "${uri}"
58+
`
59+
);
60+
}
61+
62+
if (require.main === module) {
63+
main();
64+
}
65+
else {
66+
module.exports = { start: run, stop };
67+
}

0 commit comments

Comments
 (0)