Skip to content

Commit 92bb79b

Browse files
authored
Merge pull request #15366 from mongodb-js/use-devtools-cluster-tooling
ci(NODE-6919): Use `mongodb-runner` in encryption cluster setup
2 parents b739793 + 08169cd commit 92bb79b

File tree

5 files changed

+124
-65
lines changed

5 files changed

+124
-65
lines changed

.github/workflows/encryption-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
branches: ['master']
66
pull_request:
7-
branches: [ 'master' ]
7+
branches: [ 'master', 'csfle' ]
88
workflow_dispatch: {}
99

1010
permissions:

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,4 @@ notes.md
6969
list.out
7070

7171
data
72-
*.pid
73-
mo-expansion*
72+
fle-cluster-config.json

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"devDependencies": {
3232
"@babel/core": "7.26.10",
3333
"@babel/preset-env": "7.26.9",
34+
"@mongodb-js/mongodb-downloader": "^0.3.9",
3435
"@typescript-eslint/eslint-plugin": "^8.19.1",
3536
"@typescript-eslint/parser": "^8.19.1",
3637
"acquit": "1.3.0",
@@ -58,6 +59,7 @@
5859
"mocha": "11.1.0",
5960
"moment": "2.30.1",
6061
"mongodb-memory-server": "10.1.4",
62+
"mongodb-runner": "^5.8.2",
6163
"ncp": "^2.0.0",
6264
"nyc": "15.1.0",
6365
"pug": "3.0.3",
@@ -104,7 +106,7 @@
104106
"test-deno": "deno run --allow-env --allow-read --allow-net --allow-run --allow-sys --allow-write ./test/deno.js",
105107
"test-rs": "START_REPLICA_SET=1 mocha --timeout 30000 --exit ./test/*.test.js",
106108
"test-tsd": "node ./test/types/check-types-filename && tsd",
107-
"setup-test-encryption": "bash scripts/configure-cluster-with-encryption.sh",
109+
"setup-test-encryption": "node scripts/setup-encryption-tests.js",
108110
"test-encryption": "mocha --exit ./test/encryption/*.test.js",
109111
"tdd": "mocha ./test/*.test.js --inspect --watch --recursive --watch-files ./**/*.{js,ts}",
110112
"test-coverage": "nyc --reporter=html --reporter=text npm test",
@@ -146,4 +148,4 @@
146148
"target": "ES2017"
147149
}
148150
}
149-
}
151+
}

scripts/setup-encryption-tests.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
9+
async function main() {
10+
const runnerDir = join(resolve(__dirname), '../data');
11+
const serverVersion = '8.0';
12+
13+
const configuration = await run();
14+
await writeFile('fle-cluster-config.json', JSON.stringify(configuration, null, 2));
15+
16+
async function downloadCryptShared() {
17+
const crypt_shared_dir = await downloadMongoDb(join(runnerDir, 'crypt'), serverVersion, {
18+
enterprise: true,
19+
crypt_shared: true
20+
});
21+
22+
for (const dirEntry of await readdir(crypt_shared_dir)) {
23+
if (/crypt/.test(dirEntry)) {
24+
return join(crypt_shared_dir, dirEntry);
25+
}
26+
}
27+
}
28+
29+
async function run() {
30+
await rm(runnerDir, { recursive: true }).catch(() => {});
31+
32+
const cryptShared = await downloadCryptShared();
33+
const binDir = await downloadMongoDb(runnerDir, serverVersion, {
34+
enterprise: true
35+
});
36+
37+
await start({ id: 'encryption-test-cluster', binDir, topology:
38+
'sharded', runnerDir, tmpDir: tmpdir() });
39+
40+
for await (const instance of instances({ runnerDir })) {
41+
if (instance.id === 'encryption-test-cluster') return {
42+
cryptShared, uri: instance.connectionString
43+
};
44+
}
45+
46+
throw new Error('Unable to location newly configured instance of mongod - should never happen.');
47+
}
48+
}
49+
50+
main();

0 commit comments

Comments
 (0)