Skip to content

Commit

Permalink
feat: add binary.ssl option, use if mongodb dist has only ssl versi…
Browse files Browse the repository at this point in the history
…on binary. Related #48 (thanks @mathieug)

* Remove useless binary option http

* Add binary option ssl
  • Loading branch information
mathieug authored and nodkz committed Feb 14, 2018
1 parent 3d254e7 commit b515587
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -57,7 +57,7 @@ const mongod = new MongodbMemoryServer({
downloadDir?: string, // by default %HOME/.mongodb-binaries
platform?: string, // by default os.platform()
arch?: string, // by default os.arch()
http?: any, // see mongodb-download package
ssl?: boolean, // by default false
debug?: boolean, // by default false
},
debug?: boolean, // by default false
Expand Down
2 changes: 1 addition & 1 deletion src/MongoMemoryServer.js
Expand Up @@ -22,7 +22,7 @@ export type MongoMemoryServerOptsT = {
downloadDir?: string,
platform?: string,
arch?: string,
http?: any,
ssl?: boolean,
debug?: boolean | Function,
},
debug?: boolean,
Expand Down
6 changes: 3 additions & 3 deletions src/util/MongoBinary.js
Expand Up @@ -15,7 +15,7 @@ export type MongoBinaryOpts = {
downloadDir?: string,
platform?: string,
arch?: string,
http?: any,
ssl?: boolean,
debug?: boolean | Function,
};

Expand All @@ -27,8 +27,8 @@ export default class MongoBinary {
downloadDir = path.resolve(os.homedir(), '.mongodb-binaries'),
platform = os.platform(),
arch = os.arch(),
ssl = false,
version = '3.4.4',
http = {},
} = opts;

let debug;
Expand Down Expand Up @@ -79,8 +79,8 @@ export default class MongoBinary {
downloadDir,
platform,
arch,
ssl,
version,
http,
});

downloader.debug = debug;
Expand Down
9 changes: 5 additions & 4 deletions src/util/MongoBinaryDownload.js
Expand Up @@ -15,7 +15,7 @@ export type MongoBinaryDownloadOpts = {
downloadDir: string,
platform: string,
arch: string,
http: any,
ssl: boolean,
debug?: boolean | Function,
};

Expand All @@ -32,22 +32,22 @@ export default class MongoBinaryDownload {

downloadDir: string;
arch: string;
ssl: boolean;
version: string;
platform: string;
http: any;

constructor({
platform,
arch,
ssl,
downloadDir,
version,
http,
debug,
}: $Shape<MongoBinaryDownloadOpts>) {
this.platform = platform || os.platform();
this.arch = arch || os.arch();
this.ssl = ssl || false;
this.version = version || 'latest';
this.http = http || {};
this.downloadDir = path.resolve(downloadDir || 'mongodb-download');
this.dlProgress = {
current: 0,
Expand Down Expand Up @@ -89,6 +89,7 @@ export default class MongoBinaryDownload {
const mbdUrl = new MongoBinaryDownloadUrl({
platform: this.platform,
arch: this.arch,
ssl: this.ssl,
version: this.version,
});

Expand Down
13 changes: 11 additions & 2 deletions src/util/MongoBinaryDownloadUrl.js
Expand Up @@ -14,18 +14,21 @@ export type MongoBinaryDownloadUrlOpts = {
version: string,
platform: string,
arch: string,
ssl?: boolean,
os?: ?OS, // getos() result
};

export default class MongoBinaryDownloadUrl {
platform: string;
arch: string;
ssl: ?boolean;
version: string;
os: ?OS;

constructor({ platform, arch, version, os }: MongoBinaryDownloadUrlOpts) {
constructor({ platform, arch, ssl, version, os }: MongoBinaryDownloadUrlOpts) {
this.platform = this.translatePlatform(platform);
this.arch = this.translateArch(arch, this.platform);
this.ssl = ssl;
this.version = version;
this.os = os;
}
Expand All @@ -36,7 +39,13 @@ export default class MongoBinaryDownloadUrl {
}

async getArchiveName(): Promise<string> {
let name = `mongodb-${this.platform}-${this.arch}`;
let name = `mongodb-${this.platform}`;

if (this.ssl) {
name += '-ssl';
}

name += `-${this.arch}`;

let osString;
if (this.platform === 'linux' && this.arch !== 'i686') {
Expand Down
37 changes: 37 additions & 0 deletions src/util/__tests__/MongoBinaryDownloadUrl-test.js
Expand Up @@ -4,6 +4,43 @@ import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl';

describe('MongoBinaryDownloadUrl', () => {
describe('getDownloadUrl()', () => {
describe('for mac', () => {
it('3.4.4 without ssl', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'darwin',
arch: 'x64',
version: '3.4.4',
});
expect(await du.getDownloadUrl()).toBe(
'https://downloads.mongodb.org/osx/mongodb-osx-x86_64-3.4.4.tgz'
);
});

it('3.4.4 with ssl', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'darwin',
arch: 'x64',
version: '3.4.4',
ssl: true,
});
expect(await du.getDownloadUrl()).toBe(
'https://downloads.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.4.4.tgz'
);
});

it('3.6.2 with ssl', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'darwin',
arch: 'x64',
version: '3.6.2',
ssl: true,
});
expect(await du.getDownloadUrl()).toBe(
'https://downloads.mongodb.org/osx/mongodb-osx-ssl-x86_64-3.6.2.tgz'
);
});
});

it('for ubuntu', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
Expand Down

0 comments on commit b515587

Please sign in to comment.