|
| 1 | +require('../../testUtils'); |
| 2 | +const assert = require('assert'); |
| 3 | +const { OpenDBIObject } = require('#src/utility/lmdb/OpenDBIObject'); |
| 4 | +const envMngr = require('#src/utility/environment/environmentManager'); |
| 5 | +const { CONFIG_PARAMS } = require('#src/utility/hdbTerms'); |
| 6 | + |
| 7 | +// Covers the global storage.randomAccessFields path in the OpenDBIObject constructor. The directive |
| 8 | +// tests (databases.test.js / randomAccessFieldsDirective.test.js) stamp dbiInit.randomAccessStructure |
| 9 | +// in databases.ts before the store opens, bypassing this constructor branch — so a wrong config key, |
| 10 | +// a non-boolean value, or a hdbTerms/YAML name mismatch would go uncaught. These open a DBI WITHOUT a |
| 11 | +// directive and assert the constructor reads the global config correctly. |
| 12 | +describe('OpenDBIObject storage.randomAccessFields global config', () => { |
| 13 | + let previous; |
| 14 | + beforeEach(() => { |
| 15 | + previous = envMngr.get(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS); |
| 16 | + }); |
| 17 | + afterEach(() => { |
| 18 | + envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, previous); |
| 19 | + }); |
| 20 | + |
| 21 | + it('enables randomAccessStructure on a primary DBI when the global config is true', () => { |
| 22 | + envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, true); |
| 23 | + assert.strictEqual(new OpenDBIObject(false, true).randomAccessStructure, true); |
| 24 | + }); |
| 25 | + |
| 26 | + it('leaves randomAccessStructure off on a primary DBI when the global config is false (default)', () => { |
| 27 | + envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, false); |
| 28 | + assert.strictEqual(new OpenDBIObject(false, true).randomAccessStructure, false); |
| 29 | + }); |
| 30 | + |
| 31 | + it('keeps randomAccessStructure off on non-primary DBIs even when the global config is true', () => { |
| 32 | + // Non-primary stores (e.g. the __dbis__ metadata DBI) must stay in records mode for v4-downgrade |
| 33 | + // decodability, regardless of the global setting. |
| 34 | + envMngr.setProperty(CONFIG_PARAMS.STORAGE_RANDOMACCESSFIELDS, true); |
| 35 | + assert.strictEqual(new OpenDBIObject(false, false).randomAccessStructure, false); |
| 36 | + }); |
| 37 | +}); |
0 commit comments