@@ -5,63 +5,48 @@ const { rm, readdir, writeFile } = require('fs/promises');
55const  {  tmpdir }  =  require ( 'os' ) ; 
66const  {  join,  resolve }  =  require ( 'path' ) ; 
77
8- async  function  getCryptShared ( )  { 
9-   const  crypt_shared_dir  =  await  downloadMongoDb ( './data/crypt' ,  '8.0' ,  { 
10-     enterprise : true , 
11-     crypt_shared : true 
12-   } ) ; 
138
14-   for  ( const  direntry  of  await  readdir ( crypt_shared_dir ) )  { 
15-     if  ( / c r y p t / . test ( direntry ) )  { 
16-       return  join ( crypt_shared_dir ,  direntry ) ; 
17-     } 
18-   } 
19- } 
9+ async  function  main ( )  { 
10+   const  runnerDir  =  join ( resolve ( __dirname ) ,  '../data' ) ; 
11+   const  serverVersion  =  '8.0' ; 
2012
21- const  runnerDir  =  join ( resolve ( __dirname ) ,  '../data' ) ; 
22- const  id  =  'my-cluster' ; 
13+   const  {  uri,  cryptShared }  =  await  run ( ) ; 
14+   await  writeFile ( 'mo-expansion.yml' , 
15+     `CRYPT_SHARED_LIB_PATH: "${ cryptShared }  " 
16+ MONGODB_URI: "${ uri }  "` 
17+   ) ; 
2318
24- async  function  run ( )  { 
25-   await  rm ( runnerDir ,  {  recursive : true  } ) . catch ( e  =>  { } ) ; 
19+   async  function  downloadCryptShared ( )  { 
20+     const  crypt_shared_dir  =  await  downloadMongoDb ( join ( runnerDir ,  'crypt' ) ,  serverVersion ,  { 
21+       enterprise : true , 
22+       crypt_shared : true 
23+     } ) ; 
2624
27-   const  cryptShared  =  await  getCryptShared ( ) ; 
28-   const  binDir  =  await  downloadMongoDb ( './data' ,  '8.0' ,  { 
29-     enterprise : true 
30-   } ) ; 
25+     for  ( const  dirEntry  of  await  readdir ( crypt_shared_dir ) )  { 
26+       if  ( / c r y p t / . test ( dirEntry ) )  { 
27+         return  join ( crypt_shared_dir ,  dirEntry ) ; 
28+       } 
29+     } 
30+   } 
3131
32-   const  tmpDir  =  tmpdir ( ) ; 
32+   async  function  run ( )  { 
33+     await  rm ( runnerDir ,  {  recursive : true  } ) . catch ( ( )  =>  { } ) ; 
3334
34-   await  start ( {  id,  binDir,  topology : 'replset' ,  runnerDir,  tmpDir } ) ; 
35+     const  cryptShared  =  await  downloadCryptShared ( ) ; 
36+     const  binDir  =  await  downloadMongoDb ( runnerDir ,  serverVersion ,  { 
37+       enterprise : true 
38+     } ) ; 
3539
36-   for  await  ( const  instance  of  instances ( {  runnerDir } ) )  { 
37-     if  ( instance . id  ===  id )  return  { 
38-       cryptShared,  uri : instance . connectionString 
39-     } ; 
40-   } 
40+     await  start ( {  id : 'encryption-test-cluster' ,  binDir,  topology : 'replset' ,  runnerDir,  tmpDir : tmpdir ( )  } ) ; 
4141
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- } 
42+     for  await  ( const  instance  of  instances ( {  runnerDir } ) )  { 
43+       if  ( instance . id  ===  'encryption-test-cluster' )  return  { 
44+         cryptShared,  uri : instance . connectionString 
45+       } ; 
46+     } 
5147
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-   ) ; 
48+     throw  new  Error ( 'Unable to location newly configured instance of mongod - should never happen.' ) ; 
49+   } 
6050} 
6151
62- if  ( require . main  ===  module )  { 
63-   main ( ) ; 
64- } 
65- else  { 
66-   module . exports  =  {  start : run ,  stop } ; 
67- } 
52+ main ( ) ; 
0 commit comments