[Pkg-javascript-commits] [node-leveldown] 287/492: added repair() test

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:09 UTC 2014


This is an automated email from the git hooks/post-receive script.

andrewrk-guest pushed a commit to annotated tag rocksdb-0.10.1
in repository node-leveldown.

commit 656ddcdad4c156dfb4c32444829a216f547fdfe6
Author: Rod Vagg <rod at vagg.org>
Date:   Sat Mar 30 05:26:25 2013 +1100

    added repair() test
---
 test/common.js      |  2 +-
 test/repair-test.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/test/common.js b/test/common.js
index ead3ba0..de8d7ba 100644
--- a/test/common.js
+++ b/test/common.js
@@ -28,7 +28,7 @@ var dbidx = 0
         var ret = 0
 
         list.forEach(function (f) {
-          rimraf(f, function () {
+          rimraf(path.join(__dirname, f), function (err) {
             if (++ret == list.length)
               callback()
           })
diff --git a/test/repair-test.js b/test/repair-test.js
new file mode 100644
index 0000000..d850983
--- /dev/null
+++ b/test/repair-test.js
@@ -0,0 +1,49 @@
+const test         = require('tap').test
+    , fs           = require('fs')
+    , path         = require('path')
+    , mkfiletree   = require('mkfiletree')
+    , readfiletree = require('readfiletree')
+    , testCommon   = require('./common')
+    , leveldown    = require('../')
+    , makeTest     = testCommon.makeExistingDbTest
+
+test('test argument-less repair() throws', function (t) {
+  t.throws(
+      leveldown.repair
+    , { name: 'Error', message: 'repair() requires `location` and `callback` arguments' }
+    , 'no-arg repair() throws'
+  )
+  t.end()
+})
+
+test('test callback-less, 1-arg, repair() throws', function (t) {
+  t.throws(
+      leveldown.repair.bind(null, 'foo')
+    , { name: 'Error', message: 'repair() requires `location` and `callback` arguments' }
+    , 'callback-less, 1-arg repair() throws'
+  )
+  t.end()
+})
+
+test('test repair non-existant directory returns error', function (t) {
+  leveldown.repair('/1/2/3/4', function (err) {
+    t.like(/no such/i, err, 'error on callback')
+    t.end()
+  })
+})
+
+// a proxy indicator that RepairDB is being called and doing its thing
+makeTest('test repair() compacts', function (db, t, done, location) {
+  db.close(function (err) {
+    t.notOk(err, 'no error')
+    var files = fs.readdirSync(location)
+    t.ok(files.some(function (f) { return (/\.log$/).test(f) }), 'directory contains log file(s)')
+    t.notOk(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory does not contain sst file(s)')
+    leveldown.repair(location, function () {
+      files = fs.readdirSync(location)
+      t.notOk(files.some(function (f) { return (/\.log$/).test(f) }), 'directory does not contain log file(s)')
+      t.ok(files.some(function (f) { return (/\.sst$/).test(f) }), 'directory contains sst file(s)')
+      done(false)
+    })
+  })
+})
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-leveldown.git



More information about the Pkg-javascript-commits mailing list