From eba9dfff7b489138782403fa1e1d5f54fc26e24a Mon Sep 17 00:00:00 2001 From: Doug Drechsel Date: Tue, 14 May 2024 18:48:20 -0400 Subject: [PATCH] ci: Add test support for external database adapter (#8883) --- spec/AdapterLoader.spec.js | 19 +++++++++++++++++++ spec/helper.js | 6 +++++- spec/support/MockDatabaseAdapter.js | 9 +++++++++ src/cli/utils/runner.js | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 spec/support/MockDatabaseAdapter.js diff --git a/spec/AdapterLoader.spec.js b/spec/AdapterLoader.spec.js index 72c6ef333c..9ec85b6fb7 100644 --- a/spec/AdapterLoader.spec.js +++ b/spec/AdapterLoader.spec.js @@ -142,6 +142,25 @@ describe('AdapterLoader', () => { }).not.toThrow(); }); + it('should load custom database adapter from config', done => { + const adapterPath = require('path').resolve('./spec/support/MockDatabaseAdapter'); + const options = { + databaseURI: 'oracledb://user:password@localhost:1521/freepdb1', + collectionPrefix: '', + }; + const databaseAdapterOptions = { + adapter: adapterPath, + options, + }; + expect(() => { + const databaseAdapter = loadAdapter(databaseAdapterOptions); + expect(databaseAdapter).not.toBe(undefined); + expect(databaseAdapter.options).toEqual(options); + expect(databaseAdapter.getDatabaseURI()).toEqual(options.databaseURI); + }).not.toThrow(); + done(); + }); + it('should load file adapter from direct passing', done => { spyOn(console, 'warn').and.callFake(() => {}); const mockFilesAdapter = new MockFilesAdapter('key', 'secret', 'bucket'); diff --git a/spec/helper.js b/spec/helper.js index 04defa868d..6b9db05cf2 100644 --- a/spec/helper.js +++ b/spec/helper.js @@ -35,6 +35,7 @@ process.noDeprecation = true; const cache = require('../lib/cache').default; const defaults = require('../lib/defaults').default; const ParseServer = require('../lib/index').ParseServer; +const loadAdapter = require('../lib/Adapters/AdapterLoader').loadAdapter; const path = require('path'); const TestUtils = require('../lib/TestUtils'); const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter') @@ -53,7 +54,10 @@ let databaseAdapter; let databaseURI; // need to bind for mocking mocha -if (process.env.PARSE_SERVER_TEST_DB === 'postgres') { +if (process.env.PARSE_SERVER_DATABASE_ADAPTER) { + databaseAdapter = JSON.parse(process.env.PARSE_SERVER_DATABASE_ADAPTER); + databaseAdapter = loadAdapter(databaseAdapter); +} else if (process.env.PARSE_SERVER_TEST_DB === 'postgres') { databaseURI = process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI; databaseAdapter = new PostgresStorageAdapter({ uri: databaseURI, diff --git a/spec/support/MockDatabaseAdapter.js b/spec/support/MockDatabaseAdapter.js new file mode 100644 index 0000000000..136b4a086d --- /dev/null +++ b/spec/support/MockDatabaseAdapter.js @@ -0,0 +1,9 @@ +module.exports = function (options) { + return { + options: options, + send: function () {}, + getDatabaseURI: function () { + return options.databaseURI; + }, + }; +}; diff --git a/src/cli/utils/runner.js b/src/cli/utils/runner.js index 4869111d64..ed66cdfef8 100644 --- a/src/cli/utils/runner.js +++ b/src/cli/utils/runner.js @@ -6,6 +6,7 @@ function logStartupOptions(options) { } // Keys that may include sensitive information that will be redacted in logs const keysToRedact = [ + 'databaseAdapter', 'databaseURI', 'masterKey', 'maintenanceKey',