@@ -4,27 +4,24 @@ import os from 'os';
44import path from 'path' ;
55import fs from 'fs' ;
66import nodeCrypto from 'crypto' ;
7- import nodeUtil from 'util' ;
8- import lexi from 'lexicographic-integer' ;
97import Logger , { LogLevel , StreamHandler } from '@matrixai/logger' ;
108import { WorkerManager } from '@matrixai/workers' ;
119import { withF } from '@matrixai/resources' ;
1210import { spawn , Worker } from 'threads' ;
1311import DB from '@/DB' ;
14- import rocksdbP from '@/rocksdb/rocksdbP' ;
1512import * as errors from '@/errors' ;
1613import * as utils from '@/utils' ;
17- import * as testUtils from './utils' ;
14+ import * as testsUtils from './utils' ;
1815
1916describe ( DB . name , ( ) => {
2017 const logger = new Logger ( `${ DB . name } Test` , LogLevel . WARN , [
2118 new StreamHandler ( ) ,
2219 ] ) ;
2320 const crypto = {
24- key : testUtils . generateKeySync ( 256 ) ,
21+ key : testsUtils . generateKeySync ( 256 ) ,
2522 ops : {
26- encrypt : testUtils . encrypt ,
27- decrypt : testUtils . decrypt ,
23+ encrypt : testsUtils . encrypt ,
24+ decrypt : testsUtils . decrypt ,
2825 } ,
2926 } ;
3027 let dataDir : string ;
@@ -88,7 +85,7 @@ describe(DB.name, () => {
8885 await db . stop ( ) ;
8986 const crypto_ = {
9087 ...crypto ,
91- key : testUtils . generateKeySync ( 256 ) ,
88+ key : testsUtils . generateKeySync ( 256 ) ,
9289 } ;
9390 await expect (
9491 DB . createDB ( { dbPath, crypto : crypto_ , logger } ) ,
@@ -134,8 +131,8 @@ describe(DB.name, () => {
134131 const dbPath = `${ dataDir } /db` ;
135132 const db = await DB . createDB ( { dbPath, crypto, logger } ) ;
136133 const keyPaths : Array < KeyPath > = Array . from ( { length : 1000 } , ( ) =>
137- Array . from ( { length : testUtils . getRandomInt ( 0 , 11 ) } , ( ) =>
138- nodeCrypto . randomBytes ( testUtils . getRandomInt ( 0 , 11 ) ) ,
134+ Array . from ( { length : testsUtils . getRandomInt ( 0 , 11 ) } , ( ) =>
135+ nodeCrypto . randomBytes ( testsUtils . getRandomInt ( 0 , 11 ) ) ,
139136 ) ,
140137 ) ;
141138 for ( const kP of keyPaths ) {
@@ -193,24 +190,24 @@ describe(DB.name, () => {
193190 ] ) ;
194191 await db . stop ( ) ;
195192 } ) ;
196- // Test ('keys that are empty arrays are converted to empty string', async () => {
197- // const dbPath = `${dataDir}/db`;
198- // const db = await DB.createDB({ dbPath, crypto, logger });
199- // await db.put([], 'value');
200- // expect(await db.get([])).toBe('value');
201- // await db.del([]);
202- // expect(await db.get([])).toBeUndefined();
203- // await withF([db.transaction()], async ([tran]) => {
204- // await tran.put([], 'value');
205- // expect(await tran.get([])).toBe('value');
206- // await tran.del([]);
207- // });
208- // await withF([db.transaction()], async ([tran]) => {
209- // await tran.put([], 'value');
210- // });
211- // expect(await db.get([])).toBe('value');
212- // await db.stop();
213- // });
193+ test ( 'keys that are empty arrays are converted to empty string' , async ( ) => {
194+ const dbPath = `${ dataDir } /db` ;
195+ const db = await DB . createDB ( { dbPath, crypto, logger } ) ;
196+ await db . put ( [ ] , 'value' ) ;
197+ expect ( await db . get ( [ ] ) ) . toBe ( 'value' ) ;
198+ await db . del ( [ ] ) ;
199+ expect ( await db . get ( [ ] ) ) . toBeUndefined ( ) ;
200+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
201+ await tran . put ( [ ] , 'value' ) ;
202+ expect ( await tran . get ( [ ] ) ) . toBe ( 'value' ) ;
203+ await tran . del ( [ ] ) ;
204+ } ) ;
205+ await withF ( [ db . transaction ( ) ] , async ( [ tran ] ) => {
206+ await tran . put ( [ ] , 'value' ) ;
207+ } ) ;
208+ expect ( await db . get ( [ ] ) ) . toBe ( 'value' ) ;
209+ await db . stop ( ) ;
210+ } ) ;
214211 test ( 'keys can contain separator buffer' , async ( ) => {
215212 const dbPath = `${ dataDir } /db` ;
216213 const db = await DB . createDB ( { dbPath, crypto, logger } ) ;
0 commit comments