File tree Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Expand file tree Collapse file tree 4 files changed +52
-2
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ Options:
37
37
--version MongoDB server version to use [string]
38
38
--logDir Directory to store server log files in [string]
39
39
--binDir Directory containing mongod/mongos binaries [string]
40
+ --downloadDir Directory to store downloaded MongoDB versions in [string]
40
41
--tmpDir Directory for temporary files [string] [default: "/tmp"]
41
42
--runnerDir Directory for storing cluster metadata
42
43
[string] [default: "/home/addaleax/.mongodb/runner2"]
Original file line number Diff line number Diff line change @@ -49,6 +49,11 @@ import * as utilities from './index';
49
49
default : os . tmpdir ( ) ,
50
50
describe : 'Directory for temporary files' ,
51
51
} )
52
+ . option ( 'downloadDir' , {
53
+ type : 'string' ,
54
+ describe :
55
+ 'Directory for downloading and caching MongoDB binaries (uses tmpDir if not specified)' ,
56
+ } )
52
57
. option ( 'runnerDir' , {
53
58
type : 'string' ,
54
59
default : defaultRunnerDir ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { promises as fs } from 'fs';
4
4
import path from 'path' ;
5
5
import os from 'os' ;
6
6
import createDebug from 'debug' ;
7
+ import sinon from 'sinon' ;
7
8
8
9
if ( process . env . CI ) {
9
10
createDebug . enable ( 'mongodb-runner,mongodb-downloader' ) ;
@@ -36,6 +37,40 @@ describe('MongoCluster', function () {
36
37
37
38
afterEach ( async function ( ) {
38
39
await cluster ?. close ( ) ;
40
+ sinon . restore ( ) ;
41
+ } ) ;
42
+
43
+ it ( 'can use custom downloadDir option for binary downloads' , async function ( ) {
44
+ const customDownloadDir = path . join ( tmpDir , 'custom-downloads' ) ;
45
+ await fs . mkdir ( customDownloadDir , { recursive : true } ) ;
46
+
47
+ sinon
48
+ . stub ( MongoCluster , 'downloadMongoDb' as any )
49
+ . resolves ( customDownloadDir ) ;
50
+
51
+ try {
52
+ cluster = await MongoCluster . start ( {
53
+ version : '6.x' ,
54
+ topology : 'standalone' ,
55
+ tmpDir,
56
+ downloadDir : customDownloadDir ,
57
+ downloadOptions : {
58
+ platform : 'linux' ,
59
+ arch : 'x64' ,
60
+ } ,
61
+ } ) ;
62
+ } catch ( err ) {
63
+ // This will error because no actual binary gets downloaded
64
+ }
65
+
66
+ expect ( MongoCluster [ 'downloadMongoDb' ] ) . to . have . been . calledWith (
67
+ customDownloadDir ,
68
+ '6.x' ,
69
+ {
70
+ platform : 'linux' ,
71
+ arch : 'x64' ,
72
+ } ,
73
+ ) ;
39
74
} ) ;
40
75
41
76
it ( 'can spawn a 6.x standalone mongod' , async function ( ) {
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export interface MongoClusterOptions
17
17
secondaries ?: number ;
18
18
shards ?: number ;
19
19
version ?: string ;
20
+ downloadDir ?: string ;
20
21
downloadOptions ?: DownloadOptions ;
21
22
}
22
23
@@ -30,6 +31,14 @@ export class MongoCluster {
30
31
/* see .start() */
31
32
}
32
33
34
+ private static downloadMongoDb (
35
+ tmpdir : string ,
36
+ targetVersionSemverSpecifier ?: string | undefined ,
37
+ options ?: DownloadOptions | undefined ,
38
+ ) : Promise < string > {
39
+ return downloadMongoDb ( tmpdir , targetVersionSemverSpecifier , options ) ;
40
+ }
41
+
33
42
serialize ( ) : unknown /* JSON-serializable */ {
34
43
return {
35
44
topology : this . topology ,
@@ -84,8 +93,8 @@ export class MongoCluster {
84
93
const cluster = new MongoCluster ( ) ;
85
94
cluster . topology = options . topology ;
86
95
if ( ! options . binDir ) {
87
- options . binDir = await downloadMongoDb (
88
- options . tmpDir ,
96
+ options . binDir = await MongoCluster . downloadMongoDb (
97
+ options . downloadDir ?? options . tmpDir ,
89
98
options . version ,
90
99
options . downloadOptions ,
91
100
) ;
You can’t perform that action at this time.
0 commit comments