diff --git a/packages/mongodb-memory-server-core/src/__tests__/testUtils/globalSetup.ts b/packages/mongodb-memory-server-core/src/__tests__/testUtils/globalSetup.ts index c563919ad..f61509608 100644 --- a/packages/mongodb-memory-server-core/src/__tests__/testUtils/globalSetup.ts +++ b/packages/mongodb-memory-server-core/src/__tests__/testUtils/globalSetup.ts @@ -1,4 +1,5 @@ import MongoBinary from '../../util/MongoBinary'; +import { getOS, isDebian10OrHigher } from '../../util/getos'; import resolveConfig, { ResolveConfigVariables } from '../../util/resolveConfig'; import { assertion, isNullOrUndefined } from '../../util/utils'; @@ -6,8 +7,11 @@ export = async function globalSetup(): Promise { const defaultVersion = resolveConfig(ResolveConfigVariables.VERSION); assertion(!isNullOrUndefined(defaultVersion), new Error('Default version is not defined')); const versions = [defaultVersion, '4.0.28', '4.2.23', '4.4.22', '5.0.19', '6.0.6']; + const isNewDebian = isDebian10OrHigher(await getOS()); // Ensure all required versions are downloaded for tests for (const version of versions) { - await MongoBinary.getPath({ version }); + if (!isNewDebian || parseFloat(version) >= 4.2) { + await MongoBinary.getPath({ version }); + } } }; diff --git a/packages/mongodb-memory-server-core/src/util/MongoBinaryDownloadUrl.ts b/packages/mongodb-memory-server-core/src/util/MongoBinaryDownloadUrl.ts index e0721f98c..7c59488b1 100644 --- a/packages/mongodb-memory-server-core/src/util/MongoBinaryDownloadUrl.ts +++ b/packages/mongodb-memory-server-core/src/util/MongoBinaryDownloadUrl.ts @@ -289,7 +289,9 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts { throw new UnknownVersionError(this.version); } - if (release >= 11 || ['unstable', 'testing'].includes(os.release)) { + const isTesting = ['unstable', 'testing', ''].includes(os.release); + + if (isTesting || release >= 11) { // Debian 11 is compatible with the binaries for debian 10 // but does not have binaries for before 5.0.8 // and only set to use "debian10" if the requested version is not a latest version @@ -309,10 +311,10 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts { name += '71'; } - if (release >= 10) { + if (isTesting || release >= 10) { if (semver.lt(coercedVersion, '4.2.1') && !testVersionIsLatest(this.version)) { throw new KnownVersionIncompatibilityError( - `Debian ${release}`, + `Debian ${release || os.release || os.codename}`, this.version, '>=4.2.1', 'Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release' diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/MongoBinaryDownloadUrl.test.ts b/packages/mongodb-memory-server-core/src/util/__tests__/MongoBinaryDownloadUrl.test.ts index 4e868c70e..7f23aeb07 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/MongoBinaryDownloadUrl.test.ts +++ b/packages/mongodb-memory-server-core/src/util/__tests__/MongoBinaryDownloadUrl.test.ts @@ -554,6 +554,22 @@ describe('MongoBinaryDownloadUrl', () => { ); }); + it('for debian testing/unstable', async () => { + const du = new MongoBinaryDownloadUrl({ + platform: 'linux', + arch: 'x64', + version: '5.0.9', + os: { + os: 'linux', + dist: 'debian', + release: '', + }, + }); + expect(await du.getDownloadUrl()).toBe( + 'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian11-5.0.9.tgz' + ); + }); + it('should throw a Error when the provided version could not be coerced [UnknownVersionError]', async () => { const du = new MongoBinaryDownloadUrl({ platform: 'linux', @@ -635,6 +651,29 @@ describe('MongoBinaryDownloadUrl', () => { expect(err.message).toMatchSnapshot(); } }); + + it('should throw a Error when requesting a version below 4.2.1 for debian testing [KnownVersionIncompatibilityError]', async () => { + const du = new MongoBinaryDownloadUrl({ + platform: 'linux', + arch: 'x64', + version: '4.0.25', + os: { + os: 'linux', + dist: 'debian', + codename: 'trixie', + release: '', + }, + }); + + try { + await du.getDownloadUrl(); + fail('Expected to throw a KnownVersionIncompatibilityError'); + } catch (err) { + assertIsError(err); + expect(err).toBeInstanceOf(KnownVersionIncompatibilityError); + expect(err.message).toMatchSnapshot(); + } + }); }); // for arch and arch based systems (no specific extra mapping) diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/MongoInstance.test.ts b/packages/mongodb-memory-server-core/src/util/__tests__/MongoInstance.test.ts index 1bfa1cadd..5e924330d 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/MongoInstance.test.ts +++ b/packages/mongodb-memory-server-core/src/util/__tests__/MongoInstance.test.ts @@ -10,6 +10,7 @@ import { UnexpectedCloseError, } from '../errors'; import { assertIsError } from '../../__tests__/testUtils/test_utils'; +import { getOS, isDebian10OrHigher } from '../getos'; jest.setTimeout(100000); // 10s @@ -209,13 +210,17 @@ describe('MongodbInstance', () => { describe('should work with mongodb LTS releases', () => { it('should work with mongodb 4.0', async () => { - const gotPort = await getPort({ port: 27445 }); - const mongod = await MongodbInstance.create({ - instance: { port: gotPort, dbPath: tmpDir }, - binary: { version: '4.0.28' }, // explicit version instead of default to not mess it up later - }); - expect(mongod.mongodProcess!.pid).toBeGreaterThan(0); - await mongod.stop(); + const os = await getOS(); + + if (!isDebian10OrHigher(os)) { + const gotPort = await getPort({ port: 27445 }); + const mongod = await MongodbInstance.create({ + instance: { port: gotPort, dbPath: tmpDir }, + binary: { version: '4.0.28' }, // explicit version instead of default to not mess it up later + }); + expect(mongod.mongodProcess!.pid).toBeGreaterThan(0); + await mongod.stop(); + } }); it('should work with mongodb 4.2', async () => { diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/MongoBinaryDownloadUrl.test.ts.snap b/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/MongoBinaryDownloadUrl.test.ts.snap index 9b1758660..7db8f86ec 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/MongoBinaryDownloadUrl.test.ts.snap +++ b/packages/mongodb-memory-server-core/src/util/__tests__/__snapshots__/MongoBinaryDownloadUrl.test.ts.snap @@ -10,6 +10,11 @@ exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for debian should thr Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release" `; +exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for debian should throw a Error when requesting a version below 4.2.1 for debian testing [KnownVersionIncompatibilityError] 1`] = ` +"Requested Version \\"4.0.25\\" is not available for \\"Debian trixie\\"! Available Versions: \\">=4.2.1\\" +Mongodb does not provide binaries for versions before 4.2.1 for Debian 10+ and also cannot be mapped to a previous Debian release" +`; + exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for debian should throw a Error when the provided version could not be coerced [UnknownVersionError] 1`] = `"Could not corece VERSION to a semver version (version: \\"vvv\\")"`; exports[`MongoBinaryDownloadUrl getDownloadUrl() for linux for rhel should Error when ARM64 and rhel below 8 [KnownVersionIncompatibilityError] 1`] = ` diff --git a/packages/mongodb-memory-server-core/src/util/getos/index.ts b/packages/mongodb-memory-server-core/src/util/getos/index.ts index cacf5dd96..0e369be0e 100644 --- a/packages/mongodb-memory-server-core/src/util/getos/index.ts +++ b/packages/mongodb-memory-server-core/src/util/getos/index.ts @@ -131,6 +131,14 @@ export function isValidOs(os: LinuxOS | undefined): os is LinuxOS { return !isNullOrUndefined(os) && os.dist !== UNKNOWN; } +export function isDebian10OrHigher(os: AnyOS): boolean { + if (!isLinuxOS(os) || os.dist !== 'debian') { + return false; + } + + return ['unstable', 'testing', ''].includes(os.release) || parseFloat(os.release) >= 10; +} + /** * Parse LSB-like output (either command or file) */