1package.path = package.path .. ";tests/?.lua"
2local testlib = require("testlib")
3
4function localtest(dbname)
5   local key = "a_local_key"
6   local value = "the local value"
7   local value2 = "an updated value"
8
9   local db = couch.open(dbname, true)
10
11   testlib.assert_no_local_doc(key)
12
13   db:save_local(key, value)
14   db:commit()
15
16   testlib.assert_no_doc(key)
17
18   db:close()
19
20   db = couch.open(dbname)
21
22   testlib.check_local_doc(db, key, value)
23
24   db:save_local(key, value2)
25   testlib.check_local_doc(db, key, value2)
26   db:commit()
27   testlib.check_local_doc(db, key, value2)
28
29   db:close()
30
31   db = couch.open(dbname)
32   testlib.check_local_doc(db, key, value2)
33
34   db:changes(0, 0, function(di) error("Unexpectedly got a doc: " .. di:id()) end)
35
36   -- Store a non-local document and verify it doesn't collide
37   db:save(key, "non local", 1)
38   testlib.check_local_doc(db, key, value2)
39   testlib.check_doc(db, key, "non local")
40
41   db:delete_local(key)
42   db:commit()
43
44   testlib.check_doc(db, key, "non local")
45   testlib.assert_no_local_doc(key)
46
47end
48
49testlib.run_test("Local doc test", localtest)
50