Skip to content

Commit

Permalink
fix(MongoBinaryDownloadUrl): handle cases where patch version is chec…
Browse files Browse the repository at this point in the history
…ked and "-latest" was requested
  • Loading branch information
hasezoey committed Jan 17, 2023
1 parent 7c2d490 commit 690aa42
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 3 deletions.
Expand Up @@ -254,7 +254,8 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
if (release >= 11 || ['unstable', 'testing'].includes(os.release)) {
// Debian 11 is compatible with the binaries for debian 10
// but does not have binaries for before 5.0.8
if (semver.lt(coercedVersion, '5.0.8')) {
// and only set to use "debian10" if the requested version is not a latest version
if (semver.lt(coercedVersion, '5.0.8') && !testVersionIsLatest(this.version)) {
log('debian11 detected, but version below 5.0.8 requested, using debian10');
name += '10';
} else {
Expand All @@ -271,7 +272,7 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
}

if (release >= 10) {
if (semver.lt(coercedVersion, '4.2.1')) {
if (semver.lt(coercedVersion, '4.2.1') && !testVersionIsLatest(this.version)) {
throw new KnownVersionIncompatibilityError(
`Debian ${release}`,
this.version,
Expand Down Expand Up @@ -337,7 +338,7 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
}
// there are no versions for aarch64 before mongodb 4.4.2
// 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
if (semver.lt(coercedVersion, '4.4.2')) {
if (semver.lt(coercedVersion, '4.4.2') && !testVersionIsLatest(this.version)) {
throw new KnownVersionIncompatibilityError(`Rhel ${release}`, this.version, '>=4.4.2');
}

Expand Down Expand Up @@ -602,3 +603,8 @@ function regexHelper(regex: RegExp, os: LinuxOS): boolean {
(!isNullOrUndefined(os.id_like) ? os.id_like.filter((v) => regex.test(v)).length >= 1 : false)
);
}

/** Helper to consistently test if a version is a "-latest" version, like "v5.0-latest" */
function testVersionIsLatest(version: string): boolean {
return /^v\d+\.\d+-latest$/.test(version);
}
Expand Up @@ -490,6 +490,22 @@ describe('MongoBinaryDownloadUrl', () => {
);
});

it('for debian 11 for v5.0-latest', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'x64',
version: 'v5.0-latest',
os: {
os: 'linux',
dist: 'debian',
release: '11',
},
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian11-v5.0-latest.tgz'
);
});

it('for debian 11 for 6.0.0', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
Expand Down Expand Up @@ -566,6 +582,22 @@ describe('MongoBinaryDownloadUrl', () => {
}
});

it('should not throw a error for v4.2-latest for debian 10+', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'x64',
version: 'v4.2-latest',
os: {
os: 'linux',
dist: 'debian',
release: '10',
},
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-v4.2-latest.tgz'
);
});

it('should throw a Error when requesting a version below 4.2.1 for debian 11+ [#554] [KnownVersionIncompatibilityError]', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
Expand Down Expand Up @@ -1087,6 +1119,22 @@ describe('MongoBinaryDownloadUrl', () => {
}
});

it('should not throw a error for arm64 v4.4-latest', async () => {
const du = new MongoBinaryDownloadUrl({
platform: 'linux',
arch: 'arm64',
version: 'v4.4-latest',
os: {
os: 'linux',
dist: 'rhel',
release: '8.2',
},
});
expect(await du.getDownloadUrl()).toBe(
'https://fastdl.mongodb.org/linux/mongodb-linux-aarch64-rhel82-v4.4-latest.tgz'
);
});

it('should warn when a unhandled RHEL release is used', async () => {
const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementationOnce(() => void 0);

Expand Down

0 comments on commit 690aa42

Please sign in to comment.