1#!/usr/bin/env escript
2%% -*- erlang -*-
3%%! -smp enable
4
5% Licensed under the Apache License, Version 2.0 (the "License"); you may not
6% use this file except in compliance with the License. You may obtain a copy of
7% the License at
8%
9%   http://www.apache.org/licenses/LICENSE-2.0
10%
11% Unless required by applicable law or agreed to in writing, software
12% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14% License for the specific language governing permissions and limitations under
15% the License.
16
17default_config() ->
18    test_util:build_file("etc/couchdb/default_dev.ini").
19
20main(_) ->
21    test_util:init_code_path(),
22    etap:plan(3),
23    case (catch test()) of
24        ok ->
25            etap:end_tests();
26        Other ->
27            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
28            etap:bail(Other)
29    end,
30    ok.
31
32test() ->
33    couch_config:start_link([]),
34
35    etap:fun_is(
36        fun(KVPairs) -> length(KVPairs) == 0 end,
37        couch_config:all(),
38        "No INI files specified returns 0 key/value pairs."
39    ),
40
41    ok = couch_config:set("httpd", "port", "80", false),
42
43    etap:is(
44        couch_config:get("httpd", "port"),
45        "80",
46        "Created a new non-persisted k/v pair."
47    ),
48
49    {Field, Addr} = case misc:is_ipv6() of
50                true -> {"ip6_bind_address", "::1"};
51                false -> {"ip4_bind_address", "127.0.0.1"}
52            end,
53
54    ok = couch_config:set("httpd", Field, Addr),
55    etap:is(
56        couch_config:get("httpd", Field),
57        Addr,
58        "Asking for a persistent key/value pair doesn't choke."
59    ),
60
61    ok.
62