-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelmdb_test.erl
50 lines (40 loc) · 1.3 KB
/
elmdb_test.erl
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
-module(elmdb_test).
-include_lib("eunit/include/eunit.hrl").
startup() ->
Dir = "./mytestdb1/",
?debugFmt("startup.......... @dir=~ts", [Dir]),
filelib:ensure_dir(Dir),
D = elmdb:open(Dir),
D.
teardown(D) ->
[elmdb:drop(D, L) || L <- elmdb:ls(D)],
Dir0 = elmdb:dispose(D),
Dir = "./mytestdb1/",
?debugFmt("teardown.......... @path=~ts", [Dir0]),
ok.
list_db(D) ->
?debugMsg("list......"),
PI = <<"3.14159">>,
E = <<"2.71828">>,
elmdb:put(D, {<<"math">>, <<"pi">>}, PI),
elmdb:put(D, {"math", <<"e">>}, E),
[?_assertEqual(2, elmdb:count(D, "math")),
?_assertEqual(PI, elmdb:get(D, {"math", <<"pi">>})),
?_assertEqual(E, elmdb:get(D, {<<"math">>, <<"e">>}))].
count_db(D) ->
?debugMsg("count......"),
[?_assertEqual(2, elmdb:count(D, "math")),
?_assertEqual(0, elmdb:count(D, "nonsense"))].
del_db(D) ->
?debugMsg("del......"),
elmdb:put(D, {"math", <<"PI">>}, <<"3.14">>),
elmdb:del(D, {"math", <<"PI">>}),
[?_assertEqual({error,notfound}, elmdb:get(D, {"math", <<"PI">>}))].
%[?_assertError(notfound, elmdb:get(D, {"math", <<"PI">>}))].
db_test(D) ->
[list_db(D),
count_db(D)
, del_db(D)
].
list_test_() ->
[{"Try to list all dbs", {setup, fun startup/0, fun teardown/1, fun db_test/1}}].