Skip to content

Commit 9cd80f9

Browse files
authored
fix: URL generation for MongoDB 4.4 (#329)
* allow MongoDB 4.4 on macOS * fix test for macOS * fix url generation for Windows * adjust version check for Windows
1 parent 5d66264 commit 9cd80f9

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

packages/mongodb-memory-server-core/src/util/MongoBinaryDownloadUrl.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export default class MongoBinaryDownloadUrl {
5757
case 'osx':
5858
return this.getArchiveNameOsx();
5959
case 'win32':
60+
case 'windows':
6061
return this.getArchiveNameWin();
6162
case 'linux':
6263
default:
@@ -71,9 +72,9 @@ export default class MongoBinaryDownloadUrl {
7172
async getArchiveNameWin(): Promise<string> {
7273
let name = `mongodb-${this.platform}`;
7374
name += `-${this.arch}`;
74-
if (this.version.indexOf('4.2') === 0) {
75+
if (this.version.startsWith('4.2')) {
7576
name += '-2012plus';
76-
} else {
77+
} else if (/^[1-3]\./.test(this.version)) {
7778
name += '-2008plus-ssl';
7879
}
7980
name += `-${this.version}.zip`;
@@ -88,14 +89,14 @@ export default class MongoBinaryDownloadUrl {
8889
let name = `mongodb-osx`;
8990
if (
9091
!(
91-
this.version.indexOf('3.0') === 0 ||
92-
this.version.indexOf('2.') === 0 ||
93-
this.version.indexOf('1.') === 0
92+
this.version.startsWith('3.0') ||
93+
this.version.startsWith('2.') ||
94+
this.version.startsWith('1.')
9495
)
9596
) {
9697
name += '-ssl';
9798
}
98-
if (this.version.indexOf('4.2') === 0) {
99+
if (this.version.startsWith('4.')) {
99100
name = `mongodb-macos`;
100101
}
101102
name += `-${this.arch}`;
@@ -336,7 +337,7 @@ export default class MongoBinaryDownloadUrl {
336337
case 'darwin':
337338
return 'osx';
338339
case 'win32':
339-
return 'win32';
340+
return /^(4\.[4-9]|[5-9])/.test(this.version) ? 'windows' : 'win32';
340341
case 'linux':
341342
case 'elementary OS':
342343
return 'linux';

packages/mongodb-memory-server-core/src/util/__tests__/MongoBinaryDownloadUrl-test.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl';
33
describe('MongoBinaryDownloadUrl', () => {
44
describe('getDownloadUrl()', () => {
55
describe('for mac', () => {
6-
it('4.2', async () => {
6+
it('4.4', async () => {
77
const du = new MongoBinaryDownloadUrl({
88
platform: 'darwin',
99
arch: 'x64',
10-
version: '4.2.0',
10+
version: '4.4.0',
1111
});
1212
expect(await du.getDownloadUrl()).toBe(
13-
'https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.2.0.tgz'
13+
'https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.0.tgz'
1414
);
1515
});
1616

@@ -91,6 +91,17 @@ describe('MongoBinaryDownloadUrl', () => {
9191
);
9292
});
9393

94+
it('4.4 for win32', async () => {
95+
const du = new MongoBinaryDownloadUrl({
96+
platform: 'win32',
97+
arch: 'x64',
98+
version: '4.4.0',
99+
});
100+
expect(await du.getDownloadUrl()).toBe(
101+
'https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-4.4.0.zip'
102+
);
103+
});
104+
94105
it('fallback', async () => {
95106
console.warn = jest.fn(); // mock it to prevent writing to console
96107

0 commit comments

Comments
 (0)