[Pkg-javascript-commits] [node-leveldown] 257/492: expand basic chained batch tests

Andrew Kelley andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:06 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 3a92914bbd5929da88c0c6c7d9279d93dddd525b
Author: Rod Vagg <rod at vagg.org>
Date:   Wed Mar 13 20:14:54 2013 +1100

    expand basic chained batch tests
---
 test/chained-batch-test.js | 42 +++++++++++++++++++++++++++++++-----------
 test/common.js             | 27 +++++++++++++++++++++++----
 test/iterator-test.js      | 18 +-----------------
 3 files changed, 55 insertions(+), 32 deletions(-)

diff --git a/test/chained-batch-test.js b/test/chained-batch-test.js
index a3eb044..dc8cef5 100644
--- a/test/chained-batch-test.js
+++ b/test/chained-batch-test.js
@@ -9,19 +9,39 @@ test('setUp', function (t) {
   db.open(testCommon.setUp.bind(null, t))
 })
 
-test('writes', function (t) {
-  db.batch()
-    .put('foo', 'bar')
-    .write(function (err) {
-      t.notOk(err, 'no error')
-      db.get('foo', function (err, value) {
+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')
-        t.equal(value.toString(), 'bar')
-        t.end()
-      })
-    })
+
+        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))
-})
+})
\ No newline at end of file
diff --git a/test/common.js b/test/common.js
index a5db1c1..204ec92 100644
--- a/test/common.js
+++ b/test/common.js
@@ -45,9 +45,28 @@ var dbidx = 0
       setUp(t) // same cleanup!
     }
 
+  , collectEntries = function (iterator, callback) {
+      var data = []
+        , next = function () {
+            iterator.next(function (err, key, value) {
+              if (err) return callback(err)
+              if (!arguments.length) {
+                return iterator.end(function (err) {
+                  callback(err, data)
+                })
+              }
+              if (key == +key) key = +key
+              data.push({ key: key, value: value })
+              process.nextTick(next)
+            })
+          }
+      next()
+    }
+
 module.exports = {
-    location     : location
-  , lastLocation : lastLocation
-  , setUp        : setUp
-  , tearDown     : tearDown
+    location       : location
+  , lastLocation   : lastLocation
+  , setUp          : setUp
+  , tearDown       : tearDown
+  , collectEntries : collectEntries
 }
\ No newline at end of file
diff --git a/test/iterator-test.js b/test/iterator-test.js
index 33fa0f9..4fbc9f5 100644
--- a/test/iterator-test.js
+++ b/test/iterator-test.js
@@ -1,6 +1,7 @@
 const test       = require('tap').test
     , testCommon = require('./common')
     , leveldown  = require('../')
+    , collectEntries = testCommon.collectEntries
 
 var db
   , sourceData = (function () {
@@ -18,23 +19,6 @@ var db
       return d
     }())
   , transformSource = function (d) { return { key: d.key, value: d.value } }
-  , collectEntries = function (iterator, callback) {
-      var data = []
-        , next = function () {
-            iterator.next(function (err, key, value) {
-              if (err) return callback(err)
-              if (!arguments.length) {
-                return iterator.end(function (err) {
-                  callback(err, data)
-                })
-              }
-              if (key == +key) key = +key
-              data.push({ key: key, value: value })
-              process.nextTick(next)
-            })
-          }
-      next()
-    }
 
 test('setUp', function (t) {
   db = leveldown(testCommon.location())

-- 
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