[Pkg-javascript-commits] [node-leveldown] 30/492: remove global garbage
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sun Jul 6 17:13:41 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 def2a4a33fbd86dbe91a08bea8d62f9c954f1348
Author: Rod Vagg <rod at vagg.org>
Date: Sat Aug 18 18:40:33 2012 +1000
remove global garbage
---
test/binary-test.js | 25 +++++++++++--------------
test/common.js | 24 ++++++++++++++----------
test/copy-test.js | 7 +++----
test/{ => data}/testdata.bin | Bin
test/read-stream-test.js | 7 +++----
test/simple-test.js | 41 +++++++++++++++++++++--------------------
test/write-stream-test.js | 7 +++----
7 files changed, 55 insertions(+), 56 deletions(-)
diff --git a/test/binary-test.js b/test/binary-test.js
index 7082946..b13ae53 100644
--- a/test/binary-test.js
+++ b/test/binary-test.js
@@ -1,7 +1,5 @@
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
-/*global commonSetUp:true, commonTearDown:true, loadBinaryTestData:true, binaryTestDataMD5Sum:true, checkBinaryTestData:true*/
-
var buster = require('buster')
, assert = buster.assert
, levelup = require('../lib/levelup.js')
@@ -9,24 +7,23 @@ var buster = require('buster')
, rimraf = require('rimraf')
, async = require('async')
, fs = require('fs')
-
-require('./common.js')
+ , common = require('./common')
buster.testCase('Binary API', {
'setUp': function (done) {
- commonSetUp.call(this)
- loadBinaryTestData(function (err, data) {
+ common.commonSetUp.call(this)
+ common.loadBinaryTestData(function (err, data) {
refute(err)
this.testData = data
done()
}.bind(this))
}
- , 'tearDown': commonTearDown
+ , 'tearDown': common.commonTearDown
, 'sanity check on test data': function (done) {
assert(Buffer.isBuffer(this.testData))
- checkBinaryTestData(this.testData, done)
+ common.checkBinaryTestData(this.testData, done)
}
, 'test put() and get() with binary value {encoding:binary}': function (done) {
@@ -36,7 +33,7 @@ buster.testCase('Binary API', {
db.get('binarydata', { encoding: 'binary' }, function (err, value) {
refute(err)
assert(value)
- checkBinaryTestData(value, done)
+ common.checkBinaryTestData(value, done)
})
})
}.bind(this))
@@ -49,7 +46,7 @@ buster.testCase('Binary API', {
db.get('binarydata', function (err, value) {
refute(err)
assert(value)
- checkBinaryTestData(value, done)
+ common.checkBinaryTestData(value, done)
})
})
}.bind(this))
@@ -75,7 +72,7 @@ buster.testCase('Binary API', {
db.get('binarydata', { keyEncoding: 'utf8', valueEncoding: 'binary' }, function (err, value) {
refute(err)
assert(value)
- checkBinaryTestData(value, done)
+ common.checkBinaryTestData(value, done)
})
})
}.bind(this))
@@ -88,7 +85,7 @@ buster.testCase('Binary API', {
db.get('binarydata', function (err, value) {
refute(err)
assert(value)
- checkBinaryTestData(value, done)
+ common.checkBinaryTestData(value, done)
})
})
}.bind(this))
@@ -113,7 +110,7 @@ buster.testCase('Binary API', {
refute(err)
db.get(this.testData, { encoding: 'binary' }, function (err, value) {
refute(err)
- checkBinaryTestData(value, done)
+ common.checkBinaryTestData(value, done)
}.bind(this))
}.bind(this))
}.bind(this))
@@ -156,7 +153,7 @@ buster.testCase('Binary API', {
assert.equals(value, 'a' + key + 'value')
callback()
} else {
- checkBinaryTestData(value, callback)
+ common.checkBinaryTestData(value, callback)
}
})
}
diff --git a/test/common.js b/test/common.js
index 6058556..13108f9 100644
--- a/test/common.js
+++ b/test/common.js
@@ -31,10 +31,14 @@ ba.add('isUndefined', {
, refuteMessage: '${0} expected not to be undefined'
})
-global.openTestDatabase = function () {
+module.exports.nextLocation = function () {
+ return path.join(__dirname, 'levelup_test_db_' + dbidx++)
+}
+
+module.exports.openTestDatabase = function () {
var options = typeof arguments[0] == 'object' ? arguments[0] : { createIfMissing: true, errorIfExists: true }
, callback = typeof arguments[0] == 'function' ? arguments[0] : arguments[1]
- , location = typeof arguments[0] == 'string' ? arguments[0] : path.join(__dirname, 'levelup_test_db_' + dbidx++)
+ , location = typeof arguments[0] == 'string' ? arguments[0] : module.exports.nextLocation()
rimraf(location, function (err) {
refute(err)
this.cleanupDirs.push(location)
@@ -46,7 +50,7 @@ global.openTestDatabase = function () {
}.bind(this))
}
-global.commonTearDown = function (done) {
+module.exports.commonTearDown = function (done) {
async.forEach(
this.closeableDatabases
, function (db, callback) {
@@ -58,13 +62,13 @@ global.commonTearDown = function (done) {
)
}
-global.loadBinaryTestData = function (callback) {
- fs.readFile(path.join(__dirname, 'testdata.bin'), callback)
+module.exports.loadBinaryTestData = function (callback) {
+ fs.readFile(path.join(__dirname, 'data/testdata.bin'), callback)
}
-global.binaryTestDataMD5Sum = '920725ef1a3b32af40ccd0b78f4a62fd'
+module.exports.binaryTestDataMD5Sum = '920725ef1a3b32af40ccd0b78f4a62fd'
-global.checkBinaryTestData = function (testData, callback) {
+module.exports.checkBinaryTestData = function (testData, callback) {
var fname = '__tst.dat.' + Math.random()
fs.writeFile(fname, testData, function (err) {
refute(err)
@@ -73,16 +77,16 @@ global.checkBinaryTestData = function (testData, callback) {
refute(err)
refute(stderr)
var md5Sum = stdout.split(' ')[0]
- assert.equals(md5Sum, global.binaryTestDataMD5Sum)
+ assert.equals(md5Sum, module.exports.binaryTestDataMD5Sum)
fs.unlink(fname, callback)
})
})
})
}
-global.commonSetUp = function () {
+module.exports.commonSetUp = function () {
this.cleanupDirs = []
this.closeableDatabases = []
- this.openTestDatabase = global.openTestDatabase.bind(this)
+ this.openTestDatabase = module.exports.openTestDatabase.bind(this)
this.timeout = 1000
}
\ No newline at end of file
diff --git a/test/copy-test.js b/test/copy-test.js
index 9ddd557..743bf40 100644
--- a/test/copy-test.js
+++ b/test/copy-test.js
@@ -1,7 +1,5 @@
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
-/*global commonSetUp:true, commonTearDown:true*/
-
var buster = require('buster')
, assert = buster.assert
, levelup = require('../lib/levelup.js')
@@ -9,10 +7,11 @@ var buster = require('buster')
, rimraf = require('rimraf')
, async = require('async')
, fs = require('fs')
+ , common = require('./common')
buster.testCase('Copy', {
- 'setUp': commonSetUp
- , 'tearDown': commonTearDown
+ 'setUp': common.commonSetUp
+ , 'tearDown': common.commonTearDown
, 'copy full database': function (done) {
var sourceData = []
diff --git a/test/testdata.bin b/test/data/testdata.bin
similarity index 100%
rename from test/testdata.bin
rename to test/data/testdata.bin
diff --git a/test/read-stream-test.js b/test/read-stream-test.js
index 2aee869..10580d5 100644
--- a/test/read-stream-test.js
+++ b/test/read-stream-test.js
@@ -1,7 +1,5 @@
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
-/*global commonSetUp:true, commonTearDown:true*/
-
var buster = require('buster')
, assert = buster.assert
, levelup = require('../lib/levelup.js')
@@ -10,10 +8,11 @@ var buster = require('buster')
, async = require('async')
, fs = require('fs')
, path = require('path')
+ , common = require('./common')
buster.testCase('ReadStream', {
'setUp': function () {
- commonSetUp.call(this)
+ common.commonSetUp.call(this)
this.readySpy = this.spy()
this.dataSpy = this.spy()
@@ -49,7 +48,7 @@ buster.testCase('ReadStream', {
}.bind(this)
}
- , 'tearDown': commonTearDown
+ , 'tearDown': common.commonTearDown
//TODO: test various encodings
diff --git a/test/simple-test.js b/test/simple-test.js
index e6ff7c7..dbfe452 100644
--- a/test/simple-test.js
+++ b/test/simple-test.js
@@ -1,7 +1,5 @@
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
-/*global commonSetUp:true, commonTearDown:true*/
-
var buster = require('buster')
, assert = buster.assert
, levelup = require('../lib/levelup.js')
@@ -9,10 +7,11 @@ var buster = require('buster')
, rimraf = require('rimraf')
, async = require('async')
, fs = require('fs')
+ , common = require('./common')
buster.testCase('Basic API', {
- 'setUp': commonSetUp
- , 'tearDown': commonTearDown
+ 'setUp': common.commonSetUp
+ , 'tearDown': common.commonTearDown
, 'levelup()': function () {
assert.isFunction(levelup)
@@ -21,26 +20,27 @@ buster.testCase('Basic API', {
}
, 'default options': function (done) {
- levelup('/tmp/testdb', { createIfMissing: true, errorIfExists: true }, function (err, db) {
+ var location = common.nextLocation()
+ levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
refute(err)
assert.isTrue(db.isOpen())
this.closeableDatabases.push(db)
- this.cleanupDirs.push('/tmp/testdb')
+ this.cleanupDirs.push(location)
db.close(function (err) {
refute(err)
assert.isFalse(db.isOpen())
- levelup('/tmp/testdb', function (err, db) { // no options object
+ levelup(location, function (err, db) { // no options object
refute(err)
assert.isObject(db)
assert.isFalse(db.options.createIfMissing)
assert.isFalse(db.options.errorIfExists)
- assert.equals(db.location, '/tmp/testdb')
+ assert.equals(db.location, location)
// read-only properties
db.location = 'foo'
- assert.equals(db.location, '/tmp/testdb')
+ assert.equals(db.location, location)
done()
}.bind(this))
}.bind(this))
@@ -48,24 +48,25 @@ buster.testCase('Basic API', {
}
, 'basic options': function (done) {
- levelup('/tmp/foodb', { createIfMissing: true, errorIfExists: true }, function (err, db) {
+ var location = common.nextLocation()
+ levelup(location, { createIfMissing: true, errorIfExists: true }, function (err, db) {
refute(err)
this.closeableDatabases.push(db)
- this.cleanupDirs.push('/tmp/foodb')
+ this.cleanupDirs.push(location)
assert.isObject(db)
assert.isTrue(db.options.createIfMissing)
assert.isTrue(db.options.errorIfExists)
- assert.equals(db.location, '/tmp/foodb')
+ assert.equals(db.location, location)
// read-only properties
db.location = 'bar'
- assert.equals(db.location, '/tmp/foodb')
+ assert.equals(db.location, location)
done()
}.bind(this))
}
, 'open() with !createIfMissing expects error': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), function (err, db) {
assert(err)
refute(db)
assert.isInstanceOf(err, Error)
@@ -76,7 +77,7 @@ buster.testCase('Basic API', {
}
, 'open() with createIfMissing expects directory to be created': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', { createIfMissing: true }, function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
this.closeableDatabases.push(db)
refute(err)
assert.isTrue(db.isOpen())
@@ -89,7 +90,7 @@ buster.testCase('Basic API', {
}
, 'open() with errorIfExists expects error if exists': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', { createIfMissing: true }, function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
this.closeableDatabases.push(db)
refute(err) // sanity
levelup(this.cleanupDirs[0], { errorIfExists : true }, function (err) {
@@ -103,7 +104,7 @@ buster.testCase('Basic API', {
}
, 'open() with !errorIfExists does not expect error if exists': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', { createIfMissing: true }, function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
refute(err) // sanity
this.closeableDatabases.push(db)
assert.isTrue(db.isOpen())
@@ -123,7 +124,7 @@ buster.testCase('Basic API', {
, 'Simple operations': {
'get() on non-open database causes error': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', { createIfMissing: true }, function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
refute(err) // sanity
this.closeableDatabases.push(db)
assert.isTrue(db.isOpen())
@@ -142,7 +143,7 @@ buster.testCase('Basic API', {
}
, 'put() on non-open database causes error': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', { createIfMissing: true }, function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
refute(err) // sanity
this.closeableDatabases.push(db)
assert.isTrue(db.isOpen())
@@ -186,7 +187,7 @@ buster.testCase('Basic API', {
}
, 'del() on non-open database causes error': function (done) {
- levelup(this.cleanupDirs[0] = '/tmp/levelup_test_db', { createIfMissing: true }, function (err, db) {
+ levelup(this.cleanupDirs[0] = common.nextLocation(), { createIfMissing: true }, function (err, db) {
refute(err) // sanity
this.closeableDatabases.push(db)
assert.isTrue(db.isOpen())
diff --git a/test/write-stream-test.js b/test/write-stream-test.js
index 78da40b..6b91f7c 100644
--- a/test/write-stream-test.js
+++ b/test/write-stream-test.js
@@ -1,7 +1,5 @@
/* Copyright (c) 2012 Rod Vagg <@rvagg> */
-/*global commonSetUp:true, commonTearDown:true*/
-
var buster = require('buster')
, assert = buster.assert
, levelup = require('../lib/levelup.js')
@@ -10,10 +8,11 @@ var buster = require('buster')
, async = require('async')
, fs = require('fs')
, path = require('path')
+ , common = require('./common')
buster.testCase('WriteStream', {
'setUp': function () {
- commonSetUp.call(this)
+ common.commonSetUp.call(this)
this.timeout = 1000
@@ -44,7 +43,7 @@ buster.testCase('WriteStream', {
}
}
- , 'tearDown': commonTearDown
+ , 'tearDown': common.commonTearDown
//TODO: test various encodings
--
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