Skip to content

Commit

Permalink
fix: Fix binary download on debian testing/unstable
Browse files Browse the repository at this point in the history
  • Loading branch information
orgads committed Aug 17, 2023
1 parent 36bc050 commit 3316a95
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import MongoBinary from '../../util/MongoBinary';
import { getOS, isDebian10OrHigher } from '../../util/getos';
import resolveConfig, { ResolveConfigVariables } from '../../util/resolveConfig';
import { assertion, isNullOrUndefined } from '../../util/utils';

export = async function globalSetup(): Promise<void> {
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 });
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
UnexpectedCloseError,
} from '../errors';
import { assertIsError } from '../../__tests__/testUtils/test_utils';
import { getOS, isDebian10OrHigher } from '../getos';

jest.setTimeout(100000); // 10s

Expand Down Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
Expand Down
8 changes: 8 additions & 0 deletions packages/mongodb-memory-server-core/src/util/getos/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down

0 comments on commit 3316a95

Please sign in to comment.