Permalink
Browse files

Added unit tests for syncOpen

  • Loading branch information...
1 parent b46e2af commit 34b8aa009575f20ff08e637e2bea4f1b6fc7b49f @ulikoehler ulikoehler committed Feb 3, 2013
Showing with 39 additions and 4 deletions.
  1. +0 −1 src/coffee/leveldb/handle.coffee
  2. +3 −2 src/cpp/handle.cc
  3. +36 −1 test/handle-test.coffee
@@ -67,7 +67,6 @@ exports.open = (path, options, callback) ->
###
exports.openSync = (path, options) ->
-
# optional options
if typeof options is 'function'
callback = options
View
@@ -164,7 +164,6 @@ class JHandle::OpenAsync : public OpAsync {
Persistent<Value> comparator_;
};
-
static Handle<Value> openSync(const Arguments& args) {
if (args.Length() != 2 || !args[0]->IsString()) {
return ThrowTypeError("Invalid arguments");
@@ -611,9 +610,11 @@ void JHandle::Initialize(Handle<Object> target) {
// Static methods
NODE_SET_METHOD(target, "open", OpenAsync::Hook<OpenAsync>);
- NODE_SET_METHOD(target, "openSync", openSync);
NODE_SET_METHOD(target, "destroy", OpenAsync::Hook<DestroyAsync>);
NODE_SET_METHOD(target, "repair", OpenAsync::Hook<RepairAsync>);
+
+ //Synchronous methods
+ NODE_SET_METHOD(target, "openSync", openSync);
// Set version
target->Set(String::New("majorVersion"),
View
@@ -1,10 +1,45 @@
-assert = require 'assert'
+assert = require 'assert'
crypto = require 'crypto'
leveldb = require '../lib'
path = require 'path'
fs = require 'fs'
exists = fs.existsSync || path.existsSync
+#Test sync open -- Jus t test a single get/put cycle to verify it's a valid handle
+#As the code is basically the same as the async version's code, all subsequ
+describe 'syncOpen', ->
+ filename = "#{__dirname}/../tmp/open-sync-test-file"
+ db = null
+
+ beforeEach (done) ->
+ db = leveldb.openSync filename, {create_if_missing: true, error_if_exists: true}
+ done()
+ afterEach (done) ->
+ db = null
+ iterator = null
+ leveldb.destroy filename, done
+
+ itShouldBehave = (test) ->
+ describe 'with ascii values', ->
+ key = "Hello"
+ val = "World"
+ test key, val
+ describe 'as_buffer', -> test key, val, true
+ describe 'with buffer values', ->
+ key = new Buffer [1,9,9,9]
+ val = new Buffer [1,2,3,4]
+ test key, val
+ describe 'as_buffer', -> test key, val, true
+ itShouldBehave (key, val, asBuffer) ->
+ it 'should put key/value pair', (done) ->
+ db.put key, val, (err) ->
+ assert.ifError err
+ db.get key, as_buffer: asBuffer, (err, value) ->
+ assert.ifError err
+ assert Buffer.isBuffer value if asBuffer
+ assert.equal val.toString(), value.toString()
+ done()
+
describe 'Handle', ->
filename = "#{__dirname}/../tmp/handle-test-file"

0 comments on commit 34b8aa0

Please sign in to comment.