forked from couchbase/couchstore
/
changessincefilter.lua
69 lines (54 loc) · 1.43 KB
/
changessincefilter.lua
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
package.path = package.path .. ";tests/?.lua"
local testlib = require("testlib")
function test_filter_deletes(dbname)
local t = {
{"k1", "value 1", 1,},
{"k2", "value 2", 1,},
{"k3", "value 3", 1,},
{"k4", "value 4", 1,},
{"k5", "value 5", 1,}
}
local db = couch.open(dbname, true)
for i,v in ipairs(t) do
local k = v[1]
testlib.assert_no_doc(db, k)
end
db:save_bulk(t)
db:commit()
db:delete("k1")
db:delete("k2")
db:commit()
local found = 0
db:changes(0, 4, function(di) found = found + 1 end)
if found ~= 3 then
error("Expected " .. 3 .. " results, found " .. found)
end
db:close()
end
function test_filter_mutations(dbname)
local t = {
{"k1", "value 1", 1,},
{"k2", "value 2", 1,},
{"k3", "value 3", 1,},
{"k4", "value 4", 1,},
{"k5", "value 5", 1,}
}
local db = couch.open(dbname, true)
for i,v in ipairs(t) do
local k = v[1]
testlib.assert_no_doc(db, k)
end
db:save_bulk(t)
db:commit()
db:delete("k1")
db:delete("k2")
db:commit()
local found = 0
db:changes(0, 2, function(di) found = found + 1 end)
if found ~= 2 then
error("Expected " .. 2 .. " results, found " .. found)
end
db:close()
end
testlib.run_test("Filter deletes", test_filter_deletes)
testlib.run_test("Filter mutations", test_filter_mutations)