Skip to content

Commit 690aa42

Browse files
committed
fix(MongoBinaryDownloadUrl): handle cases where patch version is checked and "-latest" was requested
1 parent 7c2d490 commit 690aa42

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
254254
if (release >= 11 || ['unstable', 'testing'].includes(os.release)) {
255255
// Debian 11 is compatible with the binaries for debian 10
256256
// but does not have binaries for before 5.0.8
257-
if (semver.lt(coercedVersion, '5.0.8')) {
257+
// and only set to use "debian10" if the requested version is not a latest version
258+
if (semver.lt(coercedVersion, '5.0.8') && !testVersionIsLatest(this.version)) {
258259
log('debian11 detected, but version below 5.0.8 requested, using debian10');
259260
name += '10';
260261
} else {
@@ -271,7 +272,7 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
271272
}
272273

273274
if (release >= 10) {
274-
if (semver.lt(coercedVersion, '4.2.1')) {
275+
if (semver.lt(coercedVersion, '4.2.1') && !testVersionIsLatest(this.version)) {
275276
throw new KnownVersionIncompatibilityError(
276277
`Debian ${release}`,
277278
this.version,
@@ -337,7 +338,7 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
337338
}
338339
// there are no versions for aarch64 before mongodb 4.4.2
339340
// Note: version 4.4.2 and 4.4.3 are NOT listed at the list, but are existing; list: https://www.mongodb.com/download-center/community/releases/archive
340-
if (semver.lt(coercedVersion, '4.4.2')) {
341+
if (semver.lt(coercedVersion, '4.4.2') && !testVersionIsLatest(this.version)) {
341342
throw new KnownVersionIncompatibilityError(`Rhel ${release}`, this.version, '>=4.4.2');
342343
}
343344

@@ -602,3 +603,8 @@ function regexHelper(regex: RegExp, os: LinuxOS): boolean {
602603
(!isNullOrUndefined(os.id_like) ? os.id_like.filter((v) => regex.test(v)).length >= 1 : false)
603604
);
604605
}
606+
607+
/** Helper to consistently test if a version is a "-latest" version, like "v5.0-latest" */
608+
function testVersionIsLatest(version: string): boolean {
609+
return /^v\d+\.\d+-latest$/.test(version);
610+
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,22 @@ describe('MongoBinaryDownloadUrl', () => {
490490
);
491491
});
492492

493+
it('for debian 11 for v5.0-latest', async () => {
494+
const du = new MongoBinaryDownloadUrl({
495+
platform: 'linux',
496+
arch: 'x64',
497+
version: 'v5.0-latest',
498+
os: {
499+
os: 'linux',
500+
dist: 'debian',
501+
release: '11',
502+
},
503+
});
504+
expect(await du.getDownloadUrl()).toBe(
505+
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian11-v5.0-latest.tgz'
506+
);
507+
});
508+
493509
it('for debian 11 for 6.0.0', async () => {
494510
const du = new MongoBinaryDownloadUrl({
495511
platform: 'linux',
@@ -566,6 +582,22 @@ describe('MongoBinaryDownloadUrl', () => {
566582
}
567583
});
568584

585+
it('should not throw a error for v4.2-latest for debian 10+', async () => {
586+
const du = new MongoBinaryDownloadUrl({
587+
platform: 'linux',
588+
arch: 'x64',
589+
version: 'v4.2-latest',
590+
os: {
591+
os: 'linux',
592+
dist: 'debian',
593+
release: '10',
594+
},
595+
});
596+
expect(await du.getDownloadUrl()).toBe(
597+
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-v4.2-latest.tgz'
598+
);
599+
});
600+
569601
it('should throw a Error when requesting a version below 4.2.1 for debian 11+ [#554] [KnownVersionIncompatibilityError]', async () => {
570602
const du = new MongoBinaryDownloadUrl({
571603
platform: 'linux',
@@ -1087,6 +1119,22 @@ describe('MongoBinaryDownloadUrl', () => {
10871119
}
10881120
});
10891121

1122+
it('should not throw a error for arm64 v4.4-latest', async () => {
1123+
const du = new MongoBinaryDownloadUrl({
1124+
platform: 'linux',
1125+
arch: 'arm64',
1126+
version: 'v4.4-latest',
1127+
os: {
1128+
os: 'linux',
1129+
dist: 'rhel',
1130+
release: '8.2',
1131+
},
1132+
});
1133+
expect(await du.getDownloadUrl()).toBe(
1134+
'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel82-v4.4-latest.tgz'
1135+
);
1136+
});
1137+
10901138
it('should warn when a unhandled RHEL release is used', async () => {
10911139
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => void 0);
10921140

0 commit comments

Comments
 (0)