UNPKG

1.83 kBJavaScriptView Raw
1var db
2 , verifyNotFoundError = require('./util').verifyNotFoundError
3 , isTypedArray = require('./util').isTypedArray
4
5module.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
13module.exports.args = function (test) {
14}
15
16module.exports.put = function (test) {
17 test('test simple put()', function (t) {
18 db.put('foo', 'bar', function (err) {
19 t.error(err)
20 db.get('foo', function (err, value) {
21 t.error(err)
22 var result = value.toString()
23 if (isTypedArray(value))
24 result = String.fromCharCode.apply(null, new Uint16Array(value))
25 t.equal(result, 'bar', "should be ok")
26 t.end()
27 })
28 })
29 })
30
31 if (process.browser) {
32 test('test object value put()', function (t) {
33 db.put('dood', {pete: 'sampras'}, function (err) {
34 t.error(err)
35 db.get('dood', { asBuffer: false }, function (err, value) {
36 t.error(err)
37 t.equal(JSON.stringify(value), JSON.stringify({pete: 'sampras'}))
38 t.end()
39 })
40 })
41 })
42 }
43
44}
45
46module.exports.tearDown = function (test, testCommon) {
47 test('tearDown', function (t) {
48 db.close(testCommon.tearDown.bind(null, t))
49 })
50}
51
52module.exports.sync = function (test) {
53 test('sync', function (t) {
54 if (db._putSync) {
55 delete db.__proto__._put
56 }
57 t.end()
58 })
59}
60
61module.exports.all = function (NoSqlDatabase, test, testCommon) {
62 module.exports.setUp(NoSqlDatabase, test, testCommon)
63 module.exports.args(test)
64 module.exports.put(test)
65 if (NoSqlDatabase.prototype._putSync) {
66 module.exports.sync(test)
67 module.exports.put(test)
68 }
69 module.exports.tearDown(test, testCommon)
70}