/
kyoto-client_test.coffee
97 lines (80 loc) · 3.18 KB
/
kyoto-client_test.coffee
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
vows = require 'vows'
kt = require '../lib/index'
util = require 'util'
assert = require 'assert'
vows.describe('kyoto-client').addBatch(
'Db':
'creating the client':
topic: new kt.Db
'after successfully opening':
topic: (db) ->
db.open 'localhost', 1978
db.clear(this.callback)
undefined
'and clearing':
topic: (error, db) ->
db
'getting a non-existent value':
topic: (db) ->
db.get 'not-here', this.callback
undefined
'returns null': (error, value) ->
assert.isNull value
'setting a value':
topic: (db) ->
db.set 'test', "Test Value", (error) =>
db.get 'test', this.callback
undefined
'allows the value to be retrieved': (error, value) ->
assert.equal value.toString('utf8'), "Test Value"
'getBulk':
topic: (db) ->
db.set 'bulk1', "Bulk Value 1", (error) =>
db.set 'bulk2', "Bulk Value 2", (error) =>
db.getBulk ['bulk1', 'bulk2', 'missing'], this.callback
undefined
'allows multiple values to be retrieved at once': (error, results) ->
assert.equal results.bulk1, "Bulk Value 1"
assert.equal results.bulk2, "Bulk Value 2"
assert.isUndefined results.missing
'getBulk with escaped values':
topic: (db) ->
db.set 'bulk3', "Bulk\tValue", (error) =>
db.set 'bulk4', "Bulk Value 2", (error) =>
db.getBulk ['bulk3', 'bulk4'], this.callback
undefined
'allows multiple values to be retrieved at once': (error, results) ->
assert.equal results.bulk3, "Bulk\tValue"
assert.equal results.bulk4, "Bulk Value 2"
assert.isUndefined results.missing
'Cursor with starting key':
topic: (db) ->
# Add a value for the cursor to retrieve
db.set 'cursor-test', "Cursor\tValue", (error) =>
db.getCursor 'cursor-test', this.callback
undefined
'current value can be retrieved': (error, cursor) ->
cursor.get (error, key, value) ->
assert.equal key.toString('utf8'), "cursor-test"
assert.equal value.toString('utf8'), "Cursor\tValue"
'can be enumerated': (error, cursor) ->
count = 0
cursor.each (error, key, value) ->
assert.isUndefined error
if key?
count++
else
assert.ok count > 0, "count is greater than zero"
'Cursor with no start key':
topic: (db) ->
db.getCursor this.callback
undefined
'can be enumerated': (error, cursor) ->
count = 0
cursor.each (error, key, value) ->
assert.isUndefined error
if key?
count++
else
assert.ok count > 0, "count is greater than zero"
).export(module)