-
-
Notifications
You must be signed in to change notification settings - Fork 108
/
Copy pathtest-browser.js
64 lines (49 loc) · 1.47 KB
/
test-browser.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
'use strict'
// Promise polyfill for IE and others.
if (typeof Promise !== 'function') {
global.Promise = require('pinkie')
}
var test = require('tape')
var uuid = require('uuid/v4')
var level = require('.')
require('level-packager/abstract/base-test')(test, level)
require('level-packager/abstract/db-values-test')(test, level)
function factory (opts) {
return level(uuid(), opts)
}
test('level put', function (t) {
t.plan(4)
var db = factory()
db.put('name', 'level', function (err) {
t.ifError(err, 'no put error')
db.get('name', function (err, value) {
t.ifError(err, 'no get error')
t.is(value, 'level')
db.close(function (err) {
t.ifError(err, 'no close error')
})
})
})
})
test('level binary value', function (t) {
t.plan(9)
var db = factory({ valueEncoding: 'binary' })
var buf = Buffer.from('00ff', 'hex')
db.put('binary', buf, function (err) {
t.ifError(err, 'no put error')
db.get('binary', function (err, value) {
t.ifError(err, 'no get error')
t.ok(Buffer.isBuffer(value), 'is a buffer')
t.same(value, buf)
db.get('binary', { valueEncoding: 'id' }, function (err, value) {
t.ifError(err, 'no get error')
t.notOk(Buffer.isBuffer(value), 'is not a buffer')
t.ok(value instanceof Uint8Array, 'is a Uint8Array')
t.same(Buffer.from(value), buf)
db.close(function (err) {
t.ifError(err, 'no close error')
})
})
})
})
})