Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge factory function into testCommon parameter #268

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, [])
Copy link
Member Author

@ralphtheninja ralphtheninja Jul 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the api is almost identical for all test functions, except for two tests in test/iterator-range-test.js which takes an additional data parameter. Which bugs me a bit 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could make that internal by only exporting all, because this file only has setUp, range and tearDown - that's one test. We only have to export "subtests" if there are multiple, and if they should be skippable.

I don't know if now is the right time, but we can also make an effort to split tests files in such a way that you'd only exclude files, not subtests. Then each file only needs one export.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

=> #270

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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to tack on testCommon everywhere, even if it's not used in some tests. Just to make it more symmetric.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't standard complain about that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought so as well.

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