-
Notifications
You must be signed in to change notification settings - Fork 0
/
testCommon.js
75 lines (62 loc) · 1.84 KB
/
testCommon.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
var path = require('path')
, fs = !process.browser && require('fs')
, rimraf = !process.browser && require('rimraf')
var dbidx = 0
, location = function () {
return path.join("DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=yyy")
}
, lastLocation = function () {
return path.join("DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=yyy")
}
, cleanup = function (callback) {
if (process.browser)
return callback()
fs.readdir(__dirname, function (err, list) {
if (err) return callback(err)
list = list.filter(function (f) {
return (/^_leveldown_test_db_/).test(f)
})
if (!list.length)
return callback()
var ret = 0
list.forEach(function (f) {
rimraf(path.join(__dirname, f), function (err) {
if (++ret == list.length)
callback()
})
})
})
}
, setUp = function (t) {
cleanup(function (err) {
t.notOk(err, 'cleanup returned an error')
t.end()
})
}
, tearDown = function (t) {
setUp(t) // same cleanup!
}
, collectEntries = function (iterator, callback) {
var data = []
, next = function () {
iterator.next(function (err, key, value) {
if (err) return callback(err)
if (!arguments.length) {
return iterator.end(function (err) {
callback(err, data)
})
}
data.push({ key: key, value: value })
process.nextTick(next)
})
}
next()
}
module.exports = {
location : location
, cleanup : cleanup
, lastLocation : lastLocation
, setUp : setUp
, tearDown : tearDown
, collectEntries : collectEntries
}