Skip to content

Commit

Permalink
fix: change mongodb version tests to use semver
Browse files Browse the repository at this point in the history
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
  • Loading branch information
hasezoey committed Aug 24, 2020
1 parent d14ab81 commit 31183dd
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 58 deletions.
2 changes: 2 additions & 0 deletions packages/mongodb-memory-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"@types/lockfile": "^1.0.1",
"@types/md5-file": "^4.0.2",
"@types/mkdirp": "^1.0.1",
"@types/semver": "^7.3.3",
"@types/tmp": "^0.2.0",
"@types/uuid": "^8.0.0",
"camelcase": "^6.0.0",
Expand All @@ -70,6 +71,7 @@
"lockfile": "^1.0.4",
"md5-file": "^5.0.0",
"mkdirp": "^1.0.4",
"semver": "^7.3.2",
"tar-stream": "^2.1.3",
"tmp": "^0.2.1",
"uuid": "^8.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import getOS, { AnyOS, LinuxOS } from './getos';
import { execSync } from 'child_process';
import resolveConfig from './resolve-config';
import debug from 'debug';
import * as semver from 'semver';

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

Expand Down Expand Up @@ -72,9 +73,9 @@ export default class MongoBinaryDownloadUrl {
async getArchiveNameWin(): Promise<string> {
let name = `mongodb-${this.platform}`;
name += `-${this.arch}`;
if (this.version.startsWith('4.2')) {
if (semver.satisfies(this.version, '4.2.x')) {
name += '-2012plus';
} else if (/^[1-3]\./.test(this.version)) {
} else if (semver.lt(this.version, '4.0.0')) {
name += '-2008plus-ssl';
}
name += `-${this.version}.zip`;
Expand All @@ -87,17 +88,11 @@ export default class MongoBinaryDownloadUrl {
*/
async getArchiveNameOsx(): Promise<string> {
let name = `mongodb-osx`;
if (
!(
this.version.startsWith('3.0') ||
this.version.startsWith('2.') ||
this.version.startsWith('1.')
)
) {
if (semver.gte(this.version, '3.2.0')) {
name += '-ssl';
}
if (this.version.startsWith('4.')) {
name = `mongodb-macos`;
if (semver.gte(this.version, '4.2.0')) {
name = `mongodb-macos`; // somehow these files are not listed in https://www.mongodb.org/dl/osx
}
name += `-${this.arch}`;
name += `-${this.version}.tgz`;
Expand Down Expand Up @@ -145,7 +140,7 @@ export default class MongoBinaryDownloadUrl {
return this.getFedoraVersionString(os);
} else if (/debian/i.test(os.dist)) {
return this.getDebianVersionString(os);
} else if (/mint/i.test(os.dist)) {
} else if (/\s+mint\s*$/i.test(os.dist)) {
return this.getMintVersionString(os);
} else if (/arch/i.test(os.dist)) {
console.warn('There is no offical build of MongoDB for ArchLinux!');
Expand Down Expand Up @@ -337,7 +332,7 @@ export default class MongoBinaryDownloadUrl {
case 'darwin':
return 'osx';
case 'win32':
return /^(4\.[4-9]|[5-9])/.test(this.version) ? 'windows' : 'win32';
return semver.gte(this.version, '4.3.0') ? 'windows' : 'win32';
case 'linux':
case 'elementary OS':
return 'linux';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,39 @@ describe('MongoBinaryDownloadUrl', () => {
);
});

it('for win32', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'win32',
arch: 'x64',
version: '3.6.3',
describe('for win32 & windows', () => {
it('3.6 (win32)', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'win32',
arch: 'x64',
version: '3.6.3',
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.3.zip'
);
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-3.6.3.zip'
);
});

it('4.2 for win32', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'win32',
arch: 'x64',
version: '4.2.0',
it('4.2 (win32)', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'win32',
arch: 'x64',
version: '4.2.0',
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.0.zip'
);
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/win32/mongodb-win32-x86_64-2012plus-4.2.0.zip'
);
});

it('4.4 for win32', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'win32',
arch: 'x64',
version: '4.4.0',
it('4.4 (windows)', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'win32',
arch: 'x64',
version: '4.4.0',
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-4.4.0.zip'
);
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/windows/mongodb-windows-x86_64-4.4.0.zip'
);
});

it('fallback', async () => {
Expand Down Expand Up @@ -287,6 +289,22 @@ describe('MongoBinaryDownloadUrl', () => {
});
});

it('shouldnt detect linux mint when using peppermint', () => {
const downloadUrl = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'x64',
version: '3.6.3',
});

expect(
downloadUrl.getLinuxOSVersionString({
os: 'linux',
dist: 'Peppermint',
release: '10',
})
).toBe('');
});

describe('getLegacyVersionString', () => {
const downloadUrl = new MongoBinaryDownloadUrl({
platform: 'linux',
Expand Down
43 changes: 24 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,11 @@
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.0.2.tgz#5bb52ee68d0f8efa9cc0099920e56be6cc4e37f3"
integrity sha512-IkVfat549ggtkZUthUzEX49562eGikhSYeVGX97SkMFn+sTZrgRewXjQ4tPKFPCykZHkX1Zfd9OoELGqKU2jJA==

"@types/semver@^7.3.3":
version "7.3.3"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.3.tgz#3ad6ed949e7487e7bda6f886b4a2434a2c3d7b1a"
integrity sha512-jQxClWFzv9IXdLdhSaTf16XI3NYe6zrEbckSpb5xhKfPbWgIyAY0AFyWWWfaiDcBuj3UHmMkCIwSRqpKMTZL2Q==

"@types/stack-utils@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
Expand All @@ -1552,15 +1557,15 @@
dependencies:
"@types/node" "*"

"@types/tmp@0.2.0":
"@types/tmp@^0.2.0":
version "0.2.0"
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.2.0.tgz#e3f52b4d7397eaa9193592ef3fdd44dc0af4298c"
integrity sha512-flgpHJjntpBAdJD43ShRosQvNC0ME97DCfGvZEDlAThQmnerRXrLbX6YgzRBQCZTthET9eAWFAMaYP0m0Y4HzQ==

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

"@types/yargs-parser@*":
version "15.0.0"
Expand Down Expand Up @@ -3400,7 +3405,7 @@ fill-range@^7.0.1:
dependencies:
to-regex-range "^5.0.1"

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

get-port@5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193"
integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==

get-port@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-4.2.0.tgz#e37368b1e863b7629c43c5a323625f95cf24b119"
integrity sha512-/b3jarXkH8KJoOMQc3uVGHASwGLPq3gSFJ7tgJm2diza+bydJPTGOibin2steecKeOylE8oY2JERlVWkAJO6yw==

get-port@^5.1.1:
version "5.1.1"
resolved "https://registry.yarnpkg.com/get-port/-/get-port-5.1.1.tgz#0469ed07563479de6efb986baf053dcd7d4e3193"
integrity sha512-g/Q1aTSDOxFpchXC4i8ZWvxA1lnPqx/JHqcpIw0/LX9T8x/GBbi6YnlN5nhaKIFkT8oFsscUKgDJYxfwfS6QsQ==

get-stdin@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"
Expand Down Expand Up @@ -3900,14 +3905,6 @@ http-signature@~1.2.0:
jsprim "^1.2.2"
sshpk "^1.7.0"

https-proxy-agent@5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
dependencies:
agent-base "6"
debug "4"

https-proxy-agent@^2.2.3:
version "2.2.4"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz#4ee7a737abd92678a293d9b34a1af4d0d08c787b"
Expand All @@ -3916,6 +3913,14 @@ https-proxy-agent@^2.2.3:
agent-base "^4.3.0"
debug "^3.1.0"

https-proxy-agent@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz#e2a90542abb68a762e0a0850f6c9edadfd8506b2"
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
dependencies:
agent-base "6"
debug "4"

human-signals@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-1.1.1.tgz#c5b1cd14f50aeae09ab6c59fe63ba3395fe4dfa3"
Expand Down

0 comments on commit 31183dd

Please sign in to comment.