Skip to content

Commit 8f9ac31

Browse files
committed
test(MongoBinaryDownloadUrl): add test for "getDownloadUrl" and "DOWNLOAD_URL"
1 parent 7a8a4c3 commit 8f9ac31

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { LinuxOS } from '../getos';
22
import MongoBinaryDownloadUrl from '../MongoBinaryDownloadUrl';
3-
import { defaultValues, ResolveConfigVariables, setDefaultValue } from '../resolveConfig';
3+
import { envName, ResolveConfigVariables } from '../resolveConfig';
44

55
afterEach(() => {
66
jest.restoreAllMocks();
@@ -360,16 +360,32 @@ describe('MongoBinaryDownloadUrl', () => {
360360
});
361361
});
362362

363-
it('should allow overwrite with "ARCHIVE_NAME"', async () => {
363+
it('should allow archive overwrite with "ARCHIVE_NAME"', async () => {
364364
const archiveName = 'mongodb-linux-x86_64-4.0.0.tgz';
365-
setDefaultValue(ResolveConfigVariables.ARCHIVE_NAME, archiveName);
365+
process.env[envName(ResolveConfigVariables.ARCHIVE_NAME)] = archiveName;
366+
366367
const du = new MongoBinaryDownloadUrl({
367368
platform: 'linux',
368369
arch: 'x64',
369370
version: '3.6.3',
370371
});
371372
expect(await du.getDownloadUrl()).toBe(`https://fastdl.mongodb.org/linux/${archiveName}`);
372-
defaultValues.delete(ResolveConfigVariables.ARCHIVE_NAME);
373+
delete process.env[envName(ResolveConfigVariables.ARCHIVE_NAME)];
374+
});
375+
376+
it('should allow full url overwrite with "DOWNLOAD_URL"', async () => {
377+
const downloadUrl = 'https://custom.org/customarchive.tgz';
378+
process.env[envName(ResolveConfigVariables.DOWNLOAD_URL)] = downloadUrl;
379+
380+
const du = new MongoBinaryDownloadUrl({
381+
platform: 'linux',
382+
arch: 'x64',
383+
version: '3.6.3',
384+
});
385+
jest.spyOn(du, 'getArchiveName');
386+
expect(await du.getDownloadUrl()).toBe(downloadUrl);
387+
expect(du.getArchiveName).not.toHaveBeenCalled();
388+
delete process.env[envName(ResolveConfigVariables.DOWNLOAD_URL)];
373389
});
374390

375391
it('should throw an error if platform is unknown (getArchiveName)', async () => {

0 commit comments

Comments
 (0)