summaryrefslogtreecommitdiff
path: root/src/dreyfus/test/dreyfus_config_test.erl
blob: 775e49d7fb52678bee9cf5f8f6d9c27b783b1472 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
% Licensed under the Apache License, Version 2.0 (the "License"); you may not
% use this file except in compliance with the License. You may obtain a copy of
% the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
% License for the specific language governing permissions and limitations under
% the License.

-module(dreyfus_config_test).


-include_lib("couch_log/include/couch_log.hrl").
-include_lib("eunit/include/eunit.hrl").

-define(TIMEOUT, 1000).


start() ->
    test_util:start_couch([dreyfus]).

setup() ->
    ok.

teardown(_) ->
    ok.

dreyfus_config_test_() ->
    {
        "dreyfus config tests",
        {
            setup,
            fun start/0, fun test_util:stop_couch/1,
            {
                foreach,
                fun setup/0, fun teardown/1,
                [
                    fun check_black_list/0,
                    fun check_delete_from_blacklist/0
                ]
            }
        }
    }.

check_black_list() ->
    Index = "mydb.myddocid.myindexname",
    Index2 = "mydb2.myddocid2.myindexname2",
    Index3 = "mydb3.myddocid3.myindexname3",
    ok = config:set("dreyfus_blacklist", Index, "true"),
    ok = config:set("dreyfus_blacklist", Index2, "true"),
    ok = config:set("dreyfus_blacklist", Index3, "true"),
    dreyfus_test_util:wait_config_change(Index3, "true"),
    FinalBl = [Index3, Index2, Index],
    lists:foreach(fun (I) ->
        ?assertEqual("true", dreyfus_config:get(I))
    end, FinalBl).

check_delete_from_blacklist() ->
    Index = "mydb.myddocid.myindexname",
    Index2 = "mydb2.myddocid2.myindexname2",
    ok = config:set("dreyfus_blacklist", Index, "true"),
    dreyfus_test_util:wait_config_change(Index, "true"),
    ok = config:delete("dreyfus_blacklist", Index),
    dreyfus_test_util:wait_config_change(Index, undefined),
    ok = config:set("dreyfus_blacklist", Index2, "true"),
    dreyfus_test_util:wait_config_change(Index2, "true"),
    ?assertEqual(undefined, dreyfus_config:get(Index)),
    ?assertEqual("true", dreyfus_config:get(Index2)).