Skip to content

Commit

Permalink
Merge factory function into testCommon parameter (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja authored and vweevers committed Jul 13, 2018
1 parent aa7e0b8 commit 1c95594
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 131 deletions.
52 changes: 26 additions & 26 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,53 +8,53 @@ var AbstractLevelDOWN = require('./').AbstractLevelDOWN
var AbstractIterator = require('./').AbstractIterator
var AbstractChainedBatch = require('./').AbstractChainedBatch

function factory () {
var factory = testCommon.factory = function () {
return new AbstractLevelDOWN()
}

/**
* Compatibility with basic LevelDOWN API
*/

require('./test/leveldown-test').args(factory, test)
require('./test/leveldown-test').args(test, testCommon)

require('./test/open-test').args(factory, test, testCommon)
require('./test/open-test').args(test, testCommon)

require('./test/del-test').setUp(factory, test, testCommon)
require('./test/del-test').args(factory, test)
require('./test/del-test').setUp(test, testCommon)
require('./test/del-test').args(test, testCommon)

require('./test/get-test').setUp(factory, test, testCommon)
require('./test/get-test').args(factory, test)
require('./test/get-test').setUp(test, testCommon)
require('./test/get-test').args(test, testCommon)

require('./test/put-test').setUp(factory, test, testCommon)
require('./test/put-test').args(factory, test)
require('./test/put-test').setUp(test, testCommon)
require('./test/put-test').args(test, testCommon)

require('./test/put-get-del-test').setUp(factory, test, testCommon)
require('./test/put-get-del-test').errorKeys(test)
require('./test/put-get-del-test').setUp(test, testCommon)
require('./test/put-get-del-test').errorKeys(test, testCommon)
// require('./test/put-get-del-test').nonErrorKeys(test, testCommon)
require('./test/put-get-del-test').errorValues()
require('./test/put-get-del-test').errorValues(test, testCommon)
require('./test/put-get-del-test').tearDown(test, testCommon)

require('./test/batch-test').setUp(factory, test, testCommon)
require('./test/batch-test').args(test)
require('./test/batch-test').setUp(test, testCommon)
require('./test/batch-test').args(test, testCommon)

require('./test/chained-batch-test').setUp(factory, test, testCommon)
require('./test/chained-batch-test').args(test)
require('./test/chained-batch-test').setUp(test, testCommon)
require('./test/chained-batch-test').args(test, testCommon)

require('./test/close-test').close(factory, test, testCommon)
require('./test/close-test').close(test, testCommon)

require('./test/iterator-test').setUp(factory, test, testCommon)
require('./test/iterator-test').args(test)
require('./test/iterator-test').sequence(test)
require('./test/iterator-test').setUp(test, testCommon)
require('./test/iterator-test').args(test, testCommon)
require('./test/iterator-test').sequence(test, testCommon)
require('./test/iterator-test').tearDown(test, testCommon)

require('./test/iterator-range-test').setUp(factory, test, testCommon, [])
require('./test/iterator-range-test').setUp(test, testCommon, [])
require('./test/iterator-range-test').tearDown(test, testCommon)

require('./test/iterator-snapshot-test').setUp(factory, test, testCommon)
require('./test/iterator-snapshot-test').setUp(test, testCommon)
require('./test/iterator-snapshot-test').tearDown(test, testCommon)

require('./test/iterator-no-snapshot-test').setUp(factory, test, testCommon)
require('./test/iterator-no-snapshot-test').setUp(test, testCommon)
require('./test/iterator-no-snapshot-test').tearDown(test, testCommon)

function implement (ctor, methods) {
Expand Down Expand Up @@ -356,7 +356,7 @@ test('test put() extensibility', function (t) {
var expectedKey = 'key'
var expectedValue = 'value'
var Test = implement(AbstractChainedBatch, { _put: spy })
var test = new Test(factory('foobar'))
var test = new Test(factory())
var returnValue = test.put(expectedKey, expectedValue)

t.equal(spy.callCount, 1, 'got _put call')
Expand All @@ -372,7 +372,7 @@ test('test del() extensibility', function (t) {
var spy = sinon.spy()
var expectedKey = 'key'
var Test = implement(AbstractChainedBatch, { _del: spy })
var test = new Test(factory('foobar'))
var test = new Test(factory())
var returnValue = test.del(expectedKey)

t.equal(spy.callCount, 1, 'got _del call')
Expand All @@ -386,7 +386,7 @@ test('test del() extensibility', function (t) {
test('test clear() extensibility', function (t) {
var spy = sinon.spy()
var Test = implement(AbstractChainedBatch, { _clear: spy })
var test = new Test(factory('foobar'))
var test = new Test(factory())
var returnValue = test.clear()

t.equal(spy.callCount, 1, 'got _clear call')
Expand Down
20 changes: 10 additions & 10 deletions test/batch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ var db
var verifyNotFoundError = require('./util').verifyNotFoundError
var isTypedArray = require('./util').isTypedArray

module.exports.setUp = function (factory, test, testCommon) {
module.exports.setUp = function (test, testCommon) {
test('setUp common', testCommon.setUp)
test('setUp db', function (t) {
db = factory()
db = testCommon.factory()
db.open(t.end.bind(t))
})
}

module.exports.args = function (test) {
module.exports.args = function (test, testCommon) {
test('test callback-less, 2-arg, batch() throws', function (t) {
t.throws(db.batch.bind(db, 'foo', {}), 'callback-less, 2-arg batch() throws')
t.end()
Expand Down Expand Up @@ -159,7 +159,7 @@ module.exports.args = function (test) {
})
}

module.exports.batch = function (test) {
module.exports.batch = function (test, testCommon) {
test('test batch() with empty array', function (t) {
db.batch([], function (err) {
t.error(err)
Expand Down Expand Up @@ -235,7 +235,7 @@ module.exports.batch = function (test) {
})
})
}
module.exports.atomic = function (test) {
module.exports.atomic = function (test, testCommon) {
test('test multiple batch()', function (t) {
t.plan(4)

Expand Down Expand Up @@ -266,11 +266,11 @@ module.exports.tearDown = function (test, testCommon) {
})
}

module.exports.all = function (factory, test, testCommon) {
module.exports.all = function (test, testCommon) {
testCommon = testCommon || require('./common')
module.exports.setUp(factory, test, testCommon)
module.exports.args(test)
module.exports.batch(test)
module.exports.atomic(test)
module.exports.setUp(test, testCommon)
module.exports.args(test, testCommon)
module.exports.batch(test, testCommon)
module.exports.atomic(test, testCommon)
module.exports.tearDown(test, testCommon)
}
16 changes: 8 additions & 8 deletions test/chained-batch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ function collectBatchOps (batch) {
return _operations
}

module.exports.setUp = function (factory, test, testCommon) {
module.exports.setUp = function (test, testCommon) {
test('setUp common', testCommon.setUp)
test('setUp db', function (t) {
db = factory()
db = testCommon.factory()
db.open(t.end.bind(t))
})
}

module.exports.args = function (test) {
module.exports.args = function (test, testCommon) {
test('test batch#put() with missing `value`', function (t) {
db.batch().put('foo1')
t.end()
Expand Down Expand Up @@ -213,7 +213,7 @@ module.exports.args = function (test) {
})
}

module.exports.batch = function (test) {
module.exports.batch = function (test, testCommon) {
test('test basic batch', function (t) {
db.batch([
{ type: 'put', key: 'one', value: '1' },
Expand Down Expand Up @@ -256,10 +256,10 @@ module.exports.tearDown = function (test, testCommon) {
})
}

module.exports.all = function (factory, test, testCommon) {
module.exports.all = function (test, testCommon) {
testCommon = testCommon || require('./common')
module.exports.setUp(factory, test, testCommon)
module.exports.args(test)
module.exports.batch(test)
module.exports.setUp(test, testCommon)
module.exports.args(test, testCommon)
module.exports.batch(test, testCommon)
module.exports.tearDown(test, testCommon)
}
4 changes: 2 additions & 2 deletions test/close-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports.close = function (factory, test, testCommon) {
module.exports.close = function (test, testCommon) {
testCommon = testCommon || require('./common')
test('test close()', function (t) {
var db = factory()
var db = testCommon.factory()

db.open(function (err) {
t.error(err)
Expand Down
18 changes: 9 additions & 9 deletions test/del-test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var db
var verifyNotFoundError = require('./util').verifyNotFoundError

module.exports.setUp = function (factory, test, testCommon) {
module.exports.setUp = function (test, testCommon) {
test('setUp common', testCommon.setUp)
test('setUp db', function (t) {
db = factory()
db = testCommon.factory()
db.open(t.end.bind(t))
})
}

module.exports.args = function (factory, test) {
module.exports.args = function (test, testCommon) {
test('test argument-less del() throws', function (t) {
t.throws(
db.del.bind(db)
Expand Down Expand Up @@ -39,7 +39,7 @@ module.exports.args = function (factory, test) {

test('test custom _serialize*', function (t) {
t.plan(3)
var db = factory()
var db = testCommon.factory()
db._serializeKey = function (data) { return data }
db._del = function (key, options, callback) {
t.deepEqual(key, { foo: 'bar' })
Expand All @@ -54,7 +54,7 @@ module.exports.args = function (factory, test) {
})
}

module.exports.del = function (test) {
module.exports.del = function (test, testCommon) {
test('test simple del()', function (t) {
db.put('foo', 'bar', function (err) {
t.error(err)
Expand Down Expand Up @@ -84,10 +84,10 @@ module.exports.tearDown = function (test, testCommon) {
})
}

module.exports.all = function (factory, test, testCommon) {
module.exports.all = function (test, testCommon) {
testCommon = testCommon || require('./common')
module.exports.setUp(factory, test, testCommon)
module.exports.args(factory, test)
module.exports.del(test)
module.exports.setUp(test, testCommon)
module.exports.args(test, testCommon)
module.exports.del(test, testCommon)
module.exports.tearDown(test, testCommon)
}
18 changes: 9 additions & 9 deletions test/get-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ var db
var verifyNotFoundError = require('./util').verifyNotFoundError
var isTypedArray = require('./util').isTypedArray

module.exports.setUp = function (factory, test, testCommon) {
module.exports.setUp = function (test, testCommon) {
test('setUp common', testCommon.setUp)
test('setUp db', function (t) {
db = factory()
db = testCommon.factory()
db.open(t.end.bind(t))
})
}

module.exports.args = function (factory, test) {
module.exports.args = function (test, testCommon) {
test('test argument-less get() throws', function (t) {
t.throws(
db.get.bind(db)
Expand Down Expand Up @@ -40,7 +40,7 @@ module.exports.args = function (factory, test) {

test('test custom _serialize*', function (t) {
t.plan(3)
var db = factory()
var db = testCommon.factory()
db._serializeKey = function (data) { return data }
db._get = function (key, options, callback) {
t.deepEqual(key, { foo: 'bar' })
Expand All @@ -55,7 +55,7 @@ module.exports.args = function (factory, test) {
})
}

module.exports.get = function (test) {
module.exports.get = function (test, testCommon) {
test('test simple get()', function (t) {
db.put('foo', 'bar', function (err) {
t.error(err)
Expand Down Expand Up @@ -161,10 +161,10 @@ module.exports.tearDown = function (test, testCommon) {
})
}

module.exports.all = function (factory, test, testCommon) {
module.exports.all = function (test, testCommon) {
testCommon = testCommon || require('./common')
module.exports.setUp(factory, test, testCommon)
module.exports.args(factory, test)
module.exports.get(test)
module.exports.setUp(test, testCommon)
module.exports.args(test, testCommon)
module.exports.get(test, testCommon)
module.exports.tearDown(test, testCommon)
}
12 changes: 6 additions & 6 deletions test/iterator-no-snapshot-test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var collectEntries = require('level-concat-iterator')

exports.setUp = function (factory, test, testCommon) {
exports.setUp = function (test, testCommon) {
test('setUp common', testCommon.setUp)
}

exports.noSnapshot = function (factory, test) {
exports.noSnapshot = function (test, testCommon) {
function make (run) {
return function (t) {
var db = factory()
var db = testCommon.factory()
var operations = [
{ type: 'put', key: 'a', value: 'a' },
{ type: 'put', key: 'b', value: 'b' },
Expand Down Expand Up @@ -65,9 +65,9 @@ exports.tearDown = function (test, testCommon) {
test('tearDown', testCommon.tearDown)
}

exports.all = function (factory, test, testCommon) {
exports.all = function (test, testCommon) {
testCommon = testCommon || require('./common')
exports.setUp(factory, test, testCommon)
exports.noSnapshot(factory, test)
exports.setUp(test, testCommon)
exports.noSnapshot(test, testCommon)
exports.tearDown(test, testCommon)
}
12 changes: 6 additions & 6 deletions test/iterator-range-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ var collectEntries = require('level-concat-iterator')

var db

module.exports.setUp = function (factory, test, testCommon, data) {
module.exports.setUp = function (test, testCommon, data) {
test('setUp common', testCommon.setUp)
test('setUp db', function (t) {
db = factory()
db = testCommon.factory()
db.open(function () {
db.batch(data.map(function (d) {
return {
Expand All @@ -18,7 +18,7 @@ module.exports.setUp = function (factory, test, testCommon, data) {
})
}

module.exports.range = function (leveldown, test, data) {
module.exports.range = function (test, testCommon, data) {
function rangeTest (name, opts, expected) {
opts.keyAsBuffer = false
opts.valueAsBuffer = false
Expand Down Expand Up @@ -354,7 +354,7 @@ module.exports.tearDown = function (test, testCommon) {
})
}

module.exports.all = function (factory, test, testCommon) {
module.exports.all = function (test, testCommon) {
testCommon = testCommon || require('./common')

var data = (function () {
Expand All @@ -371,7 +371,7 @@ module.exports.all = function (factory, test, testCommon) {
return d
}())

module.exports.setUp(factory, test, testCommon, data)
module.exports.range(factory, test, data)
module.exports.setUp(test, testCommon, data)
module.exports.range(test, testCommon, data)
module.exports.tearDown(test, testCommon)
}
Loading

0 comments on commit 1c95594

Please sign in to comment.