summaryrefslogtreecommitdiff
path: root/test/couch_config_test.erl
blob: 7db45bd703b7cbdbc0cd0747a1ae504d5b7e127c (plain)
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
% couch_config module test suote

% Set up test suite
% ?MODULE_test() returns a list of functions 
% that run the actual tests.
couch_config_test() ->
    [
        fun() -> store_tuples() end, 
        fun() -> store_strings() end,
        fun() -> store_numbers() end,
        fun() -> store_tuple_key() end
    ].


% test functions

% test storing different types and see if they come back
% the same way there put in.
store_tuples() ->
    store(key, value).
  
store_strings() ->
    store("key", "value").

store_numbers() ->
    store("number_key", 12345).

store_tuple_key() ->
    store({key, subkey}, value).

    
store(Key2, Value2) ->
    Filename = "local.ini",
    file:write_file(Filename, ""),

    Key = binary_to_list(term_to_binary(Key2)),
    Value = binary_to_list(term_to_binary(Value2)),

    couch_config:start_link(["local.ini"]),

    couch_config:store({"test_module", Key}, Value),
    Result = couch_config:get({"test_module", Key}),
    couch_config:unset(Key),

    couch_config:terminate(end_of_test, ok),

    % clean up
    file:delete(Filename),

    Value = Result.