This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathopen-test.js
123 lines (105 loc) · 3.27 KB
/
open-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
module.exports.setUp = function (test, testCommon) {
test('setUp', testCommon.setUp)
}
module.exports.args = function (leveldown, test, testCommon) {
test('test database open no-arg throws', function (t) {
var db = leveldown(testCommon.location())
t.throws(
db.open.bind(db)
, { name: 'Error', message: 'open() requires a callback argument' }
, 'no-arg open() throws'
)
t.end()
})
test('test callback-less, 1-arg, open() throws', function (t) {
var db = leveldown(testCommon.location())
t.throws(
db.open.bind(db, {})
, { name: 'Error', message: 'open() requires a callback argument' }
, 'callback-less, 1-arg open() throws'
)
t.end()
})
}
module.exports.open = function (leveldown, test, testCommon) {
test('test database open, no options', function (t) {
var db = leveldown(testCommon.location())
// default createIfMissing=true, errorIfExists=false
db.open(function (err) {
t.error(err)
db.close(function () {
t.end()
})
})
})
test('test database open, options and callback', function (t) {
var db = leveldown(testCommon.location())
// default createIfMissing=true, errorIfExists=false
db.open({}, function (err) {
t.error(err)
db.close(function () {
t.end()
})
})
})
test('test database open, close and open', function (t) {
var db = leveldown(testCommon.location())
db.open(function (err) {
t.error(err)
db.close(function (err) {
t.error(err)
db.open(function (err) {
t.error(err)
db.close(function () {
t.end()
})
})
})
})
})
}
module.exports.openAdvanced = function (leveldown, test, testCommon) {
test('test database open createIfMissing:false', function (t) {
var db = leveldown(testCommon.location())
var async = false
db.open({ createIfMissing: false }, function (err) {
t.ok(err, 'error')
t.ok(/does not exist/.test(err.message), 'error is about dir not existing')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test database open errorIfExists:true', function (t) {
var location = testCommon.location()
var db = leveldown(location)
// make a valid database first, then close and dispose
db.open({}, function (err) {
t.error(err)
db.close(function (err) {
t.error(err)
// open again with 'errorIfExists'
db = leveldown(location)
var async = false
db.open({ createIfMissing: false, errorIfExists: true }, function (err) {
t.ok(err, 'error')
t.ok(/exists/.test(err.message), 'error is about already existing')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
})
})
}
module.exports.tearDown = function (test, testCommon) {
test('tearDown', testCommon.tearDown)
}
module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('./common')
module.exports.setUp(test, testCommon)
module.exports.args(leveldown, test, testCommon)
module.exports.open(leveldown, test, testCommon)
module.exports.openAdvanced(leveldown, test, testCommon)
module.exports.tearDown(test, testCommon)
}