Skip to content

Commit

Permalink
ci: Add test support for external database adapter (parse-community#8883
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ddrechse authored May 14, 2024
1 parent 2420024 commit eba9dff
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
19 changes: 19 additions & 0 deletions spec/AdapterLoader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 5 additions & 1 deletion spec/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions spec/support/MockDatabaseAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = function (options) {
return {
options: options,
send: function () {},
getDatabaseURI: function () {
return options.databaseURI;
},
};
};
1 change: 1 addition & 0 deletions src/cli/utils/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit eba9dff

Please sign in to comment.