@@ -477,19 +477,49 @@ describe('MongoBinaryDownloadUrl', () => {
477477 delete process . env [ envName ( ResolveConfigVariables . DOWNLOAD_URL ) ] ;
478478 } ) ;
479479
480- it ( 'should allow mirror overwrite with "DOWNLOAD_MIRROR"' , async ( ) => {
481- const archiveName = 'mongodb-linux-x86_64-4.0.0.tgz' ;
482- const mirror = 'https://custom.org' ;
483- process . env [ envName ( ResolveConfigVariables . DOWNLOAD_MIRROR ) ] = mirror ;
480+ describe ( 'overwrite with "DOWNLOAD_MIRROR" option' , ( ) => {
481+ const archiveName = 'mongodb-linux-x86_64-ubuntu1804-4.0.0.tgz' ;
482+ let mbdu : MongoBinaryDownloadUrl ;
484483
485- const du = new MongoBinaryDownloadUrl ( {
486- platform : 'linux' ,
487- arch : 'x64' ,
488- version : '3.6.3' ,
484+ beforeAll ( ( ) => {
485+ mbdu = new MongoBinaryDownloadUrl ( {
486+ platform : 'linux' ,
487+ arch : 'x64' ,
488+ version : '4.0.0' ,
489+ } ) ;
490+
491+ jest . spyOn ( mbdu , 'getArchiveName' ) . mockImplementation ( ( ) => Promise . resolve ( archiveName ) ) ;
492+ } ) ;
493+
494+ afterAll ( ( ) => {
495+ jest . restoreAllMocks ( ) ;
496+ } ) ;
497+
498+ afterEach ( ( ) => {
499+ delete process . env [ envName ( ResolveConfigVariables . DOWNLOAD_MIRROR ) ] ;
500+ } ) ;
501+
502+ it ( 'should allow mirror overwrite (only server name) with "DOWNLOAD_MIRROR"' , async ( ) => {
503+ const mirror = 'https://custom.org' ;
504+ process . env [ envName ( ResolveConfigVariables . DOWNLOAD_MIRROR ) ] = mirror ;
505+
506+ expect ( await mbdu . getDownloadUrl ( ) ) . toBe ( `${ mirror } /linux/${ archiveName } ` ) ;
507+ } ) ;
508+
509+ it ( 'should allow mirror overwrite (with extra path) with "DOWNLOAD_MIRROR" without extra "/"' , async ( ) => {
510+ const mirror = 'https://custom.org/extra/path' ;
511+ process . env [ envName ( ResolveConfigVariables . DOWNLOAD_MIRROR ) ] = mirror ;
512+
513+ expect ( await mbdu . getDownloadUrl ( ) ) . toBe ( `${ mirror } /linux/${ archiveName } ` ) ;
514+ } ) ;
515+
516+ it ( 'should allow mirror overwrite (with extra path) with "DOWNLOAD_MIRROR" with extra "/"' , async ( ) => {
517+ const mirror = 'https://custom.org/extra/path/' ;
518+ process . env [ envName ( ResolveConfigVariables . DOWNLOAD_MIRROR ) ] = mirror ;
519+
520+ // no extra "/" because "mirror" already contains it
521+ expect ( await mbdu . getDownloadUrl ( ) ) . toBe ( `${ mirror } linux/${ archiveName } ` ) ;
489522 } ) ;
490- jest . spyOn ( du , 'getArchiveName' ) . mockImplementationOnce ( ( ) => Promise . resolve ( archiveName ) ) ;
491- expect ( await du . getDownloadUrl ( ) ) . toBe ( `${ mirror } /linux/${ archiveName } ` ) ;
492- delete process . env [ envName ( ResolveConfigVariables . ARCHIVE_NAME ) ] ;
493523 } ) ;
494524
495525 it ( 'should throw an error if platform is unknown (getArchiveName)' , async ( ) => {
0 commit comments