leveldown
Advanced tools
Comparing version 0.2.1 to 0.2.3
@@ -0,1 +1,7 @@ | ||
0.2.2 @ (unreleased) | ||
=================== | ||
* Pull API tests up into AbstractLevelDOWN, require it to run the | ||
tests. AbstractLevelDOWN can now be used to test LevelDOWN-compliant | ||
APIs. (@maxogden) | ||
0.2.1 @ Apr 8 2013 | ||
@@ -52,2 +58,2 @@ ================== | ||
=================== | ||
* extracted from LevelUP as stand-alone package (@rvagg) | ||
* extracted from LevelUP as stand-alone package (@rvagg) |
{ | ||
"name" : "leveldown" | ||
, "description" : "A Node.js LevelDB binding (currently being extracted from LevelUP)" | ||
, "description" : "A Node.js LevelDB binding, primary backend for LevelUP" | ||
, "contributors" : [ | ||
@@ -18,3 +18,3 @@ "Rod Vagg <r@va.gg> (https://github.com/rvagg)" | ||
] | ||
, "version" : "0.2.1" | ||
, "version" : "0.2.3" | ||
, "main" : "index.js" | ||
@@ -25,6 +25,7 @@ , "dependencies" : { | ||
, "devDependencies" : { | ||
"tap" : "*" | ||
, "rimraf" : "*" | ||
, "mkfiletree" : "*" | ||
, "readfiletree" : "*" | ||
"tap" : "~0.4.1" | ||
, "rimraf" : "~2.1.4" | ||
, "mkfiletree" : "~0.0.0" | ||
, "readfiletree" : "~0.0.0" | ||
, "abstract-leveldown" : "~0.4.0" | ||
} | ||
@@ -38,4 +39,7 @@ , "repository" : { | ||
} | ||
, "license" : "MIT" | ||
, "browser": { | ||
"bindings": "./index-shim.js" | ||
}, | ||
"license" : "MIT" | ||
, "gypfile" : true | ||
} |
@@ -229,3 +229,3 @@ LevelDOWN | ||
The callback will be called when the repair operation iscomplete, with a possible `error` argument. | ||
The callback will be called when the repair operation is complete, with a possible `error` argument. | ||
@@ -247,3 +247,12 @@ | ||
<a name="support"></a> | ||
Getting support | ||
--------------- | ||
There are multiple ways you can find help in using LevelDB in Node.js: | ||
* **IRC:** you'll find an active group of LevelUP users in the **##leveldb** channel on Freenode, including most of the contributors to this project. | ||
* **Mailing list:** there is an active [Node.js LevelDB](https://groups.google.com/forum/#!forum/node-levelup) Google Group. | ||
* **GitHub:** you're welcome to open an issue here on this GitHub repository if you have a question. | ||
<a name="contributing"></a> | ||
@@ -273,2 +282,4 @@ Contributing | ||
<tr><th align="left">Paolo Fragomeni</th><td><a href="https://github.com/hij1nx">GitHub/hij1nx</a></td><td><a href="http://twitter.com/hij1nx">Twitter/@hij1nx</a></td></tr> | ||
<tr><th align="left">Anton Whalley</th><td><a href="https://github.com/No9">GitHub/No9</a></td><td><a href="https://twitter.com/antonwhalley">Twitter/@antonwhalley</a></td></tr> | ||
<tr><th align="left">Matteo Collina</th><td><a href="https://github.com/mcollina">GitHub/mcollina</a></td><td><a href="https://twitter.com/matteocollina">Twitter/@matteocollina</a></td></tr> | ||
</tbody></table> | ||
@@ -275,0 +286,0 @@ |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/approximate-size-test') | ||
var db | ||
module.exports.setUp = function (leveldown) { | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
} | ||
module.exports.args = function () { | ||
test('test argument-less approximateSize() throws', function (t) { | ||
t.throws( | ||
db.approximateSize.bind(db) | ||
, { name: 'Error', message: 'approximateSize() requires valid `start`, `end` and `callback` arguments' } | ||
, 'no-arg approximateSize() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 1-arg, approximateSize() throws', function (t) { | ||
t.throws( | ||
db.approximateSize.bind(db, 'foo') | ||
, { name: 'Error', message: 'approximateSize() requires valid `start`, `end` and `callback` arguments' } | ||
, 'callback-less, 1-arg approximateSize() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 2-arg, approximateSize() throws', function (t) { | ||
t.throws( | ||
db.approximateSize.bind(db, 'foo', 'bar') | ||
, { name: 'Error', message: 'approximateSize() requires a callback argument' } | ||
, 'callback-less, 2-arg approximateSize() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 3-arg, approximateSize() throws', function (t) { | ||
t.throws( | ||
db.approximateSize.bind(db, function () {}) | ||
, { name: 'Error', message: 'approximateSize() requires valid `start`, `end` and `callback` arguments' } | ||
, 'callback-only approximateSize() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-only approximateSize() throws', function (t) { | ||
t.throws( | ||
db.approximateSize.bind(db, function () {}) | ||
, { name: 'Error', message: 'approximateSize() requires valid `start`, `end` and `callback` arguments' } | ||
, 'callback-only approximateSize() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test 1-arg + callback approximateSize() throws', function (t) { | ||
t.throws( | ||
db.approximateSize.bind(db, 'foo', function () {}) | ||
, { name: 'Error', message: 'approximateSize() requires valid `start`, `end` and `callback` arguments' } | ||
, '1-arg + callback approximateSize() throws' | ||
) | ||
t.end() | ||
}) | ||
} | ||
module.exports.approximateSize = function () { | ||
test('test approximateSize()', function (t) { | ||
var data = Array.apply(null, Array(10000)).map(function () { | ||
return 'aaaaaaaaaa' | ||
}).join('') | ||
db.batch( | ||
Array.apply(null, Array(10)).map(function (x, i) { | ||
return { type: 'put', key: 'foo' + i, value: data } | ||
}) | ||
, function (err) { | ||
t.notOk(err, 'no error') | ||
// cycle open/close to ensure a pack to .sst | ||
db.close(function (err) { | ||
t.notOk(err, 'no error') | ||
db.open(function (err) { | ||
t.notOk(err, 'no error') | ||
db.approximateSize('!', '~', function (err, size) { | ||
t.notOk(err, 'no error') | ||
t.type(size, 'number') | ||
t.ok( | ||
size > 100000 | ||
, 'size reports a reasonable amount (' + size + ')' | ||
) | ||
db.close(function (err) { | ||
t.notOk(err, 'no error') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
) | ||
}) | ||
} | ||
module.exports.tearDown = function () { | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp(leveldown) | ||
module.exports.args() | ||
module.exports.approximateSize() | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon) |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/batch-test') | ||
var db | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
test('test callback-less, 2-arg, batch() throws', function (t) { | ||
t.throws(db.batch.bind(db, 'foo', {}), 'callback-less, 2-arg batch() throws') | ||
t.end() | ||
}) | ||
test('test batch() with empty array', function (t) { | ||
db.batch([], function (err) { | ||
t.notOk(err, 'no error') | ||
t.end() | ||
}) | ||
}) | ||
test('test simple batch()', function (t) { | ||
db.batch([{ type: 'put', key: 'foo', value: 'bar' }], function (err) { | ||
t.notOk(err, 'no error') | ||
db.get('foo', function (err, value) { | ||
t.notOk(err, 'no error') | ||
t.type(value, Buffer) | ||
t.equal(value.toString(), 'bar') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('test batch() with missing `value`', function (t) { | ||
db.batch([{ type: 'put', key: 'foo1' }], function (err) { | ||
t.like(err.message, /value cannot be `null` or `undefined`/, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
test('test batch() with null `value`', function (t) { | ||
db.batch([{ type: 'put', key: 'foo1', value: null }], function (err) { | ||
t.like(err.message, /value cannot be `null` or `undefined`/, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
test('test batch() with missing `key`', function (t) { | ||
db.batch([{ type: 'put', value: 'foo1' }], function (err) { | ||
t.like(err.message, /key cannot be `null` or `undefined`/, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
test('test batch() with null `key`', function (t) { | ||
db.batch([{ type: 'put', key: null, value: 'foo1' }], function (err) { | ||
t.like(err.message, /key cannot be `null` or `undefined`/, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
test('test batch() with missing `key` and `value`', function (t) { | ||
db.batch([{ type: 'put' }], function (err) { | ||
t.like(err.message, /key cannot be `null` or `undefined`/, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
test('test multiple batch()', function (t) { | ||
db.batch([ | ||
{ type: 'put', key: 'foobatch1', value: 'bar1' } | ||
, { type: 'put', key: 'foobatch2', value: 'bar2' } | ||
, { type: 'put', key: 'foobatch3', value: 'bar3' } | ||
, { type: 'del', key: 'foobatch2' } | ||
], function (err) { | ||
t.notOk(err, 'no error') | ||
var r = 0 | ||
, done = function () { | ||
if (++r == 3) | ||
t.end() | ||
} | ||
db.get('foobatch1', function (err, value) { | ||
t.notOk(err, 'no error') | ||
t.type(value, Buffer) | ||
t.equal(value.toString(), 'bar1') | ||
done() | ||
}) | ||
db.get('foobatch2', function (err, value) { | ||
t.ok(err, 'entry not found') | ||
t.notOk(value, 'value not returned') | ||
t.like(err.message, /NotFound/) | ||
done() | ||
}) | ||
db.get('foobatch3', function (err, value) { | ||
t.notOk(err, 'no error') | ||
t.type(value, Buffer) | ||
t.equal(value.toString(), 'bar3') | ||
done() | ||
}) | ||
}) | ||
}) | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
if (require.main === module) | ||
abstract.all(leveldown, test, testCommon) |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/chained-batch-test') | ||
var db | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
test('basic batch', function (t) { | ||
db.batch( | ||
[ | ||
{ type: 'put', key: 'one', value: '1' } | ||
, { type: 'put', key: 'two', value: '2' } | ||
, { type: 'put', key: 'three', value: '3' } | ||
] | ||
, function (err) { | ||
t.notOk(err, 'no error') | ||
db.batch() | ||
.put('one', 'I') | ||
.put('two', 'II') | ||
.del('three') | ||
.put('foo', 'bar') | ||
.write(function (err) { | ||
t.notOk(err, 'no error') | ||
testCommon.collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 3, 'correct number of entries') | ||
var expected = [ | ||
{ key: 'foo', value: 'bar' } | ||
, { key: 'one', value: 'I' } | ||
, { key: 'two', value: 'II' } | ||
] | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
} | ||
) | ||
}) | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
if (require.main === module) | ||
abstract.all(leveldown, test, testCommon) |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, makeTest = testCommon.makeExistingDbTest | ||
, makeTest = require('./make-test') | ||
@@ -6,0 +6,0 @@ makeTest('test ended iterator', function (db, t, done) { |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/close-test') | ||
@@ -9,27 +10,4 @@ module.exports.setUp = function () { | ||
module.exports.close = function (leveldown) { | ||
test('test close()', function (t) { | ||
var db = leveldown(testCommon.location()) | ||
module.exports.close = abstract.close | ||
db.open(function (err) { | ||
t.notOk(err, 'no error') | ||
t.throws( | ||
db.close.bind(db) | ||
, { name: 'Error', message: 'close() requires a callback argument' } | ||
, 'no-arg close() throws' | ||
) | ||
t.throws( | ||
db.close.bind(db, 'foo') | ||
, { name: 'Error', message: 'close() requires a callback argument' } | ||
, 'non-callback close() throws' | ||
) | ||
db.close(function (err) { | ||
t.notOk(err, 'no error') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports.tearDown = function () { | ||
@@ -41,3 +19,3 @@ test('tearDown', testCommon.tearDown) | ||
module.exports.setUp() | ||
module.exports.close(leveldown) | ||
module.exports.close(leveldown, test, testCommon) | ||
module.exports.tearDown() | ||
@@ -44,0 +22,0 @@ } |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/del-test') | ||
var db | ||
module.exports.setUp = function (leveldown) { | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
} | ||
module.exports.args = function () { | ||
test('test argument-less del() throws', function (t) { | ||
t.throws( | ||
db.del.bind(db) | ||
, { name: 'Error', message: 'del() requires a callback argument' } | ||
, 'no-arg del() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 1-arg, del() throws', function (t) { | ||
t.throws( | ||
db.del.bind(db, 'foo') | ||
, { name: 'Error', message: 'del() requires a callback argument' } | ||
, 'callback-less, 1-arg del() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 3-arg, del() throws', function (t) { | ||
t.throws( | ||
db.del.bind(db, 'foo', {}) | ||
, { name: 'Error', message: 'del() requires a callback argument' } | ||
, 'callback-less, 2-arg del() throws' | ||
) | ||
t.end() | ||
}) | ||
} | ||
module.exports.del = function () { | ||
test('test simple del()', function (t) { | ||
db.put('foo', 'bar', function (err) { | ||
t.notOk(err, 'no error') | ||
db.del('foo', function (err) { | ||
t.notOk(err, 'no error') | ||
db.get('foo', function (err) { | ||
t.ok(err, 'entry propertly deleted') | ||
t.like(err.message, /NotFound/) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports.tearDown = function () { | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp(leveldown) | ||
module.exports.args() | ||
module.exports.del() | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon) |
@@ -6,5 +6,5 @@ const test = require('tap').test | ||
, readfiletree = require('readfiletree') | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, makeTest = testCommon.makeExistingDbTest | ||
, makeTest = require('./make-test') | ||
@@ -11,0 +11,0 @@ test('test argument-less destroy() throws', function (t) { |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/get-test') | ||
var db | ||
module.exports.setUp = function (leveldown) { | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
} | ||
module.exports.args = function () { | ||
test('test argument-less get() throws', function (t) { | ||
t.throws( | ||
db.get.bind(db) | ||
, { name: 'Error', message: 'get() requires a callback argument' } | ||
, 'no-arg get() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 1-arg, get() throws', function (t) { | ||
t.throws( | ||
db.get.bind(db, 'foo') | ||
, { name: 'Error', message: 'get() requires a callback argument' } | ||
, 'callback-less, 1-arg get() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 3-arg, get() throws', function (t) { | ||
t.throws( | ||
db.get.bind(db, 'foo', {}) | ||
, { name: 'Error', message: 'get() requires a callback argument' } | ||
, 'callback-less, 2-arg get() throws' | ||
) | ||
t.end() | ||
}) | ||
} | ||
module.exports.get = function () { | ||
test('test simple get()', function (t) { | ||
db.put('foo', 'bar', function (err) { | ||
t.notOk(err, 'no error') | ||
db.get('foo', function (err, value) { | ||
t.notOk(err, 'no error') | ||
t.type(value, Buffer) | ||
t.equal(value.toString(), 'bar') | ||
db.get('foo', {}, function (err, value) { // same but with {} | ||
t.notOk(err, 'no error') | ||
t.type(value, Buffer) | ||
t.equal(value.toString(), 'bar') | ||
db.get('foo', { asBuffer: false }, function (err, value) { | ||
t.notOk(err, 'no error') | ||
t.type(value, 'string') | ||
t.equal(value, 'bar') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports.tearDown = function () { | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp(leveldown) | ||
module.exports.args() | ||
module.exports.get() | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon) |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, collectEntries = testCommon.collectEntries | ||
, abstract = require('abstract-leveldown/abstract/iterator-test') | ||
var db | ||
, sourceData = (function () { | ||
var d = [] | ||
, i = 0 | ||
, k | ||
for (; i < 100; i++) { | ||
k = (i < 10 ? '0' : '') + i | ||
d.push({ | ||
type : 'put' | ||
, key : k | ||
, value : Math.random() | ||
}) | ||
} | ||
return d | ||
}()) | ||
, transformSource = function (d) { return { key: d.key, value: d.value } } | ||
module.exports.setUp = function (leveldown) { | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
} | ||
module.exports.args = function () { | ||
test('test argument-less iterator#next() throws', function (t) { | ||
var iterator = db.iterator() | ||
t.throws( | ||
iterator.next.bind(iterator) | ||
, { name: 'Error', message: 'next() requires a callback argument' } | ||
, 'no-arg iterator#next() throws' | ||
) | ||
iterator.end(t.end.bind(t)) | ||
}) | ||
test('test argument-less iterator#end() after next() throws', function (t) { | ||
var iterator = db.iterator() | ||
iterator.next(function () { | ||
t.throws( | ||
iterator.end.bind(iterator) | ||
, { name: 'Error', message: 'end() requires a callback argument' } | ||
, 'no-arg iterator#end() throws' | ||
) | ||
iterator.end(t.end.bind(t)) | ||
}) | ||
}) | ||
test('test argument-less iterator#end() throws', function (t) { | ||
var iterator = db.iterator() | ||
t.throws( | ||
iterator.end.bind(iterator) | ||
, { name: 'Error', message: 'end() requires a callback argument' } | ||
, 'no-arg iterator#end() throws' | ||
) | ||
iterator.end(t.end.bind(t)) | ||
}) | ||
} | ||
module.exports.sequence = function () { | ||
test('test twice iterator#end() throws', function (t) { | ||
var iterator = db.iterator() | ||
iterator.end(function (err) { | ||
t.notOk(err, 'no error') | ||
t.throws( | ||
iterator.end.bind(iterator, function () {}) | ||
, { name: 'Error', message: 'end() already called on iterator' } | ||
, 'no-arg iterator#next() throws' | ||
) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator#next after iterator#end() throws', function (t) { | ||
var iterator = db.iterator() | ||
iterator.end(function (err) { | ||
t.notOk(err, 'no error') | ||
t.throws( | ||
iterator.next.bind(iterator, function () {}) | ||
, { name: 'Error', message: 'cannot call next() after end()' } | ||
, 'no-arg iterator#next() after iterator#end() throws' | ||
) | ||
t.end() | ||
}) | ||
}) | ||
test('test twice iterator#next() throws', function (t) { | ||
var iterator = db.iterator() | ||
iterator.next(function (err) { | ||
t.notOk(err, 'no error') | ||
iterator.end(function (err) { | ||
t.notOk(err, 'no error') | ||
t.end() | ||
}) | ||
}) | ||
t.throws( | ||
iterator.next.bind(iterator, function () {}) | ||
, { name: 'Error', message: 'cannot call next() before previous next() has completed' } | ||
, 'no-arg iterator#next() throws' | ||
) | ||
}) | ||
} | ||
module.exports.iterator = function (leveldown) { | ||
test('test simple iterator()', function (t) { | ||
var data = [ | ||
{ type: 'put', key: 'foobatch1', value: 'bar1' } | ||
, { type: 'put', key: 'foobatch2', value: 'bar2' } | ||
, { type: 'put', key: 'foobatch3', value: 'bar3' } | ||
] | ||
, idx = 0 | ||
db.batch(data, function (err) { | ||
t.notOk(err, 'no error') | ||
var iterator = db.iterator() | ||
, fn = function (err, key, value) { | ||
t.notOk(err, 'no error') | ||
if (key && value) { | ||
t.equal(key.toString(), data[idx].key, 'correct key') | ||
t.equal(value.toString(), data[idx].value, 'correct value') | ||
process.nextTick(next) | ||
idx++ | ||
} else { // end | ||
t.type(err, 'undefined', 'err argument is undefined') | ||
t.type(key, 'undefined', 'key argument is undefined') | ||
t.type(value, 'undefined', 'value argument is undefined') | ||
t.equal(idx, data.length, 'correct number of entries') | ||
iterator.end(function () { | ||
t.end() | ||
}) | ||
} | ||
} | ||
, next = function () { | ||
iterator.next(fn) | ||
} | ||
next() | ||
}) | ||
}) | ||
/** the following tests are mirroring the same series of tests in | ||
* LevelUP read-stream-test.js | ||
*/ | ||
test('setUp #2', function (t) { | ||
db.close(function () { | ||
db = leveldown(testCommon.location()) | ||
db.open(function () { | ||
db.batch(sourceData, t.end.bind(t)) | ||
}) | ||
}) | ||
}) | ||
test('test full data collection', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, sourceData.length, 'correct number of entries') | ||
var expected = sourceData.map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, sourceData.length, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start=0', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '00' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, sourceData.length, 'correct number of entries') | ||
var expected = sourceData.map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start=50', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '50' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 50, 'correct number of entries') | ||
var expected = sourceData.slice(50).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start=50 and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '50', reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 51, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().slice(49).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start being a midway key (49.5)', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '49.5' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 50, 'correct number of entries') | ||
var expected = sourceData.slice(50).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start being a midway key (49999)', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '49999' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 50, 'correct number of entries') | ||
var expected = sourceData.slice(50).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start being a midway key and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '49.5', reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 50, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().slice(50).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with end=50', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 51, 'correct number of entries') | ||
var expected = sourceData.slice(0, 51).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with end being a midway key (50.5)', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50.5' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 51, 'correct number of entries') | ||
var expected = sourceData.slice(0, 51).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with end being a midway key (50555)', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50555' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 51, 'correct number of entries') | ||
var expected = sourceData.slice(0, 51).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with end being a midway key and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50.5', reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 49, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().slice(0, 49).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
// end='0', starting key is actually '00' so it should avoid it | ||
test('test iterator with end=0', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '0' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 0, 'correct number of entries') | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start=30 and end=70', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '30', end: '70' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 41, 'correct number of entries') | ||
var expected = sourceData.slice(30, 71).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start=30 and end=70 and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '70', end: '30', reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 41, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().slice(29, 70).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with limit=20', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20 }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 20, 'correct number of entries') | ||
var expected = sourceData.slice(0, 20).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with limit=20 and start=20', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '20', limit: 20 }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 20, 'correct number of entries') | ||
var expected = sourceData.slice(20, 40).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with limit=20 and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20, reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 20, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().slice(0, 20).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with limit=20 and start=20 and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '79', limit: 20, reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 20, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().slice(20, 40).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with end after limit', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20, end: '50' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 20, 'correct number of entries') | ||
var expected = sourceData.slice(0, 20).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with end before limit', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 50, end: '19' }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 20, 'correct number of entries') | ||
var expected = sourceData.slice(0, 20).map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start after database end and reverse=true', function (t) { | ||
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '9a', reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, sourceData.length, 'correct number of entries') | ||
var expected = sourceData.slice().reverse().map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
test('test iterator with start and end after database and and reverse=true', function (t) { | ||
collectEntries(db.iterator({ start: '9b', end: '9a', reverse: true }), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 0, 'correct number of entries') | ||
t.end() | ||
}) | ||
}) | ||
function testIteratorCollectsFullDatabase (name, iteratorOptions) { | ||
iteratorOptions.keyAsBuffer = false | ||
iteratorOptions.valueAsBuffer = false | ||
test(name, function (t) { | ||
collectEntries(db.iterator(iteratorOptions), function (err, data) { | ||
t.notOk(err, 'no error') | ||
t.equal(data.length, 100, 'correct number of entries') | ||
var expected = sourceData.map(transformSource) | ||
t.deepEqual(data, expected) | ||
t.end() | ||
}) | ||
}) | ||
} | ||
testIteratorCollectsFullDatabase( | ||
'test iterator with start as empty buffer' | ||
, { start: new Buffer(0) } | ||
) | ||
testIteratorCollectsFullDatabase( | ||
'test iterator with start as empty string' | ||
, { start: '' } | ||
) | ||
testIteratorCollectsFullDatabase( | ||
'test iterator with start as null' | ||
, { start: null } | ||
) | ||
testIteratorCollectsFullDatabase( | ||
'test iterator with end as empty buffer' | ||
, { end: new Buffer(0) } | ||
) | ||
testIteratorCollectsFullDatabase( | ||
'test iterator with end as empty string' | ||
, { end: '' } | ||
) | ||
testIteratorCollectsFullDatabase( | ||
'test iterator with end as null' | ||
, { end: null } | ||
) | ||
} | ||
module.exports.tearDown = function () { | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp(leveldown) | ||
module.exports.args() | ||
module.exports.sequence() | ||
module.exports.iterator(leveldown) | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon) |
const test = require('tap').test | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/leveldown-test') | ||
module.exports.args = function (leveldown) { | ||
test('test database creation no-arg throws', function (t) { | ||
t.throws( | ||
leveldown | ||
, { name: 'Error', message: 'leveldown() requires at least a location argument' } | ||
, 'no-arg leveldown() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test database open no-arg throws', function (t) { | ||
var db = leveldown('foo') | ||
t.ok(db, 'database object returned') | ||
t.isa(db.open, 'function', 'open() function exists') | ||
t.end() | ||
}) | ||
} | ||
if (require.main === module) | ||
module.exports.args(leveldown) | ||
abstract.args(leveldown, test) |
@@ -1,89 +0,7 @@ | ||
const fs = require('fs') | ||
, test = require('tap').test | ||
, testCommon = require('./common') | ||
const test = require('tap').test | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/open-test') | ||
module.exports.setUp = function () { | ||
test('setUp', testCommon.setUp) | ||
} | ||
module.exports.args = function (leveldown) { | ||
test('test database open no-arg throws', function (t) { | ||
var db = leveldown(testCommon.location()) | ||
t.throws( | ||
db.open.bind(db) | ||
, { name: 'Error', message: 'open() requires a callback argument' } | ||
, 'no-arg open() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 1-arg, open() throws', function (t) { | ||
var db = leveldown(testCommon.location()) | ||
t.throws( | ||
db.open.bind(db, {}) | ||
, { name: 'Error', message: 'open() requires a callback argument' } | ||
, 'callback-less, 1-arg open() throws' | ||
) | ||
t.end() | ||
}) | ||
} | ||
module.exports.open = function (leveldown) { | ||
test('test database open', function (t) { | ||
var db = leveldown(testCommon.location()) | ||
// default createIfMissing=true, errorIfExists=false | ||
db.open(function (err) { | ||
t.notOk(err, 'no error') | ||
db.close(function () { | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
test('test database open createIfMissing:false', function (t) { | ||
var db = leveldown(testCommon.location()) | ||
db.open({ createIfMissing: false }, function (err) { | ||
t.ok(err, 'error') | ||
t.ok(/does not exist/.test(err.message), 'error is about dir not existing') | ||
t.end() | ||
}) | ||
}) | ||
test('test database open errorIfExists:true', function (t) { | ||
var location = testCommon.location() | ||
, db = leveldown(location) | ||
// make a valid database first, then close and dispose | ||
db.open(function (err) { | ||
t.notOk(err, 'no error') | ||
db.close(function (err) { | ||
t.notOk(err, 'no error') | ||
// open again with 'errorIfExists' | ||
db = leveldown(location) | ||
db.open({ createIfMissing: false, errorIfExists: true }, function (err) { | ||
t.ok(err, 'error') | ||
t.ok(/exists/.test(err.message), 'error is about already existing') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports.tearDown = function () { | ||
test('tearDown', testCommon.tearDown) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp() | ||
module.exports.args(leveldown) | ||
module.exports.open(leveldown) | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon) |
@@ -1,159 +0,10 @@ | ||
const fs = require('fs') | ||
const test = require('tap').test | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, fs = require('fs') | ||
, path = require('path') | ||
, test = require('tap').test | ||
, testCommon = require('./common') | ||
, leveldown = require('../') | ||
, testBuffer = fs.readFileSync(path.join(__dirname, 'data/testdata.bin')) | ||
, abstract = require('abstract-leveldown/abstract/put-get-del-test') | ||
/**** SETUP & UTILITY STUFF ****/ | ||
var db | ||
, makeGetDelErrorTests = function (type, key, expectedError) { | ||
test('test get() with ' + type + ' causes error', function (t) { | ||
db.get(key, function (err) { | ||
t.ok(err, 'has error') | ||
t.type(err, Error) | ||
t.like(err.message, expectedError, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
test('test del() with ' + type + ' causes error', function (t) { | ||
db.del(key, function (err) { | ||
t.ok(err, 'has error') | ||
t.type(err, Error) | ||
t.like(err.message, expectedError, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
} | ||
, makePutErrorTest = function (type, key, value, expectedError) { | ||
test('test put() with ' + type + ' causes error', function (t) { | ||
db.put(key, value, function (err) { | ||
t.ok(err, 'has error') | ||
t.type(err, Error) | ||
t.like(err.message, expectedError, 'correct error message') | ||
t.end() | ||
}) | ||
}) | ||
} | ||
, makePutGetDelSuccessfulTest = function (type, key, value) { | ||
test('test put()/get()/del() with ' + type, function (t) { | ||
db.put(key, value, function (err) { | ||
t.notOk(err, 'no error') | ||
db.get(key, function (err, _value) { | ||
t.notOk(err, 'no error, has key/value for `' + key + '`') | ||
t.equals(_value.toString(), value.toString()) | ||
db.del(key, function (err) { | ||
t.notOk(err, 'no error, deleted key/value for `' + key + '`') | ||
db.get(key, function (err) { | ||
t.ok(err, 'entry propertly deleted') | ||
t.like(err.message, /NotFound/) | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} | ||
, makeErrorKeyTest = function (type, key, expectedError) { | ||
makeGetDelErrorTests(type, key, expectedError) | ||
makePutErrorTest(type, key, 'foo', expectedError) | ||
} | ||
/**** SETUP ENVIRONMENT ****/ | ||
module.exports.setUp = function (leveldown) { | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
} | ||
/**** TEST ERROR KEYS ****/ | ||
module.exports.errorKeys = function () { | ||
makeErrorKeyTest('null key', null, /key cannot be `null` or `undefined`/) | ||
makeErrorKeyTest('undefined key', undefined, /key cannot be `null` or `undefined`/) | ||
makeErrorKeyTest('empty String key', '', /key cannot be an empty String/) | ||
makeErrorKeyTest('empty Buffer key', new Buffer(0), /key cannot be an empty Buffer/) | ||
makeErrorKeyTest('empty Array key', [], /key cannot be an empty String/) | ||
} | ||
/**** TEST NON-ERROR KEYS ****/ | ||
module.exports.nonErrorKeys = function () { | ||
// valid falsey keys | ||
makePutGetDelSuccessfulTest('`false` key', false, 'foo false') | ||
makePutGetDelSuccessfulTest('`0` key', 0, 'foo 0') | ||
makePutGetDelSuccessfulTest('`NaN` key', NaN, 'foo NaN') | ||
// standard String key | ||
makePutGetDelSuccessfulTest( | ||
'long String key' | ||
, 'some long string that I\'m using as a key for this unit test, cross your fingers dude, we\'re going in!' | ||
, 'foo' | ||
) | ||
// Buffer key | ||
makePutGetDelSuccessfulTest('Buffer key', testBuffer, 'foo') | ||
// non-empty Array as a key | ||
makePutGetDelSuccessfulTest('Array value', 'foo', [1,2,3,4]) | ||
} | ||
/**** TEST ERROR VALUES ****/ | ||
module.exports.errorValues = function () { | ||
makePutErrorTest('null value', 'foo', null, /value cannot be `null` or `undefined`/) | ||
makePutErrorTest('undefined value', 'foo', undefined, /value cannot be `null` or `undefined`/) | ||
makePutErrorTest('empty String value', 'foo', '', /value cannot be an empty String/) | ||
makePutErrorTest('empty Buffer value', 'foo', new Buffer(0), /value cannot be an empty Buffer/) | ||
makePutErrorTest('empty Array value', 'foo', [], /value cannot be an empty String/) | ||
} | ||
module.exports.nonErrorKeys = function () { | ||
// valid falsey values | ||
makePutGetDelSuccessfulTest('`false` value', 'foo false', false) | ||
makePutGetDelSuccessfulTest('`0` value', 'foo 0', 0) | ||
makePutGetDelSuccessfulTest('`NaN` value', 'foo NaN', NaN) | ||
// standard String value | ||
makePutGetDelSuccessfulTest( | ||
'long String value' | ||
, 'foo' | ||
, 'some long string that I\'m using as a key for this unit test, cross your fingers dude, we\'re going in!' | ||
) | ||
// standard Buffer value | ||
makePutGetDelSuccessfulTest('Buffer key', 'foo', testBuffer) | ||
// non-empty Array as a value | ||
makePutGetDelSuccessfulTest('Array value', [1,2,3,4], 'foo') | ||
} | ||
/**** CLEANUP ENVIRONMENT ****/ | ||
module.exports.tearDown = function () { | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp(leveldown) | ||
module.exports.errorKeys() | ||
module.exports.nonErrorKeys() | ||
module.exports.errorValues() | ||
module.exports.nonErrorKeys() | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon, testBuffer) |
const test = require('tap').test | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, abstract = require('abstract-leveldown/abstract/put-test') | ||
var db | ||
module.exports.setUp = function (leveldown) { | ||
test('setUp common', testCommon.setUp) | ||
test('setUp db', function (t) { | ||
db = leveldown(testCommon.location()) | ||
db.open(t.end.bind(t)) | ||
}) | ||
} | ||
module.exports.args = function () { | ||
test('test argument-less put() throws', function (t) { | ||
t.throws( | ||
db.put.bind(db) | ||
, { name: 'Error', message: 'put() requires a callback argument' } | ||
, 'no-arg put() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 1-arg, put() throws', function (t) { | ||
t.throws( | ||
db.put.bind(db, 'foo') | ||
, { name: 'Error', message: 'put() requires a callback argument' } | ||
, 'callback-less, 1-arg put() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 2-arg, put() throws', function (t) { | ||
t.throws( | ||
db.put.bind(db, 'foo', 'bar') | ||
, { name: 'Error', message: 'put() requires a callback argument' } | ||
, 'callback-less, 2-arg put() throws' | ||
) | ||
t.end() | ||
}) | ||
test('test callback-less, 3-arg, put() throws', function (t) { | ||
t.throws( | ||
db.put.bind(db, 'foo', 'bar', {}) | ||
, { name: 'Error', message: 'put() requires a callback argument' } | ||
, 'callback-less, 3-arg put() throws' | ||
) | ||
t.end() | ||
}) | ||
} | ||
module.exports.put = function () { | ||
test('test simple put()', function (t) { | ||
db.put('foo', 'bar', function (err) { | ||
t.notOk(err, 'no error') | ||
db.get('foo', function (err, value) { | ||
t.notOk(err, 'no error') | ||
t.equal(value.toString(), 'bar') | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
} | ||
module.exports.tearDown = function () { | ||
test('tearDown', function (t) { | ||
db.close(testCommon.tearDown.bind(null, t)) | ||
}) | ||
} | ||
module.exports.all = function (leveldown) { | ||
module.exports.setUp(leveldown) | ||
module.exports.args() | ||
module.exports.put() | ||
module.exports.tearDown() | ||
} | ||
if (require.main === module) | ||
module.exports.all(leveldown) | ||
abstract.all(leveldown, test, testCommon) |
@@ -6,5 +6,5 @@ const test = require('tap').test | ||
, readfiletree = require('readfiletree') | ||
, testCommon = require('./common') | ||
, testCommon = require('abstract-leveldown/testCommon') | ||
, leveldown = require('../') | ||
, makeTest = testCommon.makeExistingDbTest | ||
, makeTest = require('./make-test') | ||
@@ -11,0 +11,0 @@ test('test argument-less repair() throws', function (t) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
297
7290577
5
449
6
3