1 | var db
|
2 | , verifyNotFoundError = require('./util').verifyNotFoundError
|
3 | , isTypedArray = require('./util').isTypedArray
|
4 |
|
5 | module.exports.setUp = function (NoSqlDatabase, test, testCommon) {
|
6 | test('setUp common', testCommon.setUp)
|
7 | test('setUp db', function (t) {
|
8 | db = NoSqlDatabase(testCommon.location())
|
9 | db.open(t.end.bind(t))
|
10 | })
|
11 | }
|
12 |
|
13 | module.exports.args = function (test) {
|
14 | }
|
15 |
|
16 | module.exports.isExists = function (test) {
|
17 | test('test simple isExists()', function (t) {
|
18 | db.put('foo', 'bar', function (err) {
|
19 | t.error(err)
|
20 | db.isExists('foo', function (err, value) {
|
21 | t.error(err)
|
22 | t.ok(value === true, 'should be exists foo key')
|
23 |
|
24 | db.isExists('foo', {}, function (err, value) {
|
25 | t.error(err)
|
26 | t.ok(value === true, 'should be exists foo key')
|
27 |
|
28 |
|
29 | db.isExists('foo', { fillCache: false }, function (err, value) {
|
30 | t.error(err)
|
31 | t.ok(value === true, 'should be exists foo key')
|
32 | t.end()
|
33 | })
|
34 | })
|
35 | })
|
36 | })
|
37 | })
|
38 |
|
39 | test('test simultaniously isExists()', function (t) {
|
40 | db.put('hello', 'world', function (err) {
|
41 | t.error(err)
|
42 | var r = 0
|
43 | , done = function () {
|
44 | if (++r == 20)
|
45 | t.end()
|
46 | }
|
47 | , i = 0
|
48 | , j = 0
|
49 |
|
50 | for (; i < 10; ++i)
|
51 | db.isExists('hello', function(err, value) {
|
52 | t.error(err)
|
53 | t.strictEqual(value, true)
|
54 | done()
|
55 | })
|
56 |
|
57 | for (; j < 10; ++j)
|
58 | db.isExists('not found', function(err, value) {
|
59 | t.error(err)
|
60 | t.strictEqual(value, false)
|
61 | done()
|
62 | })
|
63 | })
|
64 | })
|
65 | }
|
66 |
|
67 | module.exports.tearDown = function (test, testCommon) {
|
68 | test('tearDown', function (t) {
|
69 | db.close(testCommon.tearDown.bind(null, t))
|
70 | })
|
71 | }
|
72 |
|
73 | module.exports.sync = function (test) {
|
74 | test('sync', function (t) {
|
75 | if (db._isExistsSync) {
|
76 | delete db.__proto__._isExists
|
77 | }
|
78 | t.end()
|
79 | })
|
80 | }
|
81 |
|
82 | module.exports.all = function (NoSqlDatabase, test, testCommon) {
|
83 | module.exports.setUp(NoSqlDatabase, test, testCommon)
|
84 | module.exports.args(test)
|
85 | module.exports.isExists(test)
|
86 | if (NoSqlDatabase.prototype._isExistsSync) {
|
87 | module.exports.sync(test)
|
88 | module.exports.isExists(test)
|
89 | }
|
90 | module.exports.tearDown(test, testCommon)
|
91 | }
|