[Pkg-javascript-commits] [node-leveldown] 214/492: added initial/basic test suite
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:14:00 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 f481221fce934129dfebfb7d05f41c6f632c83aa
Author: Rod Vagg <rod at vagg.org>
Date: Sun Feb 17 13:10:48 2013 +1100
added initial/basic test suite
---
test/close-test.js | 21 +++++++++++++++++++
test/common.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++
test/leveldown-test.js | 14 +++++++++++++
test/open-test.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 144 insertions(+)
diff --git a/test/close-test.js b/test/close-test.js
new file mode 100644
index 0000000..1a64910
--- /dev/null
+++ b/test/close-test.js
@@ -0,0 +1,21 @@
+const test = require('tap').test
+ , testCommon = require('./common')
+ , leveldown = require('../')
+
+test('setUp', testCommon.setUp)
+
+test('test database close', function (t) {
+ var db = leveldown(testCommon.location())
+
+ db.open(function (err) {
+ t.notOk(err, 'no error')
+ t.throws(db.close.bind(db), 'no-arg close() throws')
+
+ db.close(function (err) {
+ t.notOk(err, 'no error')
+ t.end()
+ })
+ })
+})
+
+test('tearDown', testCommon.tearDown)
\ No newline at end of file
diff --git a/test/common.js b/test/common.js
new file mode 100644
index 0000000..902ace2
--- /dev/null
+++ b/test/common.js
@@ -0,0 +1,53 @@
+const path = require('path')
+ , fs = require('fs')
+ , rimraf = require('rimraf')
+
+var dbidx = 0
+
+ , location = function () {
+ return path.join(__dirname, '_leveldown_test_db_' + dbidx++)
+ }
+
+ , lastLocation = function () {
+ return path.join(__dirname, '_leveldown_test_db_' + dbidx)
+ }
+
+ , cleanup = function (callback) {
+ fs.readdir(__dirname, function (err, list) {
+ if (err) return callback(err)
+
+ list = list.filter(function (f) {
+ return (/^_leveldown_test_db_/).test(f)
+ })
+
+ var ret = 0
+
+ if (!list.length)
+ return callback()
+
+ list.forEach(function (f) {
+ rimraf(f, function () {
+ if (++ret == list.length)
+ callback()
+ })
+ })
+ })
+ }
+
+ , setUp = function (t) {
+ cleanup(function (err) {
+ t.notOk(err, 'cleanup returned an error')
+ t.end()
+ })
+ }
+
+ , tearDown = function (t) {
+ setUp(t) // same cleanup!
+ }
+
+module.exports = {
+ location : location
+ , lastLocation : lastLocation
+ , setUp : setUp
+ , tearDown : tearDown
+}
\ No newline at end of file
diff --git a/test/leveldown-test.js b/test/leveldown-test.js
new file mode 100644
index 0000000..b5b85a8
--- /dev/null
+++ b/test/leveldown-test.js
@@ -0,0 +1,14 @@
+const test = require('tap').test
+ , leveldown = require('../')
+
+test('test database creation no-arg throws', function (t) {
+ t.throws(leveldown, '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()
+})
\ No newline at end of file
diff --git a/test/open-test.js b/test/open-test.js
new file mode 100644
index 0000000..6842bff
--- /dev/null
+++ b/test/open-test.js
@@ -0,0 +1,56 @@
+const fs = require('fs')
+ , test = require('tap').test
+ , testCommon = require('./common')
+ , leveldown = require('../')
+
+test('setUp', testCommon.setUp)
+
+test('test database open no-arg throws', function (t) {
+ t.throws(leveldown(testCommon.location()).open, 'no-arg open() throws')
+ t.end()
+})
+
+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()
+ })
+ })
+ })
+})
+
+test('tearDown', testCommon.tearDown)
\ 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