From c0975c32a273c452c7e4353096f48e1addec8460 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Mon, 9 Dec 2024 16:32:28 +0100 Subject: [PATCH] fix(DryMongoBinary::getPath): always absoluteize System_Binary path after the logs so that it is obvious what was provided --- .../src/util/DryMongoBinary.ts | 2 +- .../src/util/__tests__/dryBinary.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts b/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts index e773d4428..564ba5efd 100644 --- a/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts +++ b/packages/mongodb-memory-server-core/src/util/DryMongoBinary.ts @@ -87,7 +87,7 @@ export class DryMongoBinary { if (!!useOpts.systemBinary) { log(`locateBinary: env "SYSTEM_BINARY" was provided with value: "${useOpts.systemBinary}"`); - const systemReturn = await this.getSystemPath(useOpts.systemBinary); + const systemReturn = await this.getSystemPath(path.resolve(useOpts.systemBinary)); if (isNullOrUndefined(systemReturn)) { throw new BinaryNotFoundError(useOpts.systemBinary, ' (systemBinary)'); diff --git a/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts b/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts index 67ba58323..ba2517fa3 100644 --- a/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts +++ b/packages/mongodb-memory-server-core/src/util/__tests__/dryBinary.test.ts @@ -499,6 +499,18 @@ describe('DryBinary', () => { expect(fspromises.access).toHaveBeenCalled(); }); + it('should return SystemBinary with absolute path', async () => { + const mockBinary = 'bin/mongod'; + process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary; + jest.spyOn(fspromises, 'access').mockResolvedValue(void 0); + + const returnValue = await binary.DryMongoBinary.locateBinary({ version: '1.1.1' }); + expect(returnValue).not.toEqual(mockBinary); + expect(returnValue).toEqual(path.resolve(mockBinary)); + expect(binary.DryMongoBinary.binaryCache.size).toBe(0); // system binaries dont get added to the cache + expect(fspromises.access).toHaveBeenCalled(); + }); + it('should throw an error if SystemBinary was provided, but not found', async () => { const mockBinary = '/usr/local/bin/mongod'; process.env[envName(ResolveConfigVariables.SYSTEM_BINARY)] = mockBinary;