Skip to content

Commit

Permalink
feat(MongoBinaryDownload): remove aliases for "binaryOpts"
Browse files Browse the repository at this point in the history
BREAKING CHANGE:
aliases for ".binaryOpts.*" have been removed, use ".binaryOpts.option" instead
  • Loading branch information
hasezoey committed May 8, 2023
1 parent 7463fdc commit 4bb3420
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 56 deletions.
64 changes: 12 additions & 52 deletions packages/mongodb-memory-server-core/src/util/MongoBinaryDownload.ts
Expand Up @@ -35,49 +35,6 @@ export class MongoBinaryDownload {
/**These options are kind of raw, they are not run through DryMongoBinary.generateOptions */
binaryOpts: Required<MongoBinaryOpts>;

// TODO: for an major version, remove the compat get/set
// the following get/set are to not break existing stuff

get checkMD5(): boolean {
return this.binaryOpts.checkMD5;
}

set checkMD5(val: boolean) {
this.binaryOpts.checkMD5 = val;
}

get downloadDir(): string {
return this.binaryOpts.downloadDir;
}

set downloadDir(val: string) {
this.binaryOpts.downloadDir = val;
}

get arch(): string {
return this.binaryOpts.arch;
}

set arch(val: string) {
this.binaryOpts.arch = val;
}

get version(): string {
return this.binaryOpts.version;
}

set version(val: string) {
this.binaryOpts.version = val;
}

get platform(): string {
return this.binaryOpts.platform;
}

set platform(val: string) {
this.binaryOpts.platform = val;
}

// end get/set backwards compat section

constructor(opts: MongoBinaryOpts) {
Expand Down Expand Up @@ -115,7 +72,7 @@ export class MongoBinaryDownload {
const opts = await DryMongoBinary.generateOptions(this.binaryOpts);

return DryMongoBinary.combineBinaryName(
this.downloadDir,
this.binaryOpts.downloadDir,
await DryMongoBinary.getBinaryName(opts)
);
}
Expand Down Expand Up @@ -153,13 +110,13 @@ export class MongoBinaryDownload {
log('startDownload');
const mbdUrl = new MongoBinaryDownloadUrl(this.binaryOpts);

await mkdir(this.downloadDir);
await mkdir(this.binaryOpts.downloadDir);

try {
await fspromises.access(this.downloadDir, constants.X_OK | constants.W_OK); // check that this process has permissions to create files & modify file contents & read file contents
await fspromises.access(this.binaryOpts.downloadDir, constants.X_OK | constants.W_OK); // check that this process has permissions to create files & modify file contents & read file contents
} catch (err) {
console.error(
`Download Directory at "${this.downloadDir}" does not have sufficient permissions to be used by this process\n` +
`Download Directory at "${this.binaryOpts.downloadDir}" does not have sufficient permissions to be used by this process\n` +
'Needed Permissions: Write & Execute (-wx)\n'
);
throw err;
Expand Down Expand Up @@ -189,7 +146,7 @@ export class MongoBinaryDownload {
): Promise<boolean | undefined> {
log('makeMD5check: Checking MD5 of downloaded binary...');

if (!this.checkMD5) {
if (!this.binaryOpts.checkMD5) {
log('makeMD5check: checkMD5 is disabled');

return undefined;
Expand Down Expand Up @@ -246,8 +203,11 @@ export class MongoBinaryDownload {
throw new Error(`MongoBinaryDownload: missing filename for url "${downloadUrl}"`);
}

const downloadLocation = path.resolve(this.downloadDir, filename);
const tempDownloadLocation = path.resolve(this.downloadDir, `${filename}.downloading`);
const downloadLocation = path.resolve(this.binaryOpts.downloadDir, filename);
const tempDownloadLocation = path.resolve(
this.binaryOpts.downloadDir,
`${filename}.downloading`
);
log(`download: Downloading${proxy ? ` via proxy "${proxy}"` : ''}: "${downloadUrl}"`);

if (await pathExists(downloadLocation)) {
Expand Down Expand Up @@ -500,8 +460,8 @@ export class MongoBinaryDownload {
Math.round(((100.0 * this.dlProgress.current) / this.dlProgress.length) * 10) / 10;
const mbComplete = Math.round((this.dlProgress.current / 1048576) * 10) / 10;

const crReturn = this.platform === 'win32' ? '\x1b[0G' : '\r';
const message = `Downloading MongoDB "${this.version}": ${percentComplete}% (${mbComplete}mb / ${this.dlProgress.totalMb}mb)${crReturn}`;
const crReturn = this.binaryOpts.platform === 'win32' ? '\x1b[0G' : '\r';
const message = `Downloading MongoDB "${this.binaryOpts.version}": ${percentComplete}% (${mbComplete}mb / ${this.dlProgress.totalMb}mb)${crReturn}`;

if (process.stdout.isTTY) {
// if TTY overwrite last line over and over until finished and clear line to avoid residual characters
Expand Down
Expand Up @@ -19,15 +19,19 @@ describe('MongoBinaryDownload', () => {
});

it('checkMD5 attribute can be set via constructor parameter', () => {
expect(new MongoBinaryDownload({ checkMD5: true, downloadDir: '/' }).checkMD5).toBe(true);
expect(new MongoBinaryDownload({ checkMD5: false, downloadDir: '/' }).checkMD5).toBe(false);
expect(new MongoBinaryDownload({ checkMD5: true, downloadDir: '/' }).binaryOpts.checkMD5).toBe(
true
);
expect(new MongoBinaryDownload({ checkMD5: false, downloadDir: '/' }).binaryOpts.checkMD5).toBe(
false
);
});

it('"checkMD5" should be disabled when config option is "false" and if config options is "true" it should be enabled', () => {
process.env[envName(ResolveConfigVariables.MD5_CHECK)] = '0';
expect(new MongoBinaryDownload({ downloadDir: '/' }).checkMD5).toBe(false);
expect(new MongoBinaryDownload({ downloadDir: '/' }).binaryOpts.checkMD5).toBe(false);
process.env[envName(ResolveConfigVariables.MD5_CHECK)] = '1';
expect(new MongoBinaryDownload({ downloadDir: '/' }).checkMD5).toBe(true);
expect(new MongoBinaryDownload({ downloadDir: '/' }).binaryOpts.checkMD5).toBe(true);
});

it('should use direct download', async () => {
Expand Down

0 comments on commit 4bb3420

Please sign in to comment.