You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2015/06/02 21:30:59 UTC
[09/41] chttpd commit: updated refs/heads/2080-port-cors to e2c2bd7
Add tests for chttpd:error_info/1
Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/6a2ed1dc
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/6a2ed1dc
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/6a2ed1dc
Branch: refs/heads/2080-port-cors
Commit: 6a2ed1dce22e4f3dc149f605efe5d288536e8a88
Parents: c9d23bd
Author: Alexander Shorin <kx...@apache.org>
Authored: Wed Jan 21 04:34:31 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Wed Jan 21 04:35:35 2015 +0300
----------------------------------------------------------------------
test/chttpd_error_info_tests.erl | 162 ++++++++++++++++++++++++++++++++++
1 file changed, 162 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/6a2ed1dc/test/chttpd_error_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/chttpd_error_info_tests.erl b/test/chttpd_error_info_tests.erl
new file mode 100644
index 0000000..225f540
--- /dev/null
+++ b/test/chttpd_error_info_tests.erl
@@ -0,0 +1,162 @@
+% 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_error_info_tests).
+
+-include_lib("eunit/include/eunit.hrl").
+
+
+error_info_test() ->
+ Error = <<"error">>,
+ Reason = <<"reason">>,
+ ArgResult = [
+ {
+ bad_request,
+ {400, <<"bad_request">>, <<>>}
+ },
+ {
+ {bad_request, Reason},
+ {400, <<"bad_request">>, Reason}
+ },
+ {
+ {bad_request, "error", "reason"},
+ {400, Error, Reason}
+ },
+ {
+ {query_parse_error, Reason},
+ {400, <<"query_parse_error">>, Reason}
+ },
+ {
+ database_does_not_exist,
+ {404, <<"not_found">>, <<"Database does not exist.">>}
+ },
+ {
+ not_found,
+ {404, <<"not_found">>, <<"missing">>}
+ },
+ {
+ {not_found, Reason},
+ {404, <<"not_found">>, Reason}
+ },
+ {
+ {not_acceptable, Reason},
+ {406, <<"not_acceptable">>, Reason}
+ },
+ {
+ conflict,
+ {409, <<"conflict">>, <<"Document update conflict.">>}
+ },
+ {
+ {conflict, Reason},
+ %% yes, the reason is ignored
+ {409, <<"conflict">>, <<"Document update conflict.">>}
+ },
+ {
+ {forbidden, Reason},
+ {403, <<"forbidden">>, Reason}
+ },
+ {
+ {forbidden, Error, Reason},
+ {403, Error, Reason}
+ },
+ {
+ {unauthorized, Reason},
+ {401, <<"unauthorized">>, Reason}
+ },
+ {
+ file_exists,
+ {412, <<"file_exists">>,
+ <<"The database could not be created, the file already exists.">>}
+ },
+ {
+ {r_quorum_not_met, Reason},
+ {412, <<"read_quorum_not_met">>, Reason}
+ },
+ {
+ {error, {nodedown, Reason}}, {412, <<"nodedown">>, Reason}
+ },
+ {
+ {maintenance_mode, Reason},
+ {412, <<"nodedown">>, Reason}
+ },
+ {
+ {maintenance_mode, nil, Reason},
+ {412, <<"nodedown">>, Reason}
+ },
+ {
+ {w_quorum_not_met, Reason},
+ {500, <<"write_quorum_not_met">>, Reason}
+ },
+ {
+ request_uri_too_long,
+ {414, <<"too_long">>, <<"the request uri is too long">>}
+ },
+ {
+ {bad_ctype, Reason},
+ {415, <<"bad_content_type">>, Reason}
+ },
+ {
+ requested_range_not_satisfiable,
+ {416, <<"requested_range_not_satisfiable">>,
+ <<"Requested range not satisfiable">>}
+ },
+ {
+ {error, illegal_database_name},
+ {400, <<"illegal_database_name">>,
+ <<"Only lowercase letters (a-z), digits (0-9), and any of"
+ " the characters _, $, (, ), +, -, and / are allowed."
+ " Moreover, the database name must begin with a letter.">>}
+ },
+ {
+ {missing_stub, Reason},
+ {412, <<"missing_stub">>, Reason}
+ },
+ {
+ request_entity_too_large,
+ {413, <<"too_large">>, <<"the request entity is too large">>}
+ },
+ {
+ not_implemented,
+ {501, <<"not_implemented">>,
+ <<"this feature is not yet implemented">>}
+ },
+ {
+ timeout,
+ {500, <<"timeout">>,
+ <<"The request could not be processed in a reasonable"
+ " amount of time.">>}
+ },
+ {
+ {Error, null},
+ {500, Error, null}
+ },
+ {
+ {Error, Reason},
+ {500, Error, Reason}
+ },
+ {
+ {Error, nil, [{}]},
+ {500, Error, null}
+ },
+ {
+ {Error, Reason, [{}]},
+ {500, Error, Reason}
+ },
+ {
+ Error,
+ {500, Error, null}
+ }
+ ],
+
+ lists:foreach(fun({Arg, Result}) ->
+ ?assertEqual(Result, apply(chttpd, error_info, [Arg]))
+ end, ArgResult).