Skip to content

Commit b515587

Browse files
mathieugnodkz
authored andcommitted
feat: add binary.ssl option, use if mongodb dist has only ssl version binary. Related #48 (thanks @mathieug)
* Remove useless binary option http * Add binary option ssl
1 parent 3d254e7 commit b515587

File tree

6 files changed

+58
-11
lines changed

6 files changed

+58
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const mongod = new MongodbMemoryServer({
5757
downloadDir?: string, // by default %HOME/.mongodb-binaries
5858
platform?: string, // by default os.platform()
5959
arch?: string, // by default os.arch()
60-
http?: any, // see mongodb-download package
60+
ssl?: boolean, // by default false
6161
debug?: boolean, // by default false
6262
},
6363
debug?: boolean, // by default false

src/MongoMemoryServer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type MongoMemoryServerOptsT = {
2222
downloadDir?: string,
2323
platform?: string,
2424
arch?: string,
25-
http?: any,
25+
ssl?: boolean,
2626
debug?: boolean | Function,
2727
},
2828
debug?: boolean,

src/util/MongoBinary.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type MongoBinaryOpts = {
1515
downloadDir?: string,
1616
platform?: string,
1717
arch?: string,
18-
http?: any,
18+
ssl?: boolean,
1919
debug?: boolean | Function,
2020
};
2121

@@ -27,8 +27,8 @@ export default class MongoBinary {
2727
downloadDir = path.resolve(os.homedir(), '.mongodb-binaries'),
2828
platform = os.platform(),
2929
arch = os.arch(),
30+
ssl = false,
3031
version = '3.4.4',
31-
http = {},
3232
} = opts;
3333

3434
let debug;
@@ -79,8 +79,8 @@ export default class MongoBinary {
7979
downloadDir,
8080
platform,
8181
arch,
82+
ssl,
8283
version,
83-
http,
8484
});
8585

8686
downloader.debug = debug;

src/util/MongoBinaryDownload.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type MongoBinaryDownloadOpts = {
1515
downloadDir: string,
1616
platform: string,
1717
arch: string,
18-
http: any,
18+
ssl: boolean,
1919
debug?: boolean | Function,
2020
};
2121

@@ -32,22 +32,22 @@ export default class MongoBinaryDownload {
3232

3333
downloadDir: string;
3434
arch: string;
35+
ssl: boolean;
3536
version: string;
3637
platform: string;
37-
http: any;
3838

3939
constructor({
4040
platform,
4141
arch,
42+
ssl,
4243
downloadDir,
4344
version,
44-
http,
4545
debug,
4646
}: $Shape<MongoBinaryDownloadOpts>) {
4747
this.platform = platform || os.platform();
4848
this.arch = arch || os.arch();
49+
this.ssl = ssl || false;
4950
this.version = version || 'latest';
50-
this.http = http || {};
5151
this.downloadDir = path.resolve(downloadDir || 'mongodb-download');
5252
this.dlProgress = {
5353
current: 0,
@@ -89,6 +89,7 @@ export default class MongoBinaryDownload {
8989
const mbdUrl = new MongoBinaryDownloadUrl({
9090
platform: this.platform,
9191
arch: this.arch,
92+
ssl: this.ssl,
9293
version: this.version,
9394
});
9495

src/util/MongoBinaryDownloadUrl.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,21 @@ export type MongoBinaryDownloadUrlOpts = {
1414
version: string,
1515
platform: string,
1616
arch: string,
17+
ssl?: boolean,
1718
os?: ?OS, // getos() result
1819
};
1920

2021
export default class MongoBinaryDownloadUrl {
2122
platform: string;
2223
arch: string;
24+
ssl: ?boolean;
2325
version: string;
2426
os: ?OS;
2527

26-
constructor({ platform, arch, version, os }: MongoBinaryDownloadUrlOpts) {
28+
constructor({ platform, arch, ssl, version, os }: MongoBinaryDownloadUrlOpts) {
2729
this.platform = this.translatePlatform(platform);
2830
this.arch = this.translateArch(arch, this.platform);
31+
this.ssl = ssl;
2932
this.version = version;
3033
this.os = os;
3134
}
@@ -36,7 +39,13 @@ export default class MongoBinaryDownloadUrl {
3639
}
3740

3841
async getArchiveName(): Promise<string> {
39-
let name = `mongodb-${this.platform}-${this.arch}`;
42+
let name = `mongodb-${this.platform}`;
43+
44+
if (this.ssl) {
45+
name += '-ssl';
46+
}
47+
48+
name += `-${this.arch}`;
4049

4150
let osString;
4251
if (this.platform === 'linux' && this.arch !== 'i686') {

src/util/__tests__/MongoBinaryDownloadUrl-test.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,43 @@ import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl';
44

55
describe('MongoBinaryDownloadUrl', () => {
66
describe('getDownloadUrl()', () => {
7+
describe('for mac', () => {
8+
it('3.4.4 without ssl', async () => {
9+
const du = new MongoBinaryDownloadUrl({
10+
platform: 'darwin',
11+
arch: 'x64',
12+
version: '3.4.4',
13+
});
14+
expect(await du.getDownloadUrl()).toBe(
15+
'https://downloads.mongodb.org/osx/mongodb-osx-x86_64-3.4.4.tgz'
16+
);
17+
});
18+
19+
it('3.4.4 with ssl', async () => {
20+
const du = new MongoBinaryDownloadUrl({
21+
platform: 'darwin',
22+
arch: 'x64',
23+
version: '3.4.4',
24+
ssl: true,
25+
});
26+
expect(await du.getDownloadUrl()).toBe(
27+
'https://downloads.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.4.4.tgz'
28+
);
29+
});
30+
31+
it('3.6.2 with ssl', async () => {
32+
const du = new MongoBinaryDownloadUrl({
33+
platform: 'darwin',
34+
arch: 'x64',
35+
version: '3.6.2',
36+
ssl: true,
37+
});
38+
expect(await du.getDownloadUrl()).toBe(
39+
'https://downloads.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.2.tgz'
40+
);
41+
});
42+
});
43+
744
it('for ubuntu', async () => {
845
const du = new MongoBinaryDownloadUrl({
946
platform: 'linux',

0 commit comments

Comments
 (0)