File tree Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Expand file tree Collapse file tree 4 files changed +34
-1
lines changed Original file line number Diff line number Diff 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' ) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ process.noDeprecation = true;
3535const cache = require ( '../lib/cache' ) . default ;
3636const defaults = require ( '../lib/defaults' ) . default ;
3737const ParseServer = require ( '../lib/index' ) . ParseServer ;
38+ const loadAdapter = require ( '../lib/Adapters/AdapterLoader' ) . loadAdapter ;
3839const path = require ( 'path' ) ;
3940const TestUtils = require ( '../lib/TestUtils' ) ;
4041const GridFSBucketAdapter = require ( '../lib/Adapters/Files/GridFSBucketAdapter' )
@@ -53,7 +54,10 @@ let databaseAdapter;
5354let 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 ,
Original file line number Diff line number Diff line change 1+ module . exports = function ( options ) {
2+ return {
3+ options : options ,
4+ send : function ( ) { } ,
5+ getDatabaseURI : function ( ) {
6+ return options . databaseURI ;
7+ } ,
8+ } ;
9+ } ;
Original file line number Diff line number Diff 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' ,
You can’t perform that action at this time.
0 commit comments