1 | module.exports.setUp = function (test, testCommon) {
|
2 | test('setUp', testCommon.setUp)
|
3 | }
|
4 |
|
5 | module.exports.args = function (NoSqlDatabase, test, testCommon) {
|
6 | }
|
7 |
|
8 | module.exports.open = function (NoSqlDatabase, test, testCommon) {
|
9 | test('test database open, no options', function (t) {
|
10 | var db = NoSqlDatabase(testCommon.location())
|
11 |
|
12 |
|
13 | db.open(function (err) {
|
14 | t.error(err)
|
15 | t.ok(db.isOpen())
|
16 | t.ok(db.opened)
|
17 | db.close(function () {
|
18 | t.notOk(db.isOpen())
|
19 | t.notOk(db.opened)
|
20 | t.end()
|
21 | })
|
22 | })
|
23 | })
|
24 |
|
25 | test('test database open, options and callback', function (t) {
|
26 | var db = NoSqlDatabase(testCommon.location())
|
27 |
|
28 |
|
29 | db.open({}, function (err) {
|
30 | t.error(err)
|
31 | t.ok(db.isOpen())
|
32 | t.ok(db.opened)
|
33 | db.close(function () {
|
34 | t.notOk(db.isOpen())
|
35 | t.notOk(db.opened)
|
36 | t.end()
|
37 | })
|
38 | })
|
39 | })
|
40 | test('test database open, close and open', function (t) {
|
41 | var db = NoSqlDatabase(testCommon.location())
|
42 |
|
43 | db.open(function (err) {
|
44 | t.error(err)
|
45 | t.ok(db.isOpen())
|
46 | db.close(function (err) {
|
47 | t.error(err)
|
48 | t.notOk(db.isOpen())
|
49 | db.open(function (err) {
|
50 | t.error(err)
|
51 | t.ok(db.isOpen())
|
52 | db.close(function () {
|
53 | t.notOk(db.isOpen())
|
54 | t.end()
|
55 | })
|
56 | })
|
57 | })
|
58 | })
|
59 | })
|
60 |
|
61 | test('test database open event', function (t) {
|
62 | var db = NoSqlDatabase(testCommon.location())
|
63 | db.once("open", function(){
|
64 | t.ok(db.isOpen())
|
65 | t.ok(db.opened)
|
66 | t.end()
|
67 | })
|
68 | db.open(function (err) {
|
69 | t.error(err)
|
70 | t.ok(db.isOpen())
|
71 | t.ok(db.opened)
|
72 | })
|
73 | })
|
74 |
|
75 | test('test database ready event', function (t) {
|
76 | var db = NoSqlDatabase(testCommon.location())
|
77 | db.once("ready", function(){
|
78 | t.ok(db.isOpen())
|
79 | t.ok(db.opened)
|
80 | t.end()
|
81 | })
|
82 | db.open(function (err) {
|
83 | t.error(err)
|
84 | t.ok(db.isOpen())
|
85 | t.ok(db.opened)
|
86 | })
|
87 | })
|
88 | }
|
89 |
|
90 | module.exports.openAdvanced = function (NoSqlDatabase, test, testCommon) {
|
91 | test('test database open createIfMissing:false', function (t) {
|
92 | var db = NoSqlDatabase(testCommon.location())
|
93 |
|
94 | db.open({ createIfMissing: false }, function (err) {
|
95 | t.ok(err, 'error')
|
96 | t.notOk(db.isOpen())
|
97 | t.ok(/does not exist/.test(err.message), 'error is about dir not existing')
|
98 | t.end()
|
99 | })
|
100 | })
|
101 |
|
102 | test('test database open errorIfExists:true', function (t) {
|
103 | var location = testCommon.location()
|
104 | , db = NoSqlDatabase(location)
|
105 |
|
106 |
|
107 | db.open({}, function (err) {
|
108 | t.error(err)
|
109 | t.ok(db.isOpen())
|
110 | db.close(function (err) {
|
111 | t.error(err)
|
112 | t.notOk(db.isOpen())
|
113 |
|
114 |
|
115 | db = NoSqlDatabase(location)
|
116 | db.open({ createIfMissing: false, errorIfExists: true }, function (err) {
|
117 | t.ok(err, 'error')
|
118 | t.notOk(db.isOpen())
|
119 | t.ok(/exists/.test(err.message), 'error is about already existing')
|
120 | t.end()
|
121 | })
|
122 | })
|
123 | })
|
124 | })
|
125 | }
|
126 |
|
127 | module.exports.tearDown = function (test, testCommon) {
|
128 | test('tearDown', testCommon.tearDown)
|
129 | }
|
130 |
|
131 | module.exports.all = function (NoSqlDatabase, test, testCommon) {
|
132 | module.exports.setUp(test, testCommon)
|
133 | module.exports.args(NoSqlDatabase, test, testCommon)
|
134 | module.exports.open(NoSqlDatabase, test, testCommon)
|
135 | module.exports.openAdvanced(NoSqlDatabase, test, testCommon)
|
136 | if (NoSqlDatabase.prototype._openSync) {
|
137 | delete NoSqlDatabase.prototype._open
|
138 | module.exports.open(NoSqlDatabase, test, testCommon)
|
139 | module.exports.openAdvanced(NoSqlDatabase, test, testCommon)
|
140 | }
|
141 | module.exports.tearDown(test, testCommon)
|
142 | }
|