File tree Expand file tree Collapse file tree 4 files changed +51
-2
lines changed Expand file tree Collapse file tree 4 files changed +51
-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,39 @@ 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
+
46
+ sinon
47
+ . stub ( MongoCluster , 'downloadMongoDb' as any )
48
+ . resolves ( customDownloadDir ) ;
49
+
50
+ try {
51
+ cluster = await MongoCluster . start ( {
52
+ version : '6.x' ,
53
+ topology : 'standalone' ,
54
+ tmpDir,
55
+ downloadDir : customDownloadDir ,
56
+ downloadOptions : {
57
+ platform : 'linux' ,
58
+ arch : 'x64' ,
59
+ } ,
60
+ } ) ;
61
+ } catch ( err ) {
62
+ // This will error because no actual binary gets downloaded
63
+ }
64
+
65
+ expect ( MongoCluster [ 'downloadMongoDb' ] ) . to . have . been . calledWith (
66
+ customDownloadDir ,
67
+ '6.x' ,
68
+ {
69
+ platform : 'linux' ,
70
+ arch : 'x64' ,
71
+ } ,
72
+ ) ;
39
73
} ) ;
40
74
41
75
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 this . 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