Skip to content

Commit 31183dd

Browse files
committed
fix: change mongodb version tests to use semver
fix: add "macos" for 4.2+ and "osx" for 4.1- fix: dont assume "anythingmint" as "mint" - move tests for "win32" & "windows" into an "describe" - add test for "Peppermint" to not assert to "mint" - add dependency "semver" fixes #340 fix partially #318
1 parent d14ab81 commit 31183dd

File tree

4 files changed

+78
-58
lines changed

4 files changed

+78
-58
lines changed

packages/mongodb-memory-server-core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"@types/lockfile": "^1.0.1",
5858
"@types/md5-file": "^4.0.2",
5959
"@types/mkdirp": "^1.0.1",
60+
"@types/semver": "^7.3.3",
6061
"@types/tmp": "^0.2.0",
6162
"@types/uuid": "^8.0.0",
6263
"camelcase": "^6.0.0",
@@ -70,6 +71,7 @@
7071
"lockfile": "^1.0.4",
7172
"md5-file": "^5.0.0",
7273
"mkdirp": "^1.0.4",
74+
"semver": "^7.3.2",
7375
"tar-stream": "^2.1.3",
7476
"tmp": "^0.2.1",
7577
"uuid": "^8.2.0",

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import getOS, { AnyOS, LinuxOS } from './getos';
22
import { execSync } from 'child_process';
33
import resolveConfig from './resolve-config';
44
import debug from 'debug';
5+
import * as semver from 'semver';
56

67
const log = debug('MongoMS:MongoBinaryDownloadUrl');
78

@@ -72,9 +73,9 @@ export default class MongoBinaryDownloadUrl {
7273
async getArchiveNameWin(): Promise<string> {
7374
let name = `mongodb-${this.platform}`;
7475
name += `-${this.arch}`;
75-
if (this.version.startsWith('4.2')) {
76+
if (semver.satisfies(this.version, '4.2.x')) {
7677
name += '-2012plus';
77-
} else if (/^[1-3]\./.test(this.version)) {
78+
} else if (semver.lt(this.version, '4.0.0')) {
7879
name += '-2008plus-ssl';
7980
}
8081
name += `-${this.version}.zip`;
@@ -87,17 +88,11 @@ export default class MongoBinaryDownloadUrl {
8788
*/
8889
async getArchiveNameOsx(): Promise<string> {
8990
let name = `mongodb-osx`;
90-
if (
91-
!(
92-
this.version.startsWith('3.0') ||
93-
this.version.startsWith('2.') ||
94-
this.version.startsWith('1.')
95-
)
96-
) {
91+
if (semver.gte(this.version, '3.2.0')) {
9792
name += '-ssl';
9893
}
99-
if (this.version.startsWith('4.')) {
100-
name = `mongodb-macos`;
94+
if (semver.gte(this.version, '4.2.0')) {
95+
name = `mongodb-macos`; // somehow these files are not listed in https://www.mongodb.org/dl/osx
10196
}
10297
name += `-${this.arch}`;
10398
name += `-${this.version}.tgz`;
@@ -145,7 +140,7 @@ export default class MongoBinaryDownloadUrl {
145140
return this.getFedoraVersionString(os);
146141
} else if (/debian/i.test(os.dist)) {
147142
return this.getDebianVersionString(os);
148-
} else if (/mint/i.test(os.dist)) {
143+
} else if (/\s+mint\s*$/i.test(os.dist)) {
149144
return this.getMintVersionString(os);
150145
} else if (/arch/i.test(os.dist)) {
151146
console.warn('There is no offical build of MongoDB for ArchLinux!');
@@ -337,7 +332,7 @@ export default class MongoBinaryDownloadUrl {
337332
case 'darwin':
338333
return 'osx';
339334
case 'win32':
340-
return /^(4\.[4-9]|[5-9])/.test(this.version) ? 'windows' : 'win32';
335+
return semver.gte(this.version, '4.3.0') ? 'windows' : 'win32';
341336
case 'linux':
342337
case 'elementary OS':
343338
return 'linux';

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

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,39 @@ describe('MongoBinaryDownloadUrl', () => {
6969
);
7070
});
7171

72-
it('for win32', async () => {
73-
const du = new MongoBinaryDownloadUrl({
74-
platform: 'win32',
75-
arch: 'x64',
76-
version: '3.6.3',
72+
describe('for win32 & windows', () => {
73+
it('3.6 (win32)', async () => {
74+
const du = new MongoBinaryDownloadUrl({
75+
platform: 'win32',
76+
arch: 'x64',
77+
version: '3.6.3',
78+
});
79+
expect(await du.getDownloadUrl()).toBe(
80+
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.3.zip'
81+
);
7782
});
78-
expect(await du.getDownloadUrl()).toBe(
79-
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.3.zip'
80-
);
81-
});
8283

83-
it('4.2 for win32', async () => {
84-
const du = new MongoBinaryDownloadUrl({
85-
platform: 'win32',
86-
arch: 'x64',
87-
version: '4.2.0',
84+
it('4.2 (win32)', async () => {
85+
const du = new MongoBinaryDownloadUrl({
86+
platform: 'win32',
87+
arch: 'x64',
88+
version: '4.2.0',
89+
});
90+
expect(await du.getDownloadUrl()).toBe(
91+
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.0.zip'
92+
);
8893
});
89-
expect(await du.getDownloadUrl()).toBe(
90-
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.0.zip'
91-
);
92-
});
9394

94-
it('4.4 for win32', async () => {
95-
const du = new MongoBinaryDownloadUrl({
96-
platform: 'win32',
97-
arch: 'x64',
98-
version: '4.4.0',
95+
it('4.4 (windows)', async () => {
96+
const du = new MongoBinaryDownloadUrl({
97+
platform: 'win32',
98+
arch: 'x64',
99+
version: '4.4.0',
100+
});
101+
expect(await du.getDownloadUrl()).toBe(
102+
'https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-4.4.0.zip'
103+
);
99104
});
100-
expect(await du.getDownloadUrl()).toBe(
101-
'https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-4.4.0.zip'
102-
);
103105
});
104106

105107
it('fallback', async () => {
@@ -287,6 +289,22 @@ describe('MongoBinaryDownloadUrl', () => {
287289
});
288290
});
289291

292+
it('shouldnt detect linux mint when using peppermint', () => {
293+
const downloadUrl = new MongoBinaryDownloadUrl({
294+
platform: 'linux',
295+
arch: 'x64',
296+
version: '3.6.3',
297+
});
298+
299+
expect(
300+
downloadUrl.getLinuxOSVersionString({
301+
os: 'linux',
302+
dist: 'Peppermint',
303+
release: '10',
304+
})
305+
).toBe('');
306+
});
307+
290308
describe('getLegacyVersionString', () => {
291309
const downloadUrl = new MongoBinaryDownloadUrl({
292310
platform: 'linux',

yarn.lock

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,6 +1540,11 @@
15401540
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.0.2.tgz#5bb52ee68d0f8efa9cc0099920e56be6cc4e37f3"
15411541
integrity sha512-IkVfat549ggtkZUthUzEX49562eGikhSYeVGX97SkMFn+sTZrgRewXjQ4tPKFPCykZHkX1Zfd9OoELGqKU2jJA==
15421542

1543+
"@types/semver@^7.3.3":
1544+
version "7.3.3"
1545+
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.3.tgz#3ad6ed949e7487e7bda6f886b4a2434a2c3d7b1a"
1546+
integrity sha512-jQxClWFzv9IXdLdhSaTf16XI3NYe6zrEbckSpb5xhKfPbWgIyAY0AFyWWWfaiDcBuj3UHmMkCIwSRqpKMTZL2Q==
1547+
15431548
"@types/stack-utils@^1.0.1":
15441549
version "1.0.1"
15451550
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
@@ -1552,15 +1557,15 @@
15521557
dependencies:
15531558
"@types/node" "*"
15541559

1555-
1560+
"@types/tmp@^0.2.0":
15561561
version "0.2.0"
15571562
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.2.0.tgz#e3f52b4d7397eaa9193592ef3fdd44dc0af4298c"
15581563
integrity sha512-flgpHJjntpBAdJD43ShRosQvNC0ME97DCfGvZEDlAThQmnerRXrLbX6YgzRBQCZTthET9eAWFAMaYP0m0Y4HzQ==
15591564

1560-
1561-
version "8.0.0"
1562-
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.0.0.tgz#165aae4819ad2174a17476dbe66feebd549556c0"
1563-
integrity sha512-xSQfNcvOiE5f9dyd4Kzxbof1aTrLobL278pGLKOZI6esGfZ7ts9Ka16CzIN6Y8hFHE1C7jIBZokULhK1bOgjRw==
1565+
"@types/uuid@^8.0.0":
1566+
version "8.3.0"
1567+
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
1568+
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
15641569

15651570
"@types/yargs-parser@*":
15661571
version "15.0.0"
@@ -3400,7 +3405,7 @@ fill-range@^7.0.1:
34003405
dependencies:
34013406
to-regex-range "^5.0.1"
34023407

3403-
3408+
find-cache-dir@^3.3.1:
34043409
version "3.3.1"
34053410
resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-3.3.1.tgz#89b33fad4a4670daa94f855f7fbe31d6d84fe880"
34063411
integrity sha512-t2GDMt3oGC/v+BMwzmllWDuJF/xcDtE5j/fCGbqDD7OLuJkj0cfh1YSA5VKPvwMeLFLNDBkwOKZ2X85jGLVftQ==
@@ -3610,16 +3615,16 @@ get-pkg-repo@^1.0.0:
36103615
parse-github-repo-url "^1.3.0"
36113616
through2 "^2.0.0"
36123617

3613-
3614-
version "5.1.1"
3615-
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193"
3616-
integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==
3617-
36183618
get-port@^4.2.0:
36193619
version "4.2.0"
36203620
resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119"
36213621
integrity sha512-/b3jarXkH8KJoOMQc3uVGHASwGLPq3gSFJ7tgJm2diza+bydJPTGOibin2steecKeOylE8oY2JERlVWkAJO6yw==
36223622

3623+
get-port@^5.1.1:
3624+
version "5.1.1"
3625+
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193"
3626+
integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==
3627+
36233628
get-stdin@^4.0.1:
36243629
version "4.0.1"
36253630
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
@@ -3900,14 +3905,6 @@ http-signature@~1.2.0:
39003905
jsprim "^1.2.2"
39013906
sshpk "^1.7.0"
39023907

3903-
3904-
version "5.0.0"
3905-
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
3906-
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
3907-
dependencies:
3908-
agent-base "6"
3909-
debug "4"
3910-
39113908
https-proxy-agent@^2.2.3:
39123909
version "2.2.4"
39133910
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz#4ee7a737abd92678a293d9b34a1af4d0d08c787b"
@@ -3916,6 +3913,14 @@ https-proxy-agent@^2.2.3:
39163913
agent-base "^4.3.0"
39173914
debug "^3.1.0"
39183915

3916+
https-proxy-agent@^5.0.0:
3917+
version "5.0.0"
3918+
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
3919+
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
3920+
dependencies:
3921+
agent-base "6"
3922+
debug "4"
3923+
39193924
human-signals@^1.1.1:
39203925
version "1.1.1"
39213926
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"

0 commit comments

Comments
 (0)