-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
base-test.js
53 lines (47 loc) · 1.66 KB
/
base-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
'use strict'
const location = require('./location')
module.exports = function (test, level) {
test('test db open and use, level(location, cb)', function (t) {
level(location, function (err, db) {
t.notOk(err, 'no error')
db.put('test1', 'success', function (err) {
t.notOk(err, 'no error')
db.close(t.end.bind(t))
})
})
})
test('test db open and use, level(location, options, cb)', function (t) {
level(location, { createIfMissing: false, errorIfExists: false }, function (err, db) {
t.notOk(err, 'no error')
db.put('test2', 'success', function (err) {
t.notOk(err, 'no error')
db.close(t.end.bind(t))
})
})
})
test('test db open and use, db=level(location)', function (t) {
const db = level(location)
db.put('test3', 'success', function (err) {
t.notOk(err, 'no error')
db.close(t.end.bind(t))
})
})
test('options.keyEncoding and options.valueEncoding are passed on to encoding-down', function (t) {
const db = level(location, { keyEncoding: 'json', valueEncoding: 'json' })
db.on('ready', function () {
const codec = db.db.codec
t.equal(codec.opts.keyEncoding, 'json', 'keyEncoding correct')
t.equal(codec.opts.valueEncoding, 'json', 'valueEncoding correct')
db.close(t.end.bind(t))
})
})
test('encoding options default to utf8', function (t) {
const db = level(location)
db.on('ready', function () {
const codec = db.db.codec
t.equal(codec.opts.keyEncoding, 'utf8', 'keyEncoding correct')
t.equal(codec.opts.valueEncoding, 'utf8', 'valueEncoding correct')
db.close(t.end.bind(t))
})
})
}