autolevel.js

Automatically use the right abstract-leveldown module for your configuration
git clone git://git.finwo.net/lib/autolevel.js
Log | Files | Refs | README | LICENSE

index.test.js (1997B)


      1 const test = require('tape');
      2 const isBuffer = require('is-buffer');
      3 
      4 const rimraf = require('rimraf');
      5 const absolutePath = require('./to-absolute-path');
      6 
      7 // Setup environment
      8 if ('object' !== typeof process) process = {};
      9 if (!process.env) process.env = {};
     10 process.env.TEST = true;
     11 const noop = ()=>{};
     12 
     13 // Load our module
     14 const autolevel = require('./index');
     15 
     16 //// // Initialize references
     17 //// let kv,
     18 ////     opts     = {asBuffer: false},
     19 ////     testData = [
     20 ////       JSON.stringify({foo: 'bar'}),
     21 ////       JSON.stringify({hello: {subject: 'world'}}),
     22 ////       JSON.stringify({type:'BBQ Meat Lovers', size:25}),
     23 ////       JSON.stringify({type:'BBQ Meat Lovers', size:30})
     24 ////     ],
     25 ////     testId = new Map();
     26 ////
     27 //// beforeAll(async () => {
     28 ////   kv = await (require('./kv')('mem://'));
     29 //// });
     30 
     31 test('Ensure autolevel loads', async t => {
     32   t.plan(2);
     33 
     34   t.equal(typeof autolevel  , 'function', 'Exported module should be a function');
     35   t.equal(typeof autolevel(), 'object'  , 'Running exported function returns an object');
     36 });
     37 
     38 test('Verify memory adapter', async t => {
     39   t.plan(3);
     40 
     41   const instance = autolevel('mem://');
     42   t.equal(await instance.put('key', 'value') , undefined, 'put returns nothing');
     43   t.equal(isBuffer(await instance.get('key')), true     , 'get returns a buffer');
     44   t.equal(await instance.get('key', {asBuffer:false})   , 'value'  , 'get returns original value');
     45 });
     46 
     47 test('Verify plain adapter', async t => {
     48   t.plan(4);
     49 
     50   const instance = autolevel('dir:data/');
     51   t.equal(await instance.put('key', 'value') , undefined, 'put returns nothing');
     52   t.equal(isBuffer(await instance.get('key')), true     , 'get returns a buffer');
     53   t.equal(await instance.get('key', {asBuffer:false})   , 'value'  , 'get returns original value');
     54   t.equal(await instance.close(), undefined, 'close returns undefined');
     55   rimraf(absolutePath('dir://data'), noop);
     56 });
     57 
     58 ///* TODO:
     59 // *   mssql
     60 // *   mysql
     61 // *   mysql2
     62 // *   mongodb
     63 // *   sqlite
     64 // */