summaryrefslogtreecommitdiff
path: root/src/couch/test/eunit/chttpd_endpoints_tests.erl
blob: 63f67c243df2d857d83c3c82a71554342dccbeb3 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
% 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(chttpd_endpoints_tests).

-include_lib("couch/include/couch_eunit.hrl").
-include_lib("couch/include/couch_db.hrl").

endpoints_test_() ->
    {
        "Checking dynamic endpoints",
        {
            setup,
            fun() ->
                test_util:start_couch([chttpd])
            end,
            fun test_util:stop/1,
            [
                fun url_handlers/0,
                fun db_handlers/0,
                fun design_handlers/0
            ]
        }
    }.

url_handlers() ->
    Handlers = [
        {<<"">>, chttpd_misc, handle_welcome_req},
        {<<"favicon.ico">>, chttpd_misc, handle_favicon_req},
        {<<"_utils">>, chttpd_misc, handle_utils_dir_req},
        {<<"_all_dbs">>, chttpd_misc, handle_all_dbs_req},
        {<<"_dbs_info">>, chttpd_misc, handle_dbs_info_req},
        {<<"_active_tasks">>, chttpd_misc, handle_task_status_req},
        {<<"_node">>, chttpd_node, handle_node_req},
        {<<"_reload_query_servers">>, chttpd_misc, handle_reload_query_servers_req},
        {<<"_replicate">>, chttpd_misc, handle_replicate_req},
        {<<"_uuids">>, chttpd_misc, handle_uuids_req},
        {<<"_session">>, chttpd_auth, handle_session_req},
        {<<"_up">>, chttpd_misc, handle_up_req},
        {<<"_membership">>, mem3_httpd, handle_membership_req},
        {<<"_db_updates">>, global_changes_httpd, handle_global_changes_req},
        {<<"_cluster_setup">>, setup_httpd, handle_setup_req}
    ],

    lists:foreach(
        fun({Path, Mod, Fun}) ->
            Handler = chttpd_handlers:url_handler(Path, undefined),
            Expect = fun Mod:Fun/1,
            ?assertEqual(Expect, Handler)
        end,
        Handlers
    ),

    ?assertEqual(undefined, chttpd_handlers:url_handler("foo", undefined)).

db_handlers() ->
    Handlers = [
        {<<"_view_cleanup">>, chttpd_db, handle_view_cleanup_req},
        {<<"_compact">>, chttpd_db, handle_compact_req},
        {<<"_design">>, chttpd_db, handle_design_req},
        {<<"_temp_view">>, chttpd_view, handle_temp_view_req},
        {<<"_changes">>, chttpd_db, handle_changes_req},
        {<<"_shards">>, mem3_httpd, handle_shards_req},
        {<<"_index">>, mango_httpd, handle_req},
        {<<"_explain">>, mango_httpd, handle_req},
        {<<"_find">>, mango_httpd, handle_req}
    ],

    lists:foreach(
        fun({Path, Mod, Fun}) ->
            Handler = chttpd_handlers:db_handler(Path, undefined),
            Expect = fun Mod:Fun/2,
            ?assertEqual(Expect, Handler)
        end,
        Handlers
    ),

    ?assertEqual(undefined, chttpd_handlers:db_handler("bam", undefined)).

design_handlers() ->
    Handlers = [
        {<<"_view">>, chttpd_view, handle_view_req},
        {<<"_show">>, chttpd_show, handle_doc_show_req},
        {<<"_list">>, chttpd_show, handle_view_list_req},
        {<<"_update">>, chttpd_show, handle_doc_update_req},
        {<<"_info">>, chttpd_db, handle_design_info_req},
        {<<"_rewrite">>, chttpd_rewrite, handle_rewrite_req}
    ],

    lists:foreach(
        fun({Path, Mod, Fun}) ->
            Handler = chttpd_handlers:design_handler(Path, undefined),
            Expect = fun Mod:Fun/3,
            ?assertEqual(Expect, Handler)
        end,
        Handlers
    ),

    ?assertEqual(undefined, chttpd_handlers:design_handler("baz", undefined)).