Skip to content

Commit 8100b2f

Browse files
committed
feat(MongoBinaryDownloadUrl::getDebianVersionString): use debian11 when possible
1 parent a56e02b commit 8100b2f

File tree

3 files changed

+79
-10
lines changed

3 files changed

+79
-10
lines changed

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,16 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
222222
let name = 'debian';
223223
const release: number = parseFloat(os.release);
224224

225-
// Note: Debian 11 is compatible with the binaries for debian 10
226-
if (release >= 10 || ['unstable', 'testing'].includes(os.release)) {
227-
if (semver.lt(this.version, '4.2.1')) {
228-
throw new KnownVersionIncompatibilityError(
229-
`Debian ${release}`,
230-
this.version,
231-
'>=4.2.1',
232-
'Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release'
233-
);
225+
if (release >= 11 || ['unstable', 'testing'].includes(os.release)) {
226+
// Debian 11 is compatible with the binaries for debian 10
227+
// but does not have binaries for before 5.0.8
228+
if (semver.lt(this.version, '5.0.8')) {
229+
log('debian11 detected, but version below 5.0.8 requested, using debian10');
230+
name += '10';
231+
} else {
232+
name += '11';
234233
}
235-
234+
} else if (release >= 10) {
236235
name += '10';
237236
} else if (release >= 9) {
238237
name += '92';
@@ -242,6 +241,17 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
242241
name += '71';
243242
}
244243

244+
if (release >= 10) {
245+
if (semver.lt(this.version, '4.2.1')) {
246+
throw new KnownVersionIncompatibilityError(
247+
`Debian ${release}`,
248+
this.version,
249+
'>=4.2.1',
250+
'Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release'
251+
);
252+
}
253+
}
254+
245255
return name;
246256
}
247257

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,38 @@ describe('MongoBinaryDownloadUrl', () => {
205205
);
206206
});
207207

208+
it('for debian 11 for 5.0.7 (using debian 10 binaries)', async () => {
209+
const du = new MongoBinaryDownloadUrl({
210+
platform: 'linux',
211+
arch: 'x64',
212+
version: '5.0.7',
213+
os: {
214+
os: 'linux',
215+
dist: 'debian',
216+
release: '11',
217+
},
218+
});
219+
expect(await du.getDownloadUrl()).toBe(
220+
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian10-5.0.7.tgz'
221+
);
222+
});
223+
224+
it('for debian 11 for 5.0.8', async () => {
225+
const du = new MongoBinaryDownloadUrl({
226+
platform: 'linux',
227+
arch: 'x64',
228+
version: '5.0.8',
229+
os: {
230+
os: 'linux',
231+
dist: 'debian',
232+
release: '11',
233+
},
234+
});
235+
expect(await du.getDownloadUrl()).toBe(
236+
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian11-5.0.8.tgz'
237+
);
238+
});
239+
208240
it('should throw a Error when requesting a version below 4.2.1 for debian 10+ [#554] [KnownVersionIncompatibilityError]', async () => {
209241
const du = new MongoBinaryDownloadUrl({
210242
platform: 'linux',
@@ -226,6 +258,28 @@ describe('MongoBinaryDownloadUrl', () => {
226258
expect(err.message).toMatchSnapshot();
227259
}
228260
});
261+
262+
it('should throw a Error when requesting a version below 4.2.1 for debian 11+ [#554] [KnownVersionIncompatibilityError]', async () => {
263+
const du = new MongoBinaryDownloadUrl({
264+
platform: 'linux',
265+
arch: 'x64',
266+
version: '4.0.25',
267+
os: {
268+
os: 'linux',
269+
dist: 'debian',
270+
release: '11',
271+
},
272+
});
273+
274+
try {
275+
await du.getDownloadUrl();
276+
fail('Expected to throw a KnownVersionIncompatibilityError');
277+
} catch (err) {
278+
assertIsError(err);
279+
expect(err).toBeInstanceOf(KnownVersionIncompatibilityError);
280+
expect(err.message).toMatchSnapshot();
281+
}
282+
});
229283
});
230284

231285
it('fallback', async () => {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for debian should thr
55
Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release"
66
`;
77

8+
exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for debian should throw a Error when requesting a version below 4.2.1 for debian 11+ [#554] [KnownVersionIncompatibilityError] 1`] = `
9+
"Requested Version \\"4.0.25\\" is not available for \\"Debian 11\\"! Available Versions: \\">=4.2.1\\"
10+
Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release"
11+
`;
12+
813
exports[`MongoBinaryDownloadUrl getDownloadUrl() should throw an error if platform is unknown (getArchiveName) 1`] = `"Unknown Platform: \\"unknown\\""`;
914

1015
exports[`MongoBinaryDownloadUrl getDownloadUrl() should throw an error if platform is unknown (translatePlatform) 1`] = `"Unknown Platform: \\"unknown\\""`;

0 commit comments

Comments
 (0)