Skip to content

Commit c0975c3

Browse files
committed
fix(DryMongoBinary::getPath): always absoluteize System_Binary path
after the logs so that it is obvious what was provided
1 parent 53d00e4 commit c0975c3

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class DryMongoBinary {
8787
if (!!useOpts.systemBinary) {
8888
log(`locateBinary: env "SYSTEM_BINARY" was provided with value: "${useOpts.systemBinary}"`);
8989

90-
const systemReturn = await this.getSystemPath(useOpts.systemBinary);
90+
const systemReturn = await this.getSystemPath(path.resolve(useOpts.systemBinary));
9191

9292
if (isNullOrUndefined(systemReturn)) {
9393
throw new BinaryNotFoundError(useOpts.systemBinary, ' (systemBinary)');

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,18 @@ describe('DryBinary', () => {
499499
expect(fspromises.access).toHaveBeenCalled();
500500
});
501501

502+
it('should return SystemBinary with absolute path', async () => {
503+
const mockBinary = 'bin/mongod';
504+
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary;
505+
jest.spyOn(fspromises, 'access').mockResolvedValue(void 0);
506+
507+
const returnValue = await binary.DryMongoBinary.locateBinary({ version: '1.1.1' });
508+
expect(returnValue).not.toEqual(mockBinary);
509+
expect(returnValue).toEqual(path.resolve(mockBinary));
510+
expect(binary.DryMongoBinary.binaryCache.size).toBe(0); // system binaries dont get added to the cache
511+
expect(fspromises.access).toHaveBeenCalled();
512+
});
513+
502514
it('should throw an error if SystemBinary was provided, but not found', async () => {
503515
const mockBinary = '/usr/local/bin/mongod';
504516
process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary;

0 commit comments

Comments
 (0)