Skip to content

Commit bfb0ec4

Browse files
committed
feat(MongoBinaryDownloadUrl): change to throw a error when debian 10 used for versions below 4.2.0
fixes #554 re #448
1 parent f961857 commit bfb0ec4

File tree

4 files changed

+47
-12
lines changed

4 files changed

+47
-12
lines changed

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

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import * as semver from 'semver';
55
import { isNullOrUndefined } from './utils';
66
import { BaseDryMongoBinaryOptions, DryMongoBinary } from './DryMongoBinary';
77
import { URL } from 'url';
8-
import { UnknownArchitectureError, UnknownPlatformError } from './errors';
8+
import {
9+
KnownVersionIncompatibilityError,
10+
UnknownArchitectureError,
11+
UnknownPlatformError,
12+
} from './errors';
913

1014
const log = debug('MongoMS:MongoBinaryDownloadUrl');
1115

@@ -220,14 +224,16 @@ export class MongoBinaryDownloadUrl implements MongoBinaryDownloadUrlOpts {
220224
const release: number = parseFloat(os.release);
221225

222226
if (release >= 10 || ['unstable', 'testing'].includes(os.release)) {
223-
if (semver.lte(this.version, '4.2.0')) {
224-
log(
225-
`getDebianVersionString: requested version "${this.version}" not available for osrelease "${release}", using "92"`
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'
226233
);
227-
name += '92';
228-
} else {
229-
name += '10';
230234
}
235+
236+
name += '10';
231237
} else if (release >= 9) {
232238
name += '92';
233239
} else if (release >= 8.1) {

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { assertIsError } from '../../__tests__/testUtils/test_utils';
2-
import { UnknownPlatformError, UnknownArchitectureError } from '../errors';
2+
import {
3+
UnknownPlatformError,
4+
UnknownArchitectureError,
5+
KnownVersionIncompatibilityError,
6+
} from '../errors';
37
import { LinuxOS } from '../getos';
48
import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl';
59
import { envName, ResolveConfigVariables } from '../resolveConfig';
@@ -169,7 +173,7 @@ describe('MongoBinaryDownloadUrl', () => {
169173
);
170174
});
171175

172-
it('for debian 10 for 4.0.25 should use debian 92 [#448]', async () => {
176+
it('should throw a Error when requesting a version below 4.2.1 for debian 10+ [#554] [KnownVersionIncompatibilityError]', async () => {
173177
const du = new MongoBinaryDownloadUrl({
174178
platform: 'linux',
175179
arch: 'x64',
@@ -180,9 +184,15 @@ describe('MongoBinaryDownloadUrl', () => {
180184
release: '10',
181185
},
182186
});
183-
expect(await du.getDownloadUrl()).toBe(
184-
'https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-debian92-4.0.25.tgz'
185-
);
187+
188+
try {
189+
await du.getDownloadUrl();
190+
fail('Expected to throw a KnownVersionIncompatibilityError');
191+
} catch (err) {
192+
assertIsError(err);
193+
expect(err).toBeInstanceOf(KnownVersionIncompatibilityError);
194+
expect(err.message).toMatchSnapshot();
195+
}
186196
});
187197
});
188198

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
@@ -1,5 +1,10 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

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

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,17 @@ export class NoRegexMatchError extends Error {
145145
this.message = `Expected "${name}" to have Regex Matches${addExtra}`;
146146
}
147147
}
148+
149+
export class KnownVersionIncompatibilityError extends Error {
150+
constructor(
151+
public dist: string,
152+
public requested_version: string,
153+
public available_versions: string,
154+
public extra?: string
155+
) {
156+
super();
157+
158+
const addExtra = !!extra ? `\n${extra}` : '';
159+
this.message = `Requested Version "${requested_version}" is not available for "${dist}"! Available Versions: "${available_versions}"${addExtra}`;
160+
}
161+
}

0 commit comments

Comments
 (0)