Skip to content

Commit eba9dff

Browse files
authored
ci: Add test support for external database adapter (#8883)
1 parent 2420024 commit eba9dff

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

Diff for: spec/AdapterLoader.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ describe('AdapterLoader', () => {
142142
}).not.toThrow();
143143
});
144144

145+
it('should load custom database adapter from config', done => {
146+
const adapterPath = require('path').resolve('./spec/support/MockDatabaseAdapter');
147+
const options = {
148+
databaseURI: 'oracledb://user:password@localhost:1521/freepdb1',
149+
collectionPrefix: '',
150+
};
151+
const databaseAdapterOptions = {
152+
adapter: adapterPath,
153+
options,
154+
};
155+
expect(() => {
156+
const databaseAdapter = loadAdapter(databaseAdapterOptions);
157+
expect(databaseAdapter).not.toBe(undefined);
158+
expect(databaseAdapter.options).toEqual(options);
159+
expect(databaseAdapter.getDatabaseURI()).toEqual(options.databaseURI);
160+
}).not.toThrow();
161+
done();
162+
});
163+
145164
it('should load file adapter from direct passing', done => {
146165
spyOn(console, 'warn').and.callFake(() => {});
147166
const mockFilesAdapter = new MockFilesAdapter('key', 'secret', 'bucket');

Diff for: spec/helper.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ process.noDeprecation = true;
3535
const cache = require('../lib/cache').default;
3636
const defaults = require('../lib/defaults').default;
3737
const ParseServer = require('../lib/index').ParseServer;
38+
const loadAdapter = require('../lib/Adapters/AdapterLoader').loadAdapter;
3839
const path = require('path');
3940
const TestUtils = require('../lib/TestUtils');
4041
const GridFSBucketAdapter = require('../lib/Adapters/Files/GridFSBucketAdapter')
@@ -53,7 +54,10 @@ let databaseAdapter;
5354
let databaseURI;
5455
// need to bind for mocking mocha
5556

56-
if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
57+
if (process.env.PARSE_SERVER_DATABASE_ADAPTER) {
58+
databaseAdapter = JSON.parse(process.env.PARSE_SERVER_DATABASE_ADAPTER);
59+
databaseAdapter = loadAdapter(databaseAdapter);
60+
} else if (process.env.PARSE_SERVER_TEST_DB === 'postgres') {
5761
databaseURI = process.env.PARSE_SERVER_TEST_DATABASE_URI || postgresURI;
5862
databaseAdapter = new PostgresStorageAdapter({
5963
uri: databaseURI,

Diff for: spec/support/MockDatabaseAdapter.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module.exports = function (options) {
2+
return {
3+
options: options,
4+
send: function () {},
5+
getDatabaseURI: function () {
6+
return options.databaseURI;
7+
},
8+
};
9+
};

Diff for: src/cli/utils/runner.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function logStartupOptions(options) {
66
}
77
// Keys that may include sensitive information that will be redacted in logs
88
const keysToRedact = [
9+
'databaseAdapter',
910
'databaseURI',
1011
'masterKey',
1112
'maintenanceKey',

0 commit comments

Comments
 (0)